Let's Make Robots!

Control your motors with L293D

UPDATE

***********************************************************************************************
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:

3235657956_b3be2b4f2f.jpg?v=0

3262168342_ae12307934.jpg?v=1240780647

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.

3235658022_f78495fddd.jpg?v=0
The capacitors stabilize the current.

The same circuit on a breadboard:
3252941552_2f4919475f.jpg?v=1240780044

Soldered on a pcb and ready to go:
3234563157_780312a389.jpg?v=0
3451483356_2fdf26be19.jpg?v=0

3257970545_12de4f710e.jpg?v=0

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);
}

Comment viewing options

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

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?

required? No. suggested? yes! They suppress noise and help with the discharge when the magnetic field collapses after the motors are shut off. (Note: In not an EE major so someone may prove me wrong but that is my understanding.)

...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 :)

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..

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.  ;)

I was planning to use a cap or two. However 7 seems like a bit of a hassle, so I think I'll try it with less for starters and see how that goes. Did you start with 7 or is it because you had problems when using less?

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.  :)

It seems that the small caps (0.1uF) are depicted with the symbol for electrolytic caps, but they sure look like ceramic caps on the fotos? Correct me if I'm wrong?....

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.

And the problem with the symbols is that the description I posted above (as well as many others) says the symbol with a plus sign is an ELECTROLYTIC cap. That's apparently incorrect. It simply means a POLARIZED cap? Furthermore the ones with no plus could mean both a tantalum or ceramic one, allthough tantalum caps are polarized too? Oh well I'll get used to it sooner or later...