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:
- drive forward: both motors stop
2)drive backward: only left motor backwards - turn left: only right motor backwards
- 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