L293D - Motor Driver Walkthrough

guibot's picture
Controlling two motors with L293D and Arduino
Time to build: 
0.15 hours

Description: 

In this walkthrough I will show one simple way to use L293D H-Bridge, and build a basic Motor Driver for Arduino. I only tried this with Arduino Diecimila and it works well.

There may be other ways to do this, but since this works for me and feeds my needs, I assume this might be useful for more people.

NOTES:

- 9V little batteries are good to power the Arduino, LED´s and one or another sensor, but not so good to power DC motors or servos;
- If you want to have more devices, like another motor, servos, sensors, it is better to have a stronger power supply like an RC Car battery pack, or, AA batteries together with 9V battery and in this case you should connect both GROUNDS;
- be very carefull when dealing with power supplies, sometimes small mistakes may cause short circuits and damage your MCU, sensors, motors.. and you don´t want that!
- If you see something wrong with your motor, like stop, stall, or erratic behavior maybe your battery needs to be recharged, or your battery is not supplying enough power to your motors. Always use your batteries fully recharged;
- If you see erratic behavior in your servo, like going into one direction and staying there, or becoming noisy maybe it needs more current to operate, or your battery needs to be recharged.

So let´s start:

L293D gives you the possibility to control two motors in both directions - datasheet

2866908240_6693d28101.jpg?v=0
Pins 1, 8, 9, 16 - POWER           Pins 4, 5, 12, 13 - GROUND
Pins 2, 7 - Input 1                     Pins 3, 6 - Output 1
Pins 10, 15 - Input 2                 Pins 11, 14 - Output 2

2866054551_6ac02e5565.jpg?v=0

The picture shows:
- one motor connected to IC pins 11 and 14.
- IC pins 10 and 15 connect to the Arduino PWM pins 5 and 6. Using PWM you are able to set different motor speeds.
- The Arduino is being powered from USB. Note the jumper next to the USB plug is set to USB Power mode.

CODE Sample

 

Here we have a different setup:
2866054667_0050ec82c5.jpg?v=0
- Note the jumper next to the USB plug is set to EXTERNAL power supply.
- The batteries pictures are symbolic. You should design your power setup regarding the MCU, motors and servos current needs. Ask in the forum what best fits your hardware.

 

Breadboard example:
2846127747_0d63c3bfca.jpg?v=0
The L293D only drives motors. Servos are driven by the MCU or Servo Drivers.

 

Below are some examples of custom made motor drivers assembled in prototype boards:

2818514406_e6ed69ac5a.jpg?v=0
This board can control one motor, supply power for Arduino, and one servo.

2824842353_6b53791e17.jpg?v=0
This board can control two motors, supply power for Arduino, and two servos.

2847531165_6c528aa8f6.jpg?v=0
2847531163_dc682163ff.jpg?v=0

This board can control two motors, supply power for Arduino, and two servos.
I also added female headers to supply power for other components (ex: sensors, …)

Your rating: None Average: 4.5 (2 votes)
jklug80's picture

I still don't understand why

I still don't understand why you are only using one power source to power the motor driver AND the mincrocontroller. It looks like you are sharing 5 volts with the microcontroller and the motors. Shouldn't you use 2 different power sources so the motors get a much higher voltage? The grounds should be shared between the two, but not the voltage (red line).

Also shouldn't the resistor connect voltage to the LED not the LED to ground?

Maybe I'm wrong, feel free to correct me.

EDIT: I guess this does give the benefit of controlling the motor in both directions so it DOES achieve it's goal. I just think the motors would be way underpowered.

guibot's picture

The motors are underpowered

The motors are underpowered yes, they support until 6V.    As soon as I make this with another setup I will post it.

As for the LED i guess you´re right! Thanks!

DerDude's picture

It shouldn't make any

It shouldn't make any difference, if you put the resistor before or after the LED. But it's a matter of "clean" wiring to put the resistor in the "hot" line, because if you do a short circuit between the cathode and ground you will burn the LED. The other way nothing will happen :-)
guibot's picture

I´ve tested the LED and

I´ve tested the LED and resistor, and seen no diference in connecting the resitor to voltage, or to the ground.

But as DerDude said, it´s a good practice to put the resistor on the red wire before the LED.

Must correct the diagram.
fritsl's picture

Oh my, it is a tough world!

Oh my, it is a tough world! I was so glad that you made and shared this tutorial, and then all sorts of "why this and why that" :D I hope you cope with that and keep it up so we can get a good base for all of us to build on. I plan to use it!

I haven't got enough brains to see anything than it is a great tutorial :) I know how much time you have put into making it, it is very consuming, so thanks.

guibot's picture

no problem at all fritsl!!

no problem at all fritsl!!   :D     I´m glad I could make this so far into the point I can share what I have learned!

I believe that the first thing one should note is.. this works!     May not be the "right way", but it works.

I believe there is a "right way" to do this techy things, but since every techy person has it´s own very opinion about the "right way" to do things, for me (arty person) if it works its perfect!!    :D

Please keep asking and giving feedback, so we all can learn and make this a better tutorial!! But please, let´s try to make this simple...  :)


jklug80's picture

I'm not being critical at

