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.

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

 

 

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?

L293D


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?

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.

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!?!?

3235658022_f78495fddd.jpg

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.

 

 

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?

 

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 

 

. 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

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

 

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.