Arduino UNO L293D Motor driver

Hello everyone,

I’m very new to arduino etc etc, but I’ve decided to go ahead and Hack an old toy car. For the time being I would like to get this old toy car to work forwards and backwards via Bluetooth / Android Phone. The Bluetooth actually does what it’s supposed to and drives the motor in both directions.
My problem is with the L293D. The motor runs at full speed when connected to the batteries directly (5.9V across the motor), but when connected to pins 3 & 6 of the L293D, it’ll only run at approximately 1/2 the required speed (3.6V across the motor).
I have attached a photo of the circuit diagram for your perusal (sorry its hand written).

Also here is the code which I cannot take any credit for whatsoever :slight_smile:

Hope someone can help

/*
 * created by Rui Santos, http://randomnerdtutorials.wordpress.com
 * Control DC motor with Smartphone via bluetooth
 * 2013
 */
int motorPin1 = 3; // pin 2 on L293D IC
int motorPin2 = 4; // pin 7 on L293D IC
int enablePin = 5; // pin 1 on L293D IC
int state;
int flag=0;        //makes sure that the serial only prints once the state
 
void setup() {
    // sets the pins as outputs:
    pinMode(motorPin1, OUTPUT);
    pinMode(motorPin2, OUTPUT);
    pinMode(enablePin, OUTPUT);
    // sets enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);
    // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
}
 
void loop() {
    //if some date is sent, reads it and saves in state
    if(Serial.available() > 0){     
      state = Serial.read();   
      flag=0;
    }   
    // if the state is '0' the DC motor will turn off
    if (state == '0') {
        digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
        digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
        if(flag == 0){
          Serial.println("Motor: off");
          flag=1;
        }
    }
    // if the state is '1' the motor will turn right
    else if (state == '1') {
        digitalWrite(motorPin1, LOW); // set pin 2 on L293D low
        digitalWrite(motorPin2, HIGH); // set pin 7 on L293D high
        if(flag == 0){
          Serial.println("Motor: right");
          flag=1;
        }
    }
    // if the state is '2' the motor will turn left
    else if (state == '2') {
        digitalWrite(motorPin1, HIGH); // set pin 2 on L293D high
        digitalWrite(motorPin2, LOW); // set pin 7 on L293D low
        if(flag == 0){
          Serial.println("Motor: left");
          flag=1;
        }
    }
}

Yes that’s right, the L293D will lose 2 to 4V as it has darlington output transistors. Its not really
designed for 6V use (people use it because its cheap and available in DIP package rather than
surface-mount). For low voltage a MOSFET H-bridge is more suitable.

Mark is right, you lose at least 1.5-2V in the L293 chip [4V sounds a little high], so the motors will always run slow. You might try figuring out how the h-bridges in the rc car work, and tapping in to control them with your processor. The h-bridge transistors are usually pretty obvious, so try to determine where the receiver connects to them, and connect the processor there, via a series-R for safety.

Thank you both for your replies.

The toy car is an old playskool bigfoot and only has a switch operated forward and reverse. Can you offer any suggestions for suitable mosfets, circuit diagram and modification to the arduino code to keep things simple?

Thanks again.

Limited amount of info to go on. You can look the following. You can use a relay for forward-reverse selection [eg 5V, 10A], and a MOSFET for speed control. The Arduino can drive the relay through an NPN transistor, and control the MOSFET gate using PWM. You'll have essentially full-voltage on the motor. Use a logic-level MOSFET, eg IRL540 [something with an "L" in the p/n], so the Arduino can drive the gate directly. Easier than building a complete MOSFET h-bridge.

http://www.google.com/search?hl=en&site=imghp&tbm=isch&source=hp&biw=1033&bih=858&q=relay+motor+control

http://www.jpelectron.com/sample/electronics/ http://www.jpelectron.com/sample/electronics/Motor-%20Basic%20relay%20direction%20control.gif

http://www.google.com/search?hl=en&site=imghp&tbm=isch&source=hp&biw=1033&bih=858&q=relay+motor+control http://rayshobby.blogspot.com/2011/02/mosfet-based-fix-to-makerbot-extruder.html

There are also better quality motor controllers than the L293, although they cost a bit, eg http://www.pololu.com/catalog/category/11

Thanks for all the helpful links and info. Looks like another project on the horizon for me :)