wierd running of motors using arduino and l293d

hi guys,
i am experiencing some weird problems while controlling two dc geared motors using arduino uno r3 with the help of a l293d driver.

i used the following code to test the circuit...

// --------------------------------------------------------------------------- Motors
int motor_left[] = {6,7};
int motor_right[] = {10,11};

// --------------------------------------------------------------------------- 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(3000);
motor_stop();
Serial.println("1");

drive_backward();
delay(3000);
motor_stop();
Serial.println("2");

turn_left();
delay(3000);
motor_stop();
Serial.println("3");

turn_right();
delay(3000);
motor_stop();
Serial.println("4"); 

motor_stop();
delay(3000);
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); 
}

the motors move as following, when the following functions are implemented:

  1. drive forward: both motors stop
    2)drive backward: only left motor backwards
  2. turn left: only right motor backwards
  3. turn right: both motors backwards
    5)motor stop: both motor backwards !!!

when i give commands to run the left motor alone, the motor perfectly runs forward, backward...
but when i do the same for the right motor it only runs backwards, that too only for the cases, high-low and low-low. for the rest it does not run.

but when i connect the motors directly to a 9V battery supplying about 8.2V, it runs both forward and backward on interchanging the polarities.

I just dunno wat the heck is going on.. Pls help me out guys.... Breaking my head for the past three days... =(

Thanks in advance :blush:

Power supply adequate? how have you wired things up?

Currently, I am supplying power to the arduno using my desktop's USB port. And I am using the 5v supply form the arduino to the motor driver circuit and grounded using arduino's gnd pin. For the raw voltage of the motors, I am using two 9v batteries in series, which gives it around 13v.. To the motors.

The wiring is exactly as described in the instrucatbles page:

Thank you MarkT for taking your time to reply... Feel free to ask any other extra details you need.

Your 9V motors are the small ones (PP3 or equivalent)??

If so they won't be able to supply enough current really - not that this explains the behaviour.

Test all the wiring is sound, try unplugging each motor in turn (with the power off of course)
and see if each is behaving when on its own - that would suggest power issues.

Mark, I don't know what you mean by those PP3 motors.... But all I know is that it's a basic DC geared motors, and they look exactly like this:

http://www.extreme-robots.nl/91-thickbox/dc-geared-motor-met-wiel-.jpg

And I will try controlling each of the motors independently using the motor driver and get back to you.

Thanks once again. :slight_smile:

That instructable doesn't show the wiring between the 4 input pins of the L293d and the Arduino. Which pin of the L293D is Arduino pin 6 connected to? Same question for pins 7, 10,11. Also check these wires very carefully, make sure they are not shorting to anything.

cyberteen:
Mark, I don't know what you mean by those PP3 motors.... But all I know is that it's a basic DC geared motors, and they look exactly like this:

Whoops, typo, I meant PP3 batteries....

Sounds like a wiring error to me.

ya Mark, i am using those PP3 batteries.
And dc42, the pins 6,7,10 and 11 are the pins on arduino connected to the input pins on the motor driver.

cyberteen:
And dc42, the pins 6,7,10 and 11 are the pins on arduino connected to the input pins on the motor driver.

yes, that's obvious from the code, but in WHAT ORDER? i.e. which Arduino pin goes to which L293D pin?

6 and 7 goes to the input pins 1 and 2 while, 10 and 11 go to the input pins 3 and 4(on the other side of the ic...)

Also my multimeter beeps when i check for continuity between the motor terminals of both the motors. Is it a good sign??

cyberteen:
6 and 7 goes to the input pins 1 and 2 while, 10 and 11 go to the input pins 3 and 4(on the other side of the ic...)

That's still not clear. The pin numbers are given on the L293D datasheet, HTTP 301 This page has been moved. For your code to work, you need the following connections:

Arduino 6 -> L293D 2
Arduino 7 -> L293D 7
Arduino 10 -> L293D 15
Arduino 11 -> L293D 10

Swapping the connections for Arduino 6 & 7 would also work, if you also reversed the motor connections. Similarly for Arduino 10 and 11. So I think your connections are probably OK.

In case the problem is an inadequate power supply, I suggest you try disconnecting the right motor from the L293D, run the sequence again and report what the left motor does. Then do the same with only the right motor connected to the L293D, reporting what the right motor does.

err... dc42, just give me a two days time, coz the whole cirucuit stopped working suddenly.. so i have to figure out what's going on now... i suspect the ic itself.... lemme se

thanks

From the symptoms you described, it did seem to me quite likely that some of the chip outputs had gone short circuit to Vcc or ground.

cyberteen:
6 and 7 goes to the input pins 1 and 2 while, 10 and 11 go to the input pins 3 and 4(on the other side of the ic...)

This, to me, sounds like you don't know how to count pins on a DIP IC.

First - locate the dot or notch on the end of the IC. Place the IC on its "legs" with that end facing away from you.

Now - if it is a dot - sometimes it will be close to the left edge of the IC as oriented - that is "pin 1" of the IC.

If it is a notch (or similar), the left-most pin at the end with the notch/dot will be "pin 1" of the IC.

Pin 2 of the IC is the next pin on the left-side.

Continue counting down the left side - when you reach the last pin on the left side, then next pin in the count will be on the right side, at the -bottom- of the IC.

Continue counting up the right side, until you reach the last pin.

Thus - on an 8-pin DIP IC - pin 1 is opposite pin 8, pin 2 is opposite pin 7, etc.

On a 28 pin DIP IC (like the ATMega328) - pin 1 is opposite pin 28, pin 2 is opposite pin 27, etc.

In other words, it's a counter-clockwise pattern.

See this diagram for details: Dual in-line package - Wikipedia

Thanks for the help, cr0sh, but i do take care of the pin numbering and always refer to a datasheet/ pinout diagram and work on the circuit. But sill i might have gone wrong wile building that, so lemme rebuild the circuit and try again....