Control your motors with L293D
***********************************************************************************************
update 26/4/09
***********************************************************************************************
My 1st instructable :)
http://www.instructables.com/id/HiTec-Servo-Hack/
***********************************************************************************************
After long research and trial and error, I´ve came up to a new walkthrough regarding this nice chip, the L293D.
Each project is one project and each one has its own unique power configurations, so you must be aware of the best battery choice and how to distribute voltage through your robot.
I strongly advice you to read the following articles:
Picking Batteries for your Robot
Once you’ve decided on batteries, how do you regulate the voltage
************************************************
L293D gives you the possibility to control two motors in both directions - datasheet
************************************************
The L293D Circuit:
Basic Implementation:
This is the most basic implementation of the chip.
As you can see, a 5V Voltage Regulator is between the battery and pins 1, 9, 16.
Pin 8 gets power before the VReg, if your motor needs for example 6V you should put 6V directly in this pin, all the other pins should not get more than 5V.
This will work with no problem at all, but if you want to do the right implementation take a look at the next example:
This is the correct Implementation (with the capacitors), and note that pin 8 is feeded by unregulated voltage. This means that if your motors need more than 5V, you should power this pin with that amount of voltage, and the rest of the circuit with 5V.

The capacitors stabilize the current.
The same circuit on a breadboard:
Soldered on a pcb and ready to go:


This is the back of the circuit, click for high resolution photo.
***********************************************************************************************
CODE
***********************************************************************************************
// Use this code to test your motor with the Arduino board:
// if you need PWM, just use the PWM outputs on the Arduino
// and instead of digitalWrite, you should use the analogWrite command
// ————————————————————————— Motors
int motor_left[] = {2, 3};
int motor_right[] = {7, 8};
// ————————————————————————— Setup
void setup() {
Serial.begin(9600);
// Setup motors
int i;
for(i = 0; i < 2; i++){
pinMode(motor_left[i], OUTPUT);
pinMode(motor_right[i], OUTPUT);
}
}
// ————————————————————————— Loop
void loop() {
drive_forward();
delay(1000);
motor_stop();
Serial.println(”1″);
drive_backward();
delay(1000);
motor_stop();
Serial.println(”2″);
turn_left();
delay(1000);
motor_stop();
Serial.println(”3″);
turn_right();
delay(1000);
motor_stop();
Serial.println(”4″);
motor_stop();
delay(1000);
motor_stop();
Serial.println(”5″);
}
// ————————————————————————— Drive
void motor_stop(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], LOW);
delay(25);
}
void drive_forward(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}
void drive_backward(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);
digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}
void turn_left(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);
digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}
void turn_right(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}






