Control your motors with L293D and Arduino

 by guibot
Featured
3477027591_08352052c8.jpg
After long research and trial and error, I have 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
 
Remove these adsRemove these ads by Signing Up

Step 1: Basic implementation

3235657956_b3be2b4f2f.jpg
3262168342_ae12307934.jpg
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:
1-40 of 50Next »
TorBoy9 says: May 13, 2012. 9:40 AM
I breadboarded this circuit and use the sketch as is. Both the circuit and the sketch work without issue. The electrical schematic and the breadboard differ slightly. I used the breadboard circuit. The Arduino pins 2,3 go to one side of the L293D, pins 7,8 go to the other side of the L293.

Your implementation into a circuit board also differs from the breadboard, such as the added voltage regulator. If you have time, could you pls update your electrical schematic?

Anyway, thanks for the great 'ible.
guibot (author) in reply to TorBoy9Jan 2, 2013. 10:59 AM
thanks for your notes, this is a very old instructable, it will be difficult to update ..
guillempq says: Jan 2, 2013. 3:46 AM
Can you control a Brushless motor?
ticapix says: Apr 28, 2009. 11:07 PM
Thanks for the article :) Can you explain or give to link which explain why you put capacitors ? (and why this way ?) Diodes aren't good ?
Wyle_E in reply to ticapixApr 28, 2009. 11:45 PM
The capacitors from the motor leads to ground absorb noise generated by the motors. Motors are notorious for generating spikes that interfere with nearby logic and sensor circuits. The big capacitor across the battery smooths the supply voltage, keeping the internal resistance of the battery from dragging the bus voltage down when the current into the circuit suddenly increases (like when you start a motor). The parallel pair of capacitors from +5V to ground filter the logic-circuit supply. The big electrolytic capacitor soaks up low-frequency trash, but isn't so good at handling high-frequency noise, like that generated by fast-switching logic. The .1 microfarad capacitor is a ceramic or polyester type that handles the hign frequencies.
booze.net in reply to Wyle_EJan 21, 2012. 3:18 AM
This post has been a great help to me. I had numerous problems affecting my logic as I hadn't implement the ceramic capacitors detailed in your post. I was tearing my hair out and temporarily abandoned my project. Thank you very much.

Paul
ticapix in reply to Wyle_EApr 29, 2009. 12:09 AM
thanks Wyle_E :)
shanakaplus says: Apr 7, 2011. 9:08 AM
um looking for elevator avr program. Do you have example program ?
moose4987 says: May 15, 2010. 4:33 PM
 so, say i were to use a motor to turn a solar panel... if i used the voltage from the solar panels which vary from 6-9 volts to power the arduino, could i also use that unregulated voltage to power the L293? 
chris27 says: Mar 2, 2010. 4:06 PM
Hey, sorry to bump an old thread, but I'm thinking of using four PICAXE 08-M chips as slaves for DC motor control via PWM, routed through a L293D (four mono-directional motors).  The only example I've seen of this kind of setup (http://www.phanderson.com/picaxe/pwm_stamp.html) seems to suggest that in order to change the duty cycle of the PWM out, you have to pull pin 4 low, then pulse a certain number of times in 100ms, then pull pin 4 high again.  Is that true?  If so, it's only possible to change the motor speed a maximum of 10 times per second - which isn't very useful when making minute adjustments to respond to gyro stabilisation.  Anyone know of a better way to achieve this?

Cheers
felixk says: Jan 13, 2010. 1:43 AM

Great Job! :)

I noticed that in the final breadboard (Page 3 of the downloadable pdf), you have included servo control and a couple of extra capacitors that are not in the system diagram. Any chance of a complete schematic of this circuit?

Thanks

mani.atico says: Jun 8, 2009. 9:36 PM
Hi,
I'm new to electronics (follow instructions level) and this instructable helped me a lot on bringing two motors to life with my arduino.

I have a basic question: is it better to use the 5V arduino output or a regulated current from the ext source (as shown on this instructable) for the L293D logic input?

Thank you
icecreamterror in reply to mani.aticoAug 20, 2009. 10:46 AM
ext source, always better with the Arduino.
comodore says: Apr 28, 2009. 3:44 PM
Hi I like your Instructables very much! Great job! I have a question that I think you may know the answer to. I need a small chip like this one that I can program and put it in a circuit so when it activates by a sensor ( in my case I want to put a light sensor (LDR))When light hits the light sensor It turns on a motor for a period of time (lets say 5 seconds). Then when the sensor finds it self in the dark it turns on the motor ( again for 5 sec) BUT IN THE opposite DIRECTION. All in All When there is lite it turns on the motor for 5 sec on one side (lets say left) when there is no light it turns the motor for 5 sec (on the oposite side, right) Do you know such a chip that will enable me to program it and make it do what I described??? Thank you! Stanislav
emmjul in reply to comodoreMay 14, 2009. 4:16 AM
You can use the same setup, simply save the states of the ldr and you can check if there was light before and have the arduino reverse the motor->

if ( pin 1 = high)
{
turn right
5 sec
}
if (pin 1 = low)
{
turn left
5 sec
}

