By primerobotics Follow
In this experiment, we will learn how to control the direction and speed of a small-sized DC motor by a driver chip L293D. Making simple experiments, we will just make the motor rotate left and right, and accelerate or decelerate automatically.
Step 1: Components
Step 2: Principle
The maximum current of an Arduino I/O port is 20mA but the drive current of a motor is at least 70mA. Therefore, we cannot directly use the I/O port to drive the current; instead, we can use an L293D to drive the motor. L293D L293D is designed to provide bidirectional drive currents of up to 600mA at voltages from 4.5V to 36V. It’s used to drive inductive loads such as relays, solenoids, DC and bipolar stepping motors, as well as other high-current/high-voltage loads in positive-supply applications.
See the figure of pins below. L293D has two pins (Vcc1 and Vcc2) for power supply. Vcc2 is used to supply power for the motor, while Vcc1, for the chip. Since a small-sized DC motor is used here, connect both pins to +5V. If you use a higher power motor, you need to connect Vcc2 to an external power supply.
Step 3: The Schematic Diagram
Step 4: Procedures
The Enable pin 1,2EN of the L293D are connected to 5V already, so L293D is always in the working state. Connect pin 1A and 2A to pin 9 and 10 of the control board respectively. The two pins of the motor are connected to pin 1Y and 2Y respectively. When pin 10 is set as High level and pin 9 as Low, the motor will start to rotate towards one direction. When the pin 10 is Low and pin 9 is High, it rotates in the opposite direction.
Build the circuit.
Upload the sketch to the Arduino Uno board
Click the Upload icon to upload the code to the control board.
If “Done uploading” appears at
the bottom of the window, it means the sketch has been successfully uploaded.
Now, the blade of the DC motor will begin rotating left and right, in a speed that varies accordingly.
In this article, you will learn how to control DC, Stepper, and servo motors by Arduino and L293D.
- 46,731 views
- 2 comments
- 47 respects
Components and supplies
Apps and online services
About this project
In this article, you will learn how to control DC, Stepper, and servo motors by Arduino and L293D. At the end of this tutorial, you should be able to control spinning direction, acceleration, speed, power and shaft position.
If you do not know what L293D is, we suggest reading L293D: Theory, Diagram, Simulation & Pinout .
Why Driving Motors with L293D?
Driving electromotors needs a high current. In addition, spinning direction and speed are two important parameters to be controlled. These requirements can be handled by using a microcontroller (or a development board like Arduino). But there is a problem; Microcontrollers cannot provide enough current to run the motor and if you connect the motor to the microcontroller directly, you may damage the microcontroller. For example, Arduino UNO pins are limited to 40mA of current which is far less than the 100-200mA current necessary to control a small hobby motor. To solve this, we should use a motor driver. Motor drivers can be connected to the microcontroller to receive commands and run the motor with a high current.
L293D is one of the most popular motor drivers to run DC motors with up to 1A current load.L293D has 4 outputs which makes it suitable for 4-wire stepper motors. L293D can also be used to drive servo motors. In this project, you will learn how to drive motors with L293 and Arduino UNO as the controller. To learn more about L293D, do not miss this article: L293D: Theory, Diagram, Simulation & Pinout .
Controlling DC Motors
There are several types of DC motors, but here we will use a simple brushed DC motor. It has small plastic gears and is quite easy to drive. This motor is suitable for small robots and toys.
You will be redirected back to this guide once you sign in, and can then subscribe to this guide.
Load up the following sketch onto your Arduino.
Pins are defined and their modes set in the ‘setup’ function as normal.
In the loop function, a value for the motor speed is found by dividing the analog reading from the pot by 4.
The factor is 4 because the analog reading will be between 0 and 1023 and the analog output needs to be between 0 and 255.
If the button is pressed, the motor will run in forward, otherwise it will run in reverse. The value of the ‘reverse’ variable is just set to the value read from the switch pin. So, if the button is pressed, this will be False, otherwise it will be True.
The speed and reverse values are passed to a function called ‘setMotor’ that will set the appropriate pins on the driver chip to control the motor.
Firstly, the speed is set, by using an analogWrite to the enable pin. The enable pin of the L293 just turns the motor on or off irrespective of what the in1 and in2 pins of the L293 are set to.
To control the direction of the motor, the pins in1 and in2 must be set to opposite values.
If in1 is HIGH and in2 is LOW, the motor will spin one way, if on the other hand in1 is LOW and in2 HIGH then the motor will spin in the opposite direction.
The ‘!’ command means ‘not’. So the first digitalWrite command for in1 sets it to the opposite of whatever the value of ‘reverse’ is, so if reverse is HIGH it sets it to LOW and vice versa.
The second digitalWrite for ‘in2’ sets the pin to whatever the value of ‘reverse’ is. This means that it will always be the opposite of whatever in1 is.
This guide was first published on Dec 19, 2012. It was last updated on Dec 19, 2012.
Introduction: Run Brushless Motor by Arduino + L298
By AnnaMai Make it easy! Follow
This instructable will show how to run DC Brushless motor (taken from HDD) with H-Bridge L298
Step 1: Take Brushless Motor From HDD
Take out DC brushless motor from broken HDD. This motor has 3 output wire. Next step will show how it run
Step 2: How Brushless Motor Run
Brushless motor has rotation part (called rotor) running without any electrical contact. This will allow it can run in high speed
Statistic part (called stator) will make rotating magnetic field to rotate rotor
In phase 1, head of coil green is (+) and coil blue is (-). Sum of magnetic field of those two coil will make total magnetic direction as in picture -> make rotor rotate to this direction and stop here.
Next in phase 2, head of coil red is (+) and coil blue is (-). Again, total magnetic direction as in picture -> make rotor rotate this direction and stop here.
Again in phase 3, 4, 5, 6, it will make rotor rotates 1 circle.
Step 3: Driver for Brushless Motor
Three pairs of resistor is connected to head of coil green, blue, red -> those transistors will be ON/OFF synchronized to make magnetic field rotating (as in above step explaination)
Step 4: Use H-bridge L298 for Driver
Half of H-bridge is used as 1 pair of transistor.
See inside L298 IC, it is possible to flow current from this H-bridge to another H-bridge
Step 5: Make a Circuit
Connect H-bridge to motor and Arduino (Pro Mini) as in picture
Here is my result connection
Step 6: Code Works
The code will implement the pattern as in picture, which will apply power to each coil as in step 2
This project will show you how to make a DIY 4-wheel robot that can be controlled using a smartphone via Dabble, a mobile application.
- 22,318 views
- 9 comments
- 33 respects
Components and supplies
Apps and online services
About this project
Another project, another out-of-the-box gifting idea! Presenting to you the Dabble controlled 4-wheel robot – an simple-and-fun to build and easy-to-control robot that can be controlled via Bluetooth using Dabble, a mobile application indigenously developed us. All you need to make your robot is an Arduino Uno board, chassis, wheels, motor shafts, and other accesories and tools. To control it, you need to install Dabble from Google Play and pair it with Bluetooth; and your robot’s ready to go places!
What better way to end the year with the same DIYing spirit that it began with, right? So what are you waiting for!
So, Let’s get started!
Step 1: Things You’ll Need
- Arduino Uno Board
- Motor Mounts
- DC Motors
- Motor Driver
- Bluetooth Module HC05
- DC Terminal Block
- Jumper Cables
Step 2: Making of the Body
Firstly, we will start making the body of the 4 Wheel Robot.
Take the chassis and turn it upside down.
Onto this chassis mount 4 motor mounts using M3 Bolts and nuts.
Fix the DC Motors and fix them on the motor mounts using M2 Nuts and Bolts.
Attach wheels on each shaft of the DC Motor.
Flip the assembly, thus your body is created.
Step 3: Adding the Brain
The microcontroller that we are going to use is Arduino Uno.
We are going to make all the connections on it, but we are also going to use a breadboard to make the connections.
Step 4: Making Connections and Using Motor Driver
Make the connection as shown in the below figure.
We are going to make use of the motor drivers because Arduino Uno does not provide sufficient power to run 4 Motors. Thus, we will be adding the motor driver, we will be able to give the robot needed energy.
The left two motors are connected in parallel. Similarly, the right two motors are too connected in parallel.The connections are made as follows:
- Enable Pins – Digital Pin 10 and 11
- VCC – Arduino 5V
- m1_dir1, m1_dir2, m2_dir1, m2_dir2 – Digital Pin 4, 5, 6, and 7
- VC – External Battery
- GND – GND of Arduino and BatteryMake sure we connect all the GND wires together.
Step 5: Connecting Smartphone
We need to add a module that will make the connection between your robot and Dabble App on Smartphone.
We are taking Bluetooth HC05 Module. Connect it as shown in the connection figure.
A DC Motor is a type of electric motor that converts DC electrical power to mechanical power i.e. a DC supply is converted to rotation or movement. DC motors are one of the commonly used motors in different applications like electronic toys, power tools, portable fans, etc.
DC Motors are further classified in to different types like series, shunt and compound and each type is used in different areas of applications. Some DC motors are also used in Robotic and Industrial applications for their easy control and precision.
Since DC motors are generally associated with small to medium applications, where the system mainly consists of a Microcontroller as the main processing unit, controlling and driving a DC motor is very important. This is because, driving a motor directly using the microcontroller is not advised (sometimes not possible) as the current from the Microcontroller is very small (usually less than 30mA).
In this project, a small DC Motor is controlled with an Arduino and a Motor Driver IC where both the speed of the motor and the direction of rotation are controlled.
- Arduino UNO [Buy Here]
- L293D Motor Driver IC [Buy Here]
- 10KΩ Potentiometer
- Push button X 2
- 12V DC Motor
- 12V DC Adapter
- Connecting wires
Arduino UNO is a simple electronics prototyping based on ATmega328P Microcontroller. It is an 8-bit AVR based microcontroller that acts as the brain of the Arduino UNO. Arduino UNO boards are frequently used in many entry level applications like controlling LEDs, driving motors to high end applications like weather monitoring, handheld gaming consoles etc.
L293D Motor Driver IC
As the name suggests, L293D is a quadruple H-bridge, high current motor driver IC. It can be used to drive two motors at a time in both the directions with an output current of 600mA for each motor. L293D IC is designed to drive relays, DC motors, stepper motors and other inductive loads with high current and high voltage requirements.
- As mentioned earlier, Arduino UNO and L293D Motor Driver IC are the main components of the circuit. Arduino UNO acts as the main processing part of the circuit. A button and a potentiometer are used to control the direction of rotation and speed of the motor respectively.
- Hence, a button is connected to Pin 13 of Arduino for driving the motor in forward direction and another button is connected to Pin 12 of Arduino for driving the motor in reverse direction with the other terminals of both the buttons connected to ground.
- A potentiometer i.e. the wiper terminal of the pot is connected to analog input pin A0 of the Arduino UNO. The other terminals of the potentiometer are connected to 5V supply and ground respectively.
- L293D is a 16-pin IC available in dual in-line package. As it is capable of driving two motors, we’ll see the connections that are needed for driving a single motor. In that,
- Pin 1 of L293D IC is used to enable the driver channels 1 and 2 i.e. inputs of motor 1. It is an active high pin and hence it is connected to 5V supply.
- Pins 2 and 7 of L293D are inputs of drivers associated with motor 1. They are connected to Pins 11 and 10 of Arduino UNO respectively.
- Pins 3 and 6 of L293D are the output pins of first driver channel. They must be connected to the motor we are going to control.
- Pins 4, 5, 12 and 13 of the L293D IC are ground pins.
- The remaining connections with respect to L293D IC are the power supply pins. L293D Motor Driver IC needs two types of power: one for its internal operations and other for driver channels that drive the motor.
- Pin 16 of L293D IC is the supply pin for internal operations and is connected to a 5V supply. Pin 8 of L293D IC is the supply for driving the motor and is connected to a 12V supply.
The aim of this project is to design an Arduino based system for controlling a DC Motor. All the connections are made as per the circuit diagram mentioned above. The working of the project is very simple and is explained here.
Two buttons are used in this project, one each for forward and reverse direction of the motor. The two buttons are connected to Pins 13 and 12 of Arduino which are internally pulled-up (using code). The other terminals of the buttons are connected to ground and hence when the button is pressed, the microcontroller detects LOW (logic 0).
The output of the POT is an analog signal and hence it is connected to analog pin of the Arduino. Based on the analog voltage value from the POT, the speed of the motor is varied.
For this to happen, we need to use the concept of PWM in the circuit. The inputs to the motor driver IC must be in the form of a PWM signal and hence are connected to Pins 11 and 10 of Arduino respectively, which are capable of generating PWM signals.
When the system is powered ON, Arduino waits for the button to be pressed. If the forward direction button is pressed, the Arduino drives input 1 of motor driver IC (Pin 2) with PWM signal and a logic low to input 2 (Pin 3). Hence, the motor starts rotating in forward direction.
Similarly, if the reverse direction button is pressed, Arduino drives input 2 (Pin 3) of L293D Motor Driver IC with the PWM signal and input 1 (pin 2) of L293D is given a logic low. Hence, the motor starts rotating in reverse directions.
The speed of the motor in either direction can be controlled using the POT as it controls the duty cycle of the output PWM signal.
You will be redirected back to this guide once you sign in, and can then subscribe to this guide.
In this lesson, you will learn how to control a small DC motor using an Arduino and a transistor.
You will use an Arduino analog output (PWM) to control the speed of the motor by sending a number between 0 and 255 from the Serial Monitor.
This guide was first published on Dec 17, 2012. It was last updated on Dec 17, 2012.
This page (Overview) was last updated on Oct 25, 2021.
Text editor powered by tinymce.
OUT OF STOCK NOTIFICATION
You have been successfully subscribed to the Notification List for this product and will therefore receive an e-mail from us when it is back in stock!
For security reasons, an e-mail has been sent to you acknowledging your subscription. Please remember that this subscription will not result in you receiving any e-mail from us about anything other than the restocking of this item.
If, for any reason, you would like to unsubscribe from the Notification List for this product you will find details of how to do so in the e-mail that has just been sent to you!
In DC motor speed testing, the PWM is applied to motor and its duty cycle is varied from min to max. While applying PWM the actual RPM of DC motor is also measured and note down to see how motor speed (RPM) varies as PWM width varies. Along with this, the applied voltage to motor is also measured to see the motor speed at different applied voltage. Finely, after noting down all the values, the observation table is prepared for pulse width (duty cycle), applied voltage and motor speed in RPM. This table is used to prepare duty cycle->RPM graph or applied voltage->RPM graph of motor.
The given project demonstrates above example. It applies PWM to DC motor to vary its speed from min to max and max to min continuously and also measures following parameters
2) Applied voltage to motor
3) Motor speed in RPM
It uses arduino UNO board to generate PWM and measure/calculate above 3 parameters. These parameters are displayed on 16×4 LCD. It is very easy to vary speed of DC motor using arduino. Arduino can generate PWM on its analog output pin and when it is applied to DC motor, its speed varies. So it is very simple and easy task. To measure RPM, opto-interrupt sensor MOC7811 is used. When motor completes 1 revolution, the sensor generates 1 pulse and such pulses are calculated by arduino to calculate RPM. So let us see how this is done. Lets start with circuit diagram first, followed by its descriptions and operation.
As shown in figure, the circuit is built using arduino UNO development board, 16×4 LCD, NPN Darlington transistor TIP122 and opto interrupt sensor MOC7811.
· The analog output pin 9 of arduino drives [email protected] RPM DC motor through TIP122. This pin is given to base input of TIP122 through current limiting resistor R2 and DC motor is connected to collector of TIP122
· The internal IR LED of MOC7811 is given forward bias using 5V supply form arduino board through current limiting resistor R1. Internal photo transistor is pulled up by resistor R4. The collector output of transistor is connected to digital pin 7 or arduino
· LCD data pins D4 to D7 are connected to digital pins 5, 4, 3 and 2 of arduino while control pins Rs and En are connected to 12 and 11. RW pin is connected to ground. Vcc pin and LED+ pin are connected to 5V supply from arduino board and Vss pin and LED- pins are connected to arduino board ground
· One pot is connected to Vee pin to vary contras of LCD
· First the motor is given 12 V supply through external power supply. Next the arduino board, LCD and sensor is given supply through USB from PC / laptop
· Initially the LCD shows different parameters as
· Then arduino starts applying PWM to motor with maximum pulse width
· So motor will start rotating at maximum speed. Some time delay is provided to allow motor to attain full speed
· As the motor starts rotating, the slotted wheel attached to its shaft will also rotate
· The MOC7811 sensor is placed such a way that the slot of wheel passes through sensor air gap. Thus when motor rotates one full revolution, the slot passes through sensor gap. Due the slot in the wheel the IR light falls on photo transistor. So transistor conducts and generates negative pulse in collector output. Thus each rotation of motor produces pulse
· The frequency of these pulses is actually RPS (-revolution per second) of motor. To measure the frequency of this pulse first the ON time is measured then OFF time is measured and from these frequency is calculated as
Time period = Ton + Toff (in us)
Frequency= 1000000/time period
· This frequency is speed of motor in RPS. From this RPS, speed of motor is calculated in RPM as
· The PWM input is varied from 250 to 100 in step of 15. That is directly displayed on LCD
· The ON time and OFF time of PWM output is also measured to calculate the PWM duty cycle as
PWM duty = [PWM_Ton / (PWM_Ton + PWM_Toff)] × 100
· Finally voltage applied to motor is calculate as
Voltage applied to motor = motor voltage × duty
· First the PWM input is decreased from 250 to 100 in 10 steps of 15 and then again it is increased from 100 to 250 and this cycle is repeated continuously
· So motor speed continuously decreases and then continuously increases. We can observe the change in motor speed that is displayed on LCD as speed in RPM
Thus the given project varies the speed of DC motor and also measures it accurately. It displays % of pulse width applied to motor along with applied voltage. So one can note down motor speed in RPM at different voltage and pulse width in observation table for further needs.