I am a beginner to robotics and have purchased a arduino uno and a RK Education L293D Motor Drive board. (http://www.rkeducation.co.uk/documents/instructions/L293DpcbComponentListandInstructions.pdf). I am curious to know if i am driving two motors with this board do i need to have just the enable pins connected to the arduino or all 6 pins (4 input pins and 2 enable pins)?
I have done what you said and have connected the enable pins to the 5v on the arduino.
I coded it as follows:
int motor1Pin1 = 8; // pin 8 on L293D int motor1Pin2 = 9; // pin 9 on L293D int motor2Pin1 = 12; // pin 12 on L293D int motor2Pin2 = 13; // pin 13 on L293D
void setup() {
// set all the other pins you’re using as outputs: pinMode(motor1Pin1, OUTPUT); pinMode(motor1Pin2, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); }
void loop() { // turn motors one direction digitalWrite(motor1Pin1, LOW); // set pin 8 on L293D low digitalWrite(motor1Pin2, HIGH); // set pin 9 on L293D high digitalWrite(motor2Pin1, LOW); // set pin 12 on L293D low digitalWrite(motor2Pin2, HIGH); // set pin 13 on L293D high }
This code will not work but if i change the following code it will work but with each motor going in a different direction
}
void loop() { // turn motors one direction digitalWrite(motor1Pin1, HIGH); // set pin 8 on L293D low digitalWrite(motor1Pin2, LOW); // set pin 9 on L293D high digitalWrite(motor2Pin1, LOW); // set pin 12 on L293D low digitalWrite(motor2Pin2, HIGH); // set pin 13 on L293D high }
doesn’t work, what do you mean? The second loop() does as it should and cause the motors to turn in opposite directions. Does the first loop() not do anything or does only one motor turn?
That transistor is not a transistor. Its a voltage regulator. Ok, I am seeing how this board is put together.
Ok, forget what I said above, let me ask you this instead: How much power are you giving this board? Is it a 4AA battery pack? I need to know how much voltage you are using here.
I am supplying the board with 9 volts, the voltage is enough for the board as when i am using the second loop in my code both motors spin in the opposite direction.
Hey guys just an update i got the l293d all working it was a silly code error. ALL i has to do was change the code highlighted and both motors move in the same direction.
int motor1Pin1 = 8; // pin 8 on L293D int motor1Pin2 = 9; // pin 9 on L293D int enablePin1 = 7; // pin 7 on L293D int motor2Pin1 = 12; // pin 12 on L293D int motor2Pin2 = 13; // pin 13 on L293D int enablePin2 = 10; // pin 10 on L293D
void setup() {
// set all the other pins you’re using as outputs: pinMode(motor1Pin1, OUTPUT); pinMode(motor1Pin2, OUTPUT); pinMode(enablePin1, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); pinMode(enablePin2, OUTPUT);
// set enablePin high so that motor can turn on: digitalWrite(enablePin1, HIGH); digitalWrite(enablePin2, HIGH); }
void loop() { digitalWrite(motor1Pin1, LOW); // set pin 8 on L293D low digitalWrite(motor1Pin2, LOW); // set pin 9 on L293D low digitalWrite(motor2Pin1, HIGH); // set pin 12 on L293D high digitalWrite(motor2Pin2, HIGH); // set pin 13 on L293D high
First, thanks for letting us know you got it working.
Second, from the code that you have working it would seem as though you have not labeled the pins in a very helpful manner, or, you hooked them up in a less than correct manner.
Based on the pinout of the L293D:
Enable 1
Input 1
Output 1
Ground
Ground
Output 2
Input 2
Logic level Voltage
Enable 2
Input 3
Ouput 3
Ground
Ground
Output 4
Input 4
Motor level Voltage
From your code it would seem as if you have connected m1p1 and m1p2 to the top half h-bridges and m2p1 and m2p2 to the bottom half h-bridges. Rather than, m1p1/m1p2 to the left side and m2p1/m2p2 to the right side.
Thanks for that advice, if you look at the pdf i posted you will see the wiring layout for the rk electronics pcb, yet when hooking up the cabling explained in the pdf i have to code it the way i was coding it with one on low and low and the other on high and high.
All good rewired it and have it coded and working correctly now, using following code and hooked up a sharp ir sensor to it.
int motor1Pin1 = 4; // pin 8 on L293D int motor1Pin2 = 5; // pin 9 on L293D int enablePin1 = 2; // pin 7 on L293D int motor2Pin1 = 6; // pin 12 on L293D int motor2Pin2 = 7; // pin 13 on L293D int enablePin2 = 3; // pin 10 on L293D int sensorPin = A0; // Analog pin 0 is sensor input int dist; // represents the distance of the IR-Sensor
void setup() {
// set all the other pins you’re using as outputs: pinMode(motor1Pin1, OUTPUT); pinMode(motor1Pin2, OUTPUT); pinMode(enablePin1, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); pinMode(enablePin2, OUTPUT);
//Set Analog pin 0 as input pinMode (sensorPin, INPUT);
// set enablePin high so that motor can turn on: digitalWrite(enablePin1, HIGH); digitalWrite(enablePin2, HIGH);
if(dist>500) { digitalWrite(motor1Pin1, HIGH); // set pin 8 on L293D low digitalWrite(motor1Pin2, LOW); // set pin 9 on L293D high digitalWrite(motor2Pin1, HIGH); // set pin 12 on L293D low digitalWrite(motor2Pin2, LOW); // set pin 13 on L293D high }else{
digitalWrite(motor1Pin1, LOW); // set pin 8 on L293D low digitalWrite(motor1Pin2, HIGH); // set pin 9 on L293D high digitalWrite(motor2Pin1, LOW); // set pin 12 on L293D low digitalWrite(motor2Pin2, HIGH); // set pin 13 on L293D high