Step 4Ard-e on Auto: Using the Ardunio to drive the DC motors
The chip basically takes three inputs, one PWM input that sets the speed of the motor and turns it on and off and two inputs that determine the direction that the motor spins. The PWM pin is the Enable of the L293, the two pins that determine the direction of the motor spins are the Inputs 1A and 2A. The motors are connected to the outputs 1Y and 2Y. The L293 can control two DC motors so once you get it hooked up to the Arduino Ard-e can drive himself.
The data-sheet for the L293 can be found at http://www.datasheetcatalog.com/datasheets_pdf/L/2/9/3/L293.shtml
I ended up ordering two of the L293 chips from www.mouser.com and they cost me about $7. After a few hours of trial and error I finally got the Arduino to drive both of Ard-e's motors. I didn't read the data-sheet carefully enough because I originally was using 3V to try and run the L293 when it obviously (now at least its obvious) needs at least five volts. So after numerous trips to www.Arduino.cc here is the code I used to test drive Ard-e's motors:
int diraPin = 10;
int dirbPin = 9; //These two have to be opposite digital values to spin the motor if they are both HIGH or both LOW then the motor is actually braked.
int enablePin = 11; //This pin sets the speed of the motor and needs to be a PWM pin.
int dira2Pin = 2;
int dirb2Pin = 3;
int enable2Pin = 5; // These are used in the same way to drive the second motor.
int val = 0; // Variable used to set the speed of the motors.
void setup() {
pinMode(diraPin, OUTPUT);
pinMode(dirbPin, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(dira2Pin, OUTPUT);
pinMode(dirb2Pin, OUTPUT);
pinMode(enable2Pin, OUTPUT); // Declares all of the pins as outputs.
}
void loop() {
val = 175; //A value used for setting the speed of the motor, about 70% of its speed.
//Spin motor 1 backward for one second
analogWrite(enablePin, val); // Set the speed of the motors with PWM
digitalWrite(diraPin, LOW);
digitalWrite(dirbPin, HIGH);
//spin motor 2 backward for one second
analogWrite(enable2Pin, val);
digitalWrite(dira2Pin, LOW);
digitalWrite(dirb2Pin, HIGH);
delay(1000); // If you switch which direction pin is high and which is low the motor will spin a different direction.
//spin motor 1 forward for one second
digitalWrite(diraPin, HIGH);
digitalWrite(dirbPin, LOW);
//spin motor 2 forward for one second
digitalWrite(dira2Pin, HIGH);
digitalWrite(dirb2Pin, LOW);
delay(1000);
// stop for a second
val=0;
analogWrite(enablePin, val);
analogWrite(enable2Pin, val);
delay(1000);
}
So to test this out on Ard-e I ended up putting a breadboard onto the addition that had previously held the pan and tilt system. I also moved the Arduino right next to the breadboard for easy prototyping. I also had to add another two AA batteries so the the L293 would have the 6V it needs to power the motors.
Heres a quick video of Ard-e running this program. One of the motors spins faster than the other so he veers towards the camera near the end of it. I don't really know why this happens...
So once you write all of the code and rearrange the components to make the Arduino boss around the L293 and get those pesky DC motors under control Ard-e's possible uses increase dramatically. All you need now are some sensors.
| « Previous Step | Download PDFView All Steps | Next Step » |


















































Would this be caused by the first motor (#1) in line with the + would cause a voltage drop to motor (# 2)?. Would placing a resistor in line with M#1 control the voltage better?
Another possible work around for this is to use the chip to control the ground circuit from the motor.
Just a thought, as most DC motors in automotive interiors use "Hot" motors and use the PCM directly or the PCM controls micro relays to control the ground to operate.
NooB.