RK Education L293D board

Hi All

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)?

Regards

CJGAUS

Dear ChuckI have done what

Dear Chuck

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
  }

 

would you happen to know what i am doing wrong?

When you say your first loop()

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?

Hi BirdmanThe first loop

Hi Birdman

The first loop does completely nothing (no motors spinning), the second loop when uploaded will turn both motors in the opposite direction.

Still no solution

Hey guys I still have no solutions, any others got any idea what im doing wrong?

5v?

In addition to the enable pins and the power for the motors themselves, do you also have a 5v supply going in for some thinkin’ power?

Oh, wait a sec…

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.

Need more infos. How about

Need more infos. How about some pictures or schematic of your hardware setup. What power supply? GND connected on UNO and L293 board?

voltage

Hi Chris

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.

Cheers

Alright, I am with RoboFreak then…

Are you sharing grounds?

grounds

sorry im not sure what you mean by that question?

Shared grounds

No matter if you are using one power supply or 2, you will need to have all grounds (from everything) connected together.

grounds

have the grounds shared still no go.

shared grounds reply

thanks chris i have done what you said with no luck, still getting the same issue

ALL WORKING

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:

  1. Enable 1
  2. Input 1
  3. Output 1
  4. Ground
  5. Ground
  6. Output 2
  7. Input 2
  8. Logic level Voltage
  9. Enable 2
  10. Input 3
  11. Ouput 3
  12. Ground
  13. Ground
  14. Output 4
  15. Input 4
  16. 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

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.

To satisfy my curiosity

is there any possibility that you could post a picture that shows your wiring? Or, just tell me how you have the following hooked up.

M082438P01WM.jpg

MA1                                          MB1
MA2                                          MB2
EN1                                           EN2
IP1                                            IP3
IP2                                            IP4
V+
V- 

All good

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);
 
  Serial.begin(9600);
}

void loop() {
//var dist contains distance
dist = analogRead(0);

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
   
}   
}

Good to see

Glad you are making progress with your robot.