I'm not being critical at all... I'm just trying to learn too ;) If you don't ask questions then that means you either understand it fully or don't understand it at all (not even enough to form a question). I'm just very inquisitive!
guibot's picture

But I do ask questions...  

But I do ask questions...   maybe in a compulsive way sometimes  :)
robologist's picture

Fun to watch, and learn from

Glad to see you got it going! It's fun watching the behavior of robots, observing what they see, and are reacting to from what code we've used. Might be interesting to add more sensors, or maybe a speaker?
Chriskid's picture

hurry up on the breadboard tut.

Hahaha. I really think i am gonna build it, where did you get those parts with the screws? thanks. amzaing. Five stars

guibot's picture

Terminal Blocks

those parts are Terminal Blocks, you can get them in hardware and electronic shops   ;)
Chriskid's picture

thanks, oh and sorry to bug

thanks, oh and sorry to bug you, but what are those white bits, and how do they plug into the arduino?
guibot's picture

I use this "white bits"

I use this "white bits" instead of the male to female headers because they are better connectors. In the photo is the correspondent female bit, and to connect to the arduino pins I use male headers as you can see   :)

2851360643_9df5d9f141.jpg?v=0


Chriskid's picture

what are the female headers

what are the female headers for, I cant see where they would come in on the circuit diagram
guibot's picture

Looking at the diagram you

Looking at the diagram you can see the "Microcontroller PWM Pins", and "Microcontroller Power" - this are the male headers ( in the foto they are the "white bits") and it is where you connect the female headers.
OptimusTronic's picture

thanks men, I understand

thanks men, I understand your explication. Thanks
guibot's picture

I´ve updated pics and

I´ve updated pics and text  ;)
buhatkj's picture

Thanks guibot for this

Thanks guibot for this tutorial, Also I would add that this works without changes for the SN754410 since it is pin-compatible with the L293D.  I was able to do this in just a few minutes and it sure works better than my pololu controller.  Now I know the h-bridge chip was OK, but the PIC was borked on that one :-/

:-)

jka's picture

The SN754410 is pin

The SN754410 is pin compatible with the L293D, yes. But not functionally compatible. It's the equivalent of an L293, not an L293D, since it doesn't have clamp diodes built in.
robologist's picture

It does have diodes as the L293D does

Check the datasheet on page 2, for the "Typical of all outputs" diagram :

http://focus.ti.com/lit/ds/symlink/sn754410.pdf

 

guibot's picture

So this tell us they do

So this tell us they do exactly the same?

Because if they do, I must think in getting some SN754410, they are a lot cheaper than L293D.

jka's picture

No, it doesn't. Just because

No, it doesn't. Just because there are diodes in the specs doesn't mean that it's clamping diodes. If you read the spec, clamping diodes are not mentioned with one word. They are, if you read the spec for the L293D which has them.

Furthermore:

Page 1. "Improved Functional Replacement for the SGS L293" It says "L293". Not "L293D"

Page 6. If you look at their application example, they have external clamping diodes.

 

jka's picture

Researched it a bit more. I

Researched it a bit more. I found a reference to someone who has talked to TI Tech support about this and they confirm that the diodes are for ESD protection and not clamping. http://ladyada.net/make/mshield/use.html
guibot's picture

OK!!!Thanks jka  ;)

OK!!!

Thanks jka  ;)

robologist's picture

Sorry about that JKA, I'd always seen them as clamping diodes

Since seeing the datasheet diagram, I've used the 754410 for years without any external diodes believing they were already part of the device, and never had any problems. I'm a little surprised they don't make it clearer that the diodes present aren't meant for clamping but primarily for ESD.  My only complaint about either the L293D or 754410 was that they take a bit of voltage off, since they are BJT drivers.
jka's picture

Thats ok. It loks like

Thats ok. It loks like clamps and I thought that too, until I read that it's L293 equivalent. Then I started reading the spec sheet a couple of times. They might work as clamps, but they are probably not rated for it. So even though it might work for some time, some day a large spike will come along and kill the diodes.
guibot's picture

Hi! thanks!!   It´s good

Hi! thanks!!  
It´s good to know this works better than the polulu controller  :D
GroG's picture

Thanks for the tutorial! 

Thanks for the tutorial!  When I start playing with micro-controllers I'll use it as a reference.  Do you have expierence with the other controllers (Pic Axe, Pololu, Basic Stamp, or BOA's favorite the PIC16F690)? How would you compare them with the Arduino? 

Hopefully, this will not turn into another geek-tosterone laden "My PIC is better than yours" debate....

guibot's picture

Hi! Glad you like it!!  :)I

Hi! Glad you like it!!  :)
I only have experience with Arduino, so I cannot compare it with other microcontrollers.

I know there is a comparison sheet somewhere, but can´t find it right now.

Chriskid's picture

Ok, first, I know I asked

Ok, first, I know I asked this already, but I realized that one of us had a communication error. "what are the female headers for, I cant see where they would come in on the circuit diagram" is what I asked in one of my previous comments. Now, what I meant to ask was, What are the two 6-pin female headers that are on the ninth picture you posted for? Now to be a bit more clear, they are right between the "switch" and the plugs for the servo. Thanks. I am sorry for not being clear.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.