Control a DC motor with Arduino and L293D chip
This is a quick guide with a bit of extra info (pin configurations etc..) that I’ve learnt along the way on how to use the L293D with the Arduino, showing that we can:
A) Use a supplemental power source to power the DC motor
B) Use the L293D chip to drive the motor
C) Use a switch to change the direction of the motor
UPDATE: If you intend to use this for robotics then please check out this page here to get the most out of this chip – I actually found the SN754410 easier to work with that the L293D, its exactly the same apart from it can handle more current Arduino obstacle avoidance robot
L239D DC Motor Driver & Pin Configuration
Although I’ve only used 1 motor, it is possible to use 2 motors on a single L293D chip, of course you then have to compensate on the current accordingly to ensure enough juice for both motors under peak load. Remember that if you use 2 motors, the power source will be the same voltage but the current needed will be doubled – a good start is by altering how your batteries are connected in series or parallel.
“The L293D is a monolithic integrated, high voltage, high current, 4-channel driver.” Basically this means using this chip you can use DC motors and power supplies of up to 36 Volts, thats some pretty big motors and the chip can supply a maximum current of 600mA per channel, the L293D chip is also what’s known as a type of H-Bridge. The H-Bridge is typically an electrical circuit that enables a voltage to be applied across a load in either direction to an output, e.g. motor.
This means you can essentially reverse the direction of current and thus reverse the direction of the motor. It works by having 4 elements in the circuit commonly known as corners: high side left, high side right, low side right, and low side left. By using combinations of these you are able to start, stop and reverse the current. You could make this circuit out of relays but its easier to use an IC – The L293D chip is pretty much 2 H-Bridge circuits, 1 per side of the chip or 1 per motor.
The bit we really care about in all of this is the 2 input pins per motor that do this logic and these, more importantly for our needs, can be controlled from the Arduino board.
You also don’t have to worry about voltage regulation so much because it allows for 2 power sources – 1 direct source, upto 36V for the motors and the other, 5V, to control the IC which can be supplied from the Arduino power supply or since my motor power supply is only 6V I’m going to use this (if the motor supply was higher I would consider using a transistor or voltage regulator). The only thing to remember is that the grounding connection must be shared/ common for both supplies. Below you can see the pin layout for the chip and the truth table showing the output logic.
|Pin 1||Pin 2||Pin 7||Function|
|Low||Not applicable||Not applicable||Stop|
Generally speaking most DC motors require a lot more current than the Arduino board can provide for instance the motor that I’m using needs around 5 to 6 Volts. Now I could use a 12 Volt power source for the Arduino, but then its going to drain quickly when it has to power everything, especially if I was to add in another motor and a couple of servos, so instead my Arduino runs off of my 9 Volt power supply I made. (here)
You’ll need a few capacitors in this circuit to smooth out the power load to the motors as much as possible to help avoid any spikes and stabalise the current. I’m using a 50 Volt 10 uF capacitor on the power supply – I suggest you do this as the bare minimum. You could also add in a capacitor for each motor that you use – something like a 220nF multilayer ceramic capacitor should be OK for the small motors.
Arduino L293D Circuit Components
10K Ohm resistor (Brown, Black, Orange, Gold)
50V 10uF Capacitor
6V DC motor
L293D motor controller/ driver chip (IC)
A switch (push, toggle etc..)
Arduino Deumilanove w/ ATMEGA328
Breadboard / Prototyping board
Jumper/ Connector wires
4x AA battery holder
4x AA batteries
Optional 220nF multilayer ceramic capacitor (Y5V)
Optional 9V DC power supply or use the USB power for the Arduino
Building the L293D motor driver circuit
First lets start with the 16 pins on the L293D chip and what we need to wire these to. You’ll see that its basically got 2 sides, 1 for each motor.
- Enables and disables the motor whether it is on or off (high or low) comes from the Arduino digital PWM pin 9
- Logic pin for the motor (input is either high or low) goes to Arduino digital pin 4
- Is for one of the motor terminals can be either +/-
- Is for the other motor terminal
- Logic pin for our motor (input is either high or low) goes to Arduino digital PWM pin 3
- Power supply for the motor, this should be given the rated voltage of your motor, so mine is from a 6V supply
- Enables and disables the 2nd motor on or off (high or low)
- Logic pin for the 2nd motor (input is either high or low)
- Is for one of the 2nd motor terminals can be either +/-
- Is for the 2nd motors other terminal
- Logic pin for the 2nd motor (input is either high or low)
- Connected to +5V, in this case the power from motor supply
You can see from my photos how I’ve placed the L293D and wired it according to the above pins. Next I have my switch on Arduino digital pin 2 and I have the GND pin from Arduino connected to the GND rail on my breadboard. I also add the capacitor in between the power supply – making sure that the negative and positive terminals are correctly aligned. Finally I complete the circuit by adding in wires to carry the current from one side of the breadboard to the other and I add in the motor and its power supply.
For more detail: Control a DC motor with Arduino and L293D chip
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
Cheapest PCB Prototype: Only $2 for 10pcs 10×10cm PCBs, 24 hours Quick Turn, DHL Delivery in 3 Days
This Post / Project can also be found using search terms:
- bluetooth controlled arduino robot using adraxx l239d motor controller
- motor driver L293D connection with arduino