@ Tue, 2009-10-20 23:58
L293D for noobs
Just found this tutorial and thought I'd share it. It explains how the L293D works in details so even noobs (like me) can't possibly misunderstand it.
Plus the accent is great :)
@ Sun, 2009-10-18 10:13
To guibot!
@ Sat, 2009-10-17 06:25
I found a cheaper and faster version of the L293D.
The SN754410 is a good chip, it is pin to pin compatible with L293D, So you can put it in the place of the L293D.
@ Sat, 2009-10-17 07:00
Remember though, the diodes
Remember though, the diodes in the SN754410 are for ESD protection, they are not flyback diodes like the L293D.
That said, it apparently works for some people without extra flyback diodes.
@ Sat, 2009-10-17 09:03
Oh, okey.
@ Sat, 2009-10-17 13:23
ESD = ElectroStatic
@ Sun, 2009-10-18 07:41
ESD...
@ Thu, 2009-10-15 02:42
Capacitors?!
I'm planning to use the same H-bridge for a robot (my 1st robot and 1st H-bridge), so I'm very greatful for this istructable. Thanks :)
But excuse me for asking a noob question: Are ALL those capacitors (9?) really necesary just to control to DC motors? Or is it because you're using UNREGULATED power? Or some other specific circumstances?
@ Thu, 2009-10-15 04:11
required? No. suggested?
@ Thu, 2009-10-15 04:34
Well...
...I'm quite a noob in these matters but I am aware that one should use caps to stabilize the current flow. But still 9 (!!!) that's quite a bit...
Here are a few similar setups and they often do use caps, though not allways, and none of them comes close to 9:
www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1255204188
www.me.umn.edu/courses/me2011/robot/technotes/L293/L293.html
itp.nyu.edu/physcomp/Labs/DCMotorControl
www.ladyada.net/make/mshield/
akashxav.com/2009/04/18/arduino-l293d-dc-motor/
www.solarbotics.com/projects/circuits/2007/07/circuit-l293d-mini-sumo/
Just to name a few :)
@ Thu, 2009-10-15 06:26
Silly me...
Just noticed .. the 2 large caps are for the voltage regulator. A typical setup.
So we're down to 7 caps which is still quite a lot..
@ Thu, 2009-10-15 14:30
You can build your circuit
You can build your circuit without the caps. But as jklug80 said, they are ment to stabilize voltage spikes.
i get this circuit schematic from the ladyada motor shield. ;)
@ Thu, 2009-10-15 20:33
Well...
@ Fri, 2009-10-16 01:52
I started with just the
I started with just the L293D, the motors and the microcontroller, and it works ok ;)
I used the caps because they were on the schematic and I wanted to learn how to use them on the h-bridge. I is just a matter of getting used to, now, I can't think in making this circuit without the caps. :)
@ Sat, 2009-10-17 03:59
Hmmm...error in the diagram?
@ Sat, 2009-10-17 22:24
No plus sign = ceramics
No plus sign = ceramics probably. Note the plus on the actual electrolytic. Sometimes folks use whatever symbol is handy (in graphics) for the device they have.
It does appear they have a place for caps on the LadyAda Motorshield between ground and motor outputs, but they appear to not be populated. I'd probably omit those 4 too.
@ Sun, 2009-10-18 07:48
I'll keep that in mind
@ Sun, 2009-10-18 08:10
You can also get
You can also get non-polarised electrolytics, which naturally have no (+) sign at all =D
@ Sun, 2009-10-18 08:13
Damnit!!
@ Sun, 2009-10-18 08:18
There are other
At the end of the day only a few things really matter for most uses: capacitance, maximum voltage and polarity. Sometimes you'll need to know the equivalent series resistance, leakage rate, or other details but normally you don't worry about them.
@ Tue, 2009-10-20 01:25
D'OH!
"There are other non-polarised types too, such as polyester, aluminium foil, green caps..."
@ Sat, 2009-10-17 05:07
They're probably Tantalum
They're probably Tantalum caps, judging from the appearance, value and polarisation.
@ Sun, 2009-10-18 08:10
Still wondering :|
HOW can you tell it's a tantalum cap judging from the appearance, value and polarisation?
According to the diagram they're NOT polarized (tantalums are). The value could be both ceramic and tantalum (or am I wrong?). And the appearences of the two types are extremely similar...
@ Sat, 2009-10-17 05:58
Damnit ... :)
Damnit I think you're right. The 3rd kind I allways forget. Another noob mistake on my part. Man it isn't easy learning electronics. A lot of incomplete or wrong information around. Guess I'll have to find a better symbol list.
Besides these things look VERY similar to the ceramic ones :|
@ Fri, 2009-07-17 20:59
i connect everything like on
i connect everything like on the first breadboard-picture.
whit one motor everything is ok. but with two there is this problem. and i dont think it is the batterie cause it works but not in different ways.. together they drive in the same direction but in diffent ways not. in the serial monitor left and right doesnt appear ???
@ Sat, 2009-07-18 00:04
how are you powering your
@ Sat, 2009-07-18 00:29
Tomorow I will buy a
@ Sat, 2009-07-18 01:09
Usb gives you 5V at 500mA (i
Usb gives you 5V at 500mA (i guess), it might not be enough to power your motors.
9v little batteries aren't good for motors as well, you can use common RC race packs, or a couple of AAA bateries.
Take a read into the following posts:
Picking Batteries for your Robot
Once you’ve decided on batteries, how do you regulate the voltage
@ Fri, 2009-07-10 12:00
I need Help!
so. i build the circuit on my breadboard. The easy one only works, if the upper connection from pin1 to pin16 on the L293D is Not connectet. otherwise the motors only drive forward. so today i tried to build the correct implementation but it is still not working until i pull the capacitor on pin16 out of the breadboard.
The Red "Dot" is the place where the capacitor should be. But when he is there the motors only beep. did i something wrong?
http://www.freewebs.com/sikspack1/DSC00638.JPG <- this is the link to the bigger picture.
a.. why is on the pcb two more capacitors and a voltage regulator?
@ Fri, 2009-07-10 12:58
Do you have made connections
Do you have made connections between the upper and lower Power and GND rails. These are normally not connected internally.
The voltage regulator in guibots schematic is only for a separate power supply for servo motors.
@ Fri, 2009-07-10 13:53
Thats the Problem! I can't.
Thats the Problem! I can't. if i connect the upper gnd to the lower gnd.. it's ok and everything is working but when connecting the upper 5V to the lower 5V the motors only work in one direction. and if i don't remove the capacitor (red marked in the picture) the motors are only peeping.
Why there are 2 capacitors? when i remove the 100µF-capacitor and the 5V-5V-connection it works. but is it right!?!?
@ Fri, 2009-07-10 16:12
Did you check the polarity
Did you check the polarity of the capacitor?
The L293D has 2 Power supply pins. Pin8 is normally used for the unregulated motor power supply (directly from the battery). Pin16 is for the regulated (5V) logic power supply. You can also use a single regulated power supply for both, this is not recommended, but for testing its should be ok.
For a real robot you should supply power to the Arduino board over the external power connector from a battery. The unregulated battery power is than available on Pin Vin on the Arduino.
@ Fri, 2009-07-10 18:11
yes the polarity is right.
yes the polarity is right. i've replaced the 100µF to a 0,1µF Capacitor and now its running unless you connect pin1 to pin16??? i don't know.
another questino: do i need a Volatage regulator if i only want to use the two motors? and do i need 1A oder 1.5A?
@ Fri, 2009-07-17 19:26
Did you tried without the caps?
Did you tried without the caps? How does the motors work without the caps. Try first without the caps and then you can try with the caps, this is easier to debug.
The voltage reg is.. if you motors runs at 6v you should connect your power source (battery) directly to the pin8. Then because your microcontroller (Arduino) and the chip L293D operates at 5V you should power them with 5v. This is where the voltage reg comes in.
let's take the following case scenario:
9V little battery powers the arduino through the power plug. You connect the pin1, 8, and 16 on the L293D with the 5V that comes out from the arduino.
Then your motors operate at 7.2V, you connect V+ from the 7.2V battery to the pin8 on the L293D and then you have to connect the GROUND of that battery to the rest of your circuit.
hope this helps
@ Fri, 2009-07-17 19:58
Same problem
. Without the caps its the same thing. it only works with one motor. if you connect both they only drive one directon and stop. but they sould both drive 4times in different directions and then stop. on the serial monitor you can see Forward Backward forward backward. while it is writing backward the motors stop and during forward they work. hm. did i understand it right: i have to connect a batterie (6V or whatever the motors need) between pin8 of L293d and V+?
Thanx
@ Fri, 2009-07-17 20:25
"... i have to connect a
"... i have to connect a batterie (6V or whatever the motors need) between pin8 of L293d and V+? ..."
The battery power goes DIRECTLY to the pin8, nothing else here.
Than the other pins on the L293D gets regulated power (5V from the arduino or from an external voltage regulator)
You have to check what are your motors needs.
How are you powering the motors and the circuit??
@ Sat, 2009-07-11 13:46
I even don't know what is
I even don't know what is wrong with your schematic. Maybe you better take a look for the Aduino motor sheet. This is more Arduino specific. Arduino - ArduinoMotorShield or http://blushingboy.net/p/motorShieldV3/
Yo don't need a voltage regulator. You can use the internal Arduino regulated power for the L293 logic.
@ Fri, 2009-05-22 10:30
Good solid info but a question if I may?
Can I 'stack' these chips , put several on top of each, soldering pin1 to pin1 etc to boost the current output?
Just a quick 'dirty thought' for Mr Basic
Pete
@ Fri, 2009-05-22 11:43
piggyback
@ Sat, 2009-04-18 13:30
Great L293D motor driver
@ Fri, 2009-07-17 19:15
Hello Edgee, sorry for the
@ Sat, 2009-04-18 12:57
I just found this tuto, it's
@ Sat, 2009-04-18 11:37
nice
Nice board!
I thought the L293D chip is actually 4 independent sets of 4 pins where each V+ pin provides power for one of the motor outputs. You have regulated power to 3 of them and unregulated power to one. Why is that?
This is the diagram as the chip is connected on the picaxe 28 board. As you can see, all V pins are connected to V2
@ Sat, 2009-04-18 23:52
Check the datasheet for the
@ Sun, 2009-04-19 00:00
How about that. I build
How about that. I build edward from the schematics in the picaxe manuals. I just figured the 5V indications where a typo. Edward runs 7.2V on all corners of the motor driver chip and it still works.
Well, I wont make another board without first checking all the real datasheets properly.
@ Thu, 2009-01-29 15:57
MAJOR UPDATE
@ Thu, 2009-01-29 17:30
Good stuff
@ Thu, 2009-01-29 23:06
Thanks :)
@ Tue, 2009-01-20 23:00
MCU Code for PWM
@ Wed, 2009-01-21 03:50
This is Arduino specific