Author Topic: Arduino motor control(L293DNE)  (Read 3809 times)

0 Members and 1 Guest are viewing this topic.

Offline lastRitesTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Arduino motor control(L293DNE)
« on: June 19, 2011, 01:48:52 PM »
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.
Code: [Select]
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 :(..

Offline lastRitesTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: Arduino motor control(L293DNE)
« Reply #1 on: June 20, 2011, 08:19:49 AM »
I think the ic is not working correctly. When I supply "HIGH" to enable pin1 and enable pin 2, the first motor starts spinning..  any ideas?

Offline vinniewryan

  • Full Member
  • ***
  • Posts: 56
  • Helpful? 2
Re: Arduino motor control(L293DNE)
« Reply #2 on: June 20, 2011, 11:07:56 AM »
Test the outputs of your MCU with a multimeter to make sure it's not a bad chip or a pull-up/pull-down issue. Make sure your outputs from the MCU are going HIGH and LOW correctly. If they are, then manually test the inputs of the motor controller with a wire connected to V+ or GND with a resistor in line. Make sure the motors both work independantly. Then test them both at the same time. If all of the above checks out, monitor the power to the motor controller with a motor on, then off to make sure there is no significant drop in V+ supply. Report your results.

Offline lastRitesTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: Arduino motor control(L293DNE)
« Reply #3 on: June 21, 2011, 02:33:03 AM »
Will do, thanks! :) I did not use any diodes or pull up or pull down resitors. 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?

Offline lastRitesTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: Arduino motor control(L293DNE)
« Reply #4 on: June 23, 2011, 09:16:28 PM »
If they are, then manually test the inputs of the motor controller with a wire connected to V+ or GND with a resistor in line.
I am a bit confused about how this works.. Can you please explain? Everything else worked fine.

Offline lastRitesTopic starter

  • Jr. Member
  • **
  • Posts: 18
  • Helpful? 0
Re: Arduino motor control(L293DNE)
« Reply #5 on: June 24, 2011, 04:31:44 AM »
Thanks for all the help guys :) I connected all the logic inputs to the ground through 10K resistors and everything started working perfectly :)

 


Get Your Ad Here