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.

Hey, Guibot!

Obrigado pelo bom tutorial! ;)

I have been experimenting with this same IC and I am having unidentified problems. Mainly when using it in conjunction with the Tamiya Gearbox. The problem is that those motors use only 3VDC.This is below the minimum specified voltage for the IC VCC. I was wondering if there are any limitations to VCC2 or pin 8. Can I simply apply 3VDC to pin 8 and get them out of either output pin (if enable and control pins are high)?

Or do I need to use 5VDC for everything (including pin 8) and drop them down to 3 VDC after the output pins with some diodes?

Thanks for your help,

Andrés

Hi Andres,

I kinda have the same problem. I bought a Tamiya double gear box (double gear) and i am using a Arduino Mega ADK board. I understand that the motors are rated @3VDC.  Did u get them to run now? Also I am using a L293DNE motor driver. My circuits are according to this example and the code too. But my motors/motor doesn't respond. Any suggestions?

 

Gokul

Hey Gokul,

Yep. I got them running. If yours don´t spin AT ALL, make sure the following is happening:

  • Pin 16 is getting between 4.5 and 36VDC.
  • Either or both pins 2 and 15 or 6 and 11 get a logic high.
  • That the enable pins (1 and 9) are high at the same time of the ones in the previous point.
  • That the GND is common between the L293D power supply and the mcu power supply.
  • Pin 8 gets at least 4.5VDC.

Here is what I´ve learnt: pin 8 (motor V+) will not accept anything below it´s minimum rating: 4.5 VDC. In my own research, the IC will drop between 0.5 and 0.8 VDC. That means you will be supplying between 4 and 3.7 VDC to the motors. In my case, that was still too hot for my motors. I solved it doing something that should not have solved it. I hooked a bicolour LED (common cathode) in parallel to the IC´s motor output. So, if the motor spins CW, the green half of the LED lights up. If it spins CCW, I get a red.

Hope this helps.

Andrés

The L293D drops about 1.5V from the supply you give it to what the motors actually see. So if you supply 5V the motors will actually see about 3.5V, which should be fine.

Thanks, Ignoblegnome. I will do that then.

Cheers!

Andrés

First - thank you for this tutirial. Now the question. On the first foto you have 2 big caps before and after the voltage regulator. But then you have 2 smaller but not 0.1uF caps on the Vss and enable pin of the L293. On the schematic later you only have 2 "big" caps, but on the first foto 4! Why is that, and do I need additional "big" 100uF caps on the L293. Thank you

The two caps on the first foto are, as you can see here very advisable.
The other caps on the drawing are meant to supress electric noise and voltage spikes.. you can try all the circuit without the caps and it will work, but remember it is always a good practive to use them. I am no EE though and I apologize for not being able to explain this in greater details.

Hi. LMR world.... . i dont have any PICAXE or arduino or any other development board... Is there any alternative way of checking it out?? 

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

Now I gotta know for sure: Are the o.1uF caps tantalum OR ceramic?