else
{
do nothing
}

Hope I could help
comodore in reply to emmjulMay 14, 2009. 11:17 AM
THANK YOU SO MUCH!!! OK, so I just upload this to the Arduino? On what pins do I connect the motor, LDR, power??? I needed someone to write the code because I am a complete n00b in programing... THANK YOU! Could you please now just help me, to say, put it together, like on what pins do I connect the motor, LDR, power... Can I remove the ATMega chip and use it with out the Arduino board, connecting the components directly to the chip? Thank you!
emmjul in reply to comodoreMay 15, 2009. 7:52 AM
no you can't, it's just pseudocode so you can get an idea what you have to programm, sadly I don't own an arduino so I can't write it for you. sry
comodore in reply to emmjulMay 22, 2009. 2:11 AM
Well... Thanks any way... Thanks, you helped me! :D
dagenius in reply to comodoreApr 30, 2009. 5:08 PM
If that is all you are looking to do, then a pickaxe 08-M coupled with the circuit in this instructable should do the trick. the cheapest 08-M that I found was about $3.00 USD.
comodore in reply to dageniusMay 2, 2009. 9:36 AM
And how do you program them? Thanks!
dagenius in reply to comodoreMay 13, 2009. 5:49 PM
the chips have a serial in, serial out(also a in0), and a ground to share with a serial cable. They do take a little more diy to use, because the breakout boards sold on the internet are terrible, and you can make one much smaller, cheaper, and funner with a perf board, solder, pic, and various components. The pic must be programmed with a certain resistor setup that can be found all over the internet.
comodore in reply to dageniusMay 14, 2009. 11:10 AM
Ah ok thanks! I think I am going to use an arduino, that is the arduino chip thanks!
guibot (author) in reply to comodoreApr 28, 2009. 7:55 PM
The Arduino board is fully programable, you can see more info at www.arduino.cc
comodore in reply to guibotApr 29, 2009. 8:00 AM
Yea, but I need something smaller, much much smaller like a chip...
narnian in reply to comodoreMay 1, 2009. 5:46 PM
Any of the microcontrollers whether PIC or AVR can do this. But you will still need support components for regulating power and possibly programming interface, so yes the Arduino is a little big, but you may find you need the same components in any case.
comodore in reply to narnianMay 2, 2009. 3:30 PM
Well, maybe, but the problem is I can't fit the Arduino into the case... I think that I I just program the chip and solder all the components... I would save much space... So should I use this chip? How do I actually program it, the chip that is? As I said, I need something small..like a bug circuit with the programed chip that turns on the motor when it gets a signal for a defined amount of time... Thanks!
guibot (author) in reply to comodoreApr 29, 2009. 8:54 AM
there are arduino clones of many sizes, or can build your customized arduino only with the essencial components, I have build one for this project

check the following links:

http://store.fundamentallogic.com/ecom/index.php?main_page=index&cPath=15

http://www.arduino.cc/en/Main/ArduinoBoardNano
comodore in reply to guibotApr 30, 2009. 5:12 AM
Thank you!
Eirinn in reply to comodoreMay 2, 2009. 1:29 AM
Once you've programmed the arduino you can remove the chip, add a crystal and it can act alone with a power source - you don't always need a smaller arduino ;)
comodore in reply to EirinnMay 2, 2009. 3:32 PM
Great, that is good to hear... I am new in programing and electronic... :P Why do I need a crystal, actually what does a crystal do??? How should it be connected? What chip should I use? Thank you!
Eirinn in reply to comodoreMay 3, 2009. 1:54 AM
I recommend the Arduino Duemillanove, it's relatively easy to use and program and the crystal (i have no idea besides this) is just to make it functional outside the board it's in. The arduino Duemillanove uses the AtMega328. ps: a "crystal" is just a component like a resister or capacitor, it's not a diamond or a ruby :P
comodore in reply to EirinnMay 5, 2009. 1:04 PM
I have the Arduino Duemillanove ... Are there types of crystals, if yes, which type should I use??? Are there separate chips that you can buy, without the whole board? On the chip it self hod do I know where should I hock up the sensor, power, motor, crystal... Yes, I am a n00b! ;) Thank you!
Eirinn in reply to comodoreMay 6, 2009. 8:20 AM
I will answer you honestly; i don't know. But googling goes a long way ;)
comodore in reply to EirinnMay 7, 2009. 1:22 AM
:P Thanks!
guibot (author) in reply to comodoreMay 2, 2009. 4:11 PM
comodore in reply to guibotMay 3, 2009. 4:03 PM
Thanks!
guibot (author) in reply to comodoreMay 7, 2009. 2:20 AM
comodore in reply to guibotMay 7, 2009. 3:22 AM
Thanks! x2 :D
lordofthedonuts says: Apr 29, 2009. 12:47 PM
Nice to see some folks from LMR on insturctables, keep up the good work!
kurtbadelt says: Apr 28, 2009. 11:18 AM
Hi. i have one like this but i used diodes instead of capacitors. whats the diference? should i migrate to caps?
1-40 of 50Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!