PDA

View Full Version : Arduino motor control(L293DNE)



lastRites
06-20-2011, 01:18 AM
I need to control 2 DC motors (12V,300mA(stall)) with the arduino uno board. So I built a motor controller using the L293DNE ic. It controls 1 motor perfectly but when I program the arduino with instructions for the second motor, the 1st motor does not spin in one direction. I have written a code to test the motor in both directions. I have all the ground lines common. I am powering the motors from a pc psu(12V,10A) or a NiCD battery pack(6V). i soldered 0.1uF capacitors across the motor terminals and a 10uF electrolytic capacitor across the motor power supply. Connected the motors through pins 3 and 6(motor 1), and 11 and 14(motor 2) as described in the data sheet.


int motor1Pin1 = 3; // pin 2 on L293D
int motor1Pin2 = 4; // pin 7 on L293D
int enablePin1 = 9; // pin 1 on L293D
int motor2Pin1 = 5; // pin 10 on L293D
int motor2Pin2 = 6; // pin 15 on L293D
int enablePin2 = 10; // pin 9 on L293D
void setup()
{
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enablePin1, OUTPUT);
pinMode(enablePin2, OUTPUT);
// set enablePin high so that motors can turn on:
digitalWrite(enablePin1, HIGH);
digitalWrite(enablePin2, HIGH);

digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);

Serial.begin(9600);

}
void loop()
{

while(Serial.available() == 0);
int val = Serial.read()-'0';
// if input is '1', motor will turn on one direction:
if(val == 1)
{
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, HIGH);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, HIGH);
}
// if input is other, motor will turn on opposite direction:
else {
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, HIGH);
digitalWrite(motor2Pin2, LOW);
}
delay(200);
}
When I upload this the motor1 starts spinning without any input through the terminal, but when I comment out the lines concerning one motor, the other works fine. I have checked and rechecked every connection with a multimeter but did not find any error :(..

kawal24
06-20-2011, 04:16 PM
I am confused why you are using Serial.available command.


int val = Serial.read()-'0';
if (val == 1)

from what device you are taking input ? is it a pushbutton or anything else ? if it is so then i dont see any input devices being defined/used in the code you gave.
In any case if you are using a input device like pushbutton or anything you will have to define an integer for storing the value like
int val = 0; at the beginning.

lolman_returns
06-20-2011, 06:50 PM
Did you try taking the L293D off and just turning LEDs on and off with the code?

Just a hunch, if that works, that means there is a current issue with two motors.

Do try and let us know, your code seems to be correct.

lastRites
06-20-2011, 07:47 PM
@kawal24: I am using the keyboard to send characters over the usb cable using the serial monitor.
@lolman_returns: Yeah leds work fine. Current issue? The ic can handle .6 amps right? The motors are rated half of that(Checked using multimeter)..
I think the ic is not working correctly. When I supply "HIGH" to enable pin1 and enable pin 2, the first motor starts spinning..

Coolpratheesh
06-21-2011, 01:57 AM
I think your driver must be busted....

lastRites
06-21-2011, 01:29 PM
Maybe. I did not use any diodes. Is that the problem because when using 1 motor only, the circuit wrks fine. Can someone please upload a schematic of a motor driver board?

Coolpratheesh
06-21-2011, 08:33 PM
Check dis out .... this is the original Arduino motor shield ..... i myself am working on a motor driver shield for the arduino and i have deviced a way to replace the namd gate ..... using bc548 .... just make 2 not gates using bc548s and that will do the trick.

gshubham96
06-22-2011, 12:14 AM
see this tut..
http://itp.nyu.edu/physcomp/Labs/DCMotorControl
u will gonna have to modify it a bit coz it's only for one motor.

lolman_returns
06-22-2011, 10:37 PM
see this tut..
http://itp.nyu.edu/physcomp/Labs/DCMotorControl
u will gonna have to modify it a bit coz it's only for one motor.
Looking at the OP's code, it is quite evident that he has referred to this tutorial to begin with.

gshubham96
06-22-2011, 11:08 PM
k...my mistake:\

lastRites
06-24-2011, 04:01 PM
Thanks for all the help guys :) I connected all the logic inputs to the ground through 10K resistors and everything started working perfectly :)