Introduction: Arduino DC Motor Speed and Direction L293D

This instructable will guide you through the parts and steps to control a Dc motor's speed and direction with the help of a dual H-Bridge L293D motor driver for arduino.

The motor driver has two channels which means that it can controll the direction of two Dc motors simultaneously.

Let me walk you through the parts required to do this...and then the steps with codes.

Step 1: Part List

1) Arduino uno.. Original version cheaply available at http://www.ebay.co.uk/itm/UNO-R3-Arduino-MEGA328P...

2) L293D... 5pcs available for 1.59 euros at http://www.ebay.co.uk/itm/Hot-5Pcs-DIP-16-Line-L2...

3) Tactile push button.. 100pcs for .99 euros at http://www.ebay.co.uk/itm/4pin-100pcs-Tactile-Pus...

4) 10K potentiometer... http://www.ebay.co.uk/itm/Mini-10K-OHM-Linear-Tap...

5) Breadboard.. http://www.ebay.co.uk/itm/400-Points-Solderless-B...

6) Jumper wires... http://www.ebay.co.uk/itm/65Pcs-Male-to-Male-Sold...

7) Computer with arduino IDE... I cannot provide link to this u know.

Step 2: L293D Pin Layout

Step 3: Breadboard Layout

NOW lets get working.

Step 4: Attach the L293D, Potentiometer and the Button Onto the Breadboard..

L293D PINS CONNECTION

PIN1(Enable1) -- DigitalPin11(PWM)

PIN2(INPUT1) -- DigitalPin10(PWM)

PIN3(OUTPUT1) -- MOTOR PIN 1

PIN4(GND1) -- Gnd

PIN6(OUTPUT2) -- MOTOR PIN 2

PIN7(INPUT2) -- DigitalPin9(PWM)

PIN8(12v) -- 5v

PIN9(Vss3.3v) -- 5v/// the pin says 3.3v but u can connect it to 5v also.

POTENTIOMETER PINS CONNECTION

Pin1(positive)-- 5v

Pin2(signal) -- analogPIN0

PIn3(negative) -- Gnd

PUSH BUTTON PINS CONNECTION

1PIN= Gnd

2PIN = DigitalPIN7

Step 5: Arduino Code

/*

*/

int enablePin = 11;

int in1Pin = 10;

int in2Pin = 9;

int switchPin = 7;

int potPin = 0;

int statusPin= 13;

void setup()

{

pinMode(in1Pin, OUTPUT);

pinMode(in2Pin, OUTPUT);

pinMode(enablePin, OUTPUT);

pinMode(switchPin, INPUT_PULLUP);

pinMode(statusPin,OUTPUT);

}

void loop()

{

digitalWrite(13,HIGH);

int speed = analogRead(potPin) / 4;

boolean reverse = digitalRead(switchPin);

setMotor(speed, reverse);

}

void setMotor(int speed, boolean reverse)

{

analogWrite(enablePin, speed);

digitalWrite(in1Pin, ! reverse);

digitalWrite(in2Pin, reverse);

}

Step 6: That's It Your Done!!

Turn the potentiometer to control the speed of the motor and press the button to change the direction.