loading

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.

<p>used this circuit as primary level project in my college thank you very much</p>
<p>can someone help?<br></p><p>char COM; //Variable creation</p><p>int motor1Pin1 = 3; // pin 2 on L293D</p><p>int motor1Pin2 = 4; // pin 7 on L293D</p><p>int enablePin = 9; // pin 1 on L293D</p><p>void setup()</p><p>{</p><p> Serial.begin(9600); // Begins a Serial with a 9600bps Baud Rate(</p><p> pinMode(motor1Pin1, OUTPUT);</p><p> pinMode(motor1Pin2, OUTPUT);</p><p> pinMode(enablePin, OUTPUT);</p><p>}</p><p>void loop()</p><p>{</p><p> if (Serial.available() &gt; 0)</p><p> {</p><p> COM = Serial.read();</p><p> switch (COM)</p><p> {</p><p> case '8'://FORWARD</p><p> digitalWrite(motor1Pin1,255, 1);</p><p> digitalWrite(motor1Pin2,255, 1);</p><p> break; // switch OFF</p><p> case '4'://LEFT</p><p> digitalWrite(motor1Pin1,255, 0);</p><p> digitalWrite(motor1Pin2,255, 1);</p><p> break; //switch OFF</p><p> case '2'://BACK</p><p> digitalWrite(motor1Pin1,255, 0);</p><p> digitalWrite(motor1Pin2,255, 0);</p><p> break; //switch OFF</p><p> case '6'://RIGHT</p><p> digitalWrite(motor1Pin1,255, 1);</p><p> digitalWrite(motor1Pin2,255, 0);</p><p> break; //switch OFF</p><p> }</p><p> delay(250); // 250 mili seconds Delay</p><p> digitalWrite(motor1Pin1,255, 1);</p><p> digitalWrite(motor1Pin2,255, 1);</p><p> COM = 0;</p><p> }</p><p>}</p>
<p>this program is correct or not?</p><p>u will execute this program?</p>
<p>Hello , I want to know how we can do it with out a switch. Can you give me any clue, please?</p>
<p>Thanks for this circuit - it worked well first time.</p><p>I am however rather at a loss to understand how the motor speed is controlled through the L293D ic. I have used the pot, analog input and PWM output to control a motor but I cannot see how the pwm output controls the motor speed here. </p><p>Rob</p>
<p>Ive got this working. Really helped me with a project.</p><p>Ive upgraded to a 24v motor, and wanted to know how would we connect it without frying the L293 chip or the arduino.</p><p>I know we would need mosfets / transistors(noobie appologies)</p><p>Thanks. </p>
Use L293N for your perpose
<p>Thanks,</p><p>I tried the L298N Motor driver, works good.<br><br>I also check alternate methods to work with high voltage motors, it was with using relays. But that is for some other time to experiment with :-p</p>
<p>Feel free if u have some doubt.. i will try to clarify it.. </p>
<p>Hello sir,</p><p> I am driving a 24V DC motor using arduino uno. No any special motor driver i am using.motor drives only by SPDT relay for more current requirement.but i can not control the speed of motor.so please tell me how i control the speed of motor using relay itself.or send me code of that.</p><p>Regards,</p><p>Vinod Kumbhar.</p>
<p>Hi Surya,</p><p>Thanks for this. I have very limited or no knowledge about electronics. I am doing a DIY project just by reading stuff and using my common sense. So my questions may be ... you know :-)</p><p>I am using a 12v DC motor. I have completed the project with no electronics (relays, limit switches etc). I want to re-do the project using electronic components so that I can get more control over the working. </p><p>I read in some other place that if I use 12V motor, I need to use transistors, diodes and capacitors to manage the current without damaging the Arduino. </p><p>Can you confirm this and if possible, can you send me a connection diagram? Thanks.</p><p>-- Senthil</p>
<p>Thank You senthil for your comment..It is actually required to use capacitors transistors and diodes to control a 12v D.C.Motor without damaging the arduino because the arduino can only handle upto 5v input power and a 12v dc motor will produce 12v directly to the I/O pins of the arduino and it may start smoking.....You can check out this site for circuit diagram..<a href="https://www.google.co.in/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=0CAcQjRw&url=http%3A%2F%2Felectronics.stackexchange.com%2Fquestions%2F102022%2Fhow-to-control-the-speed-of-a-12v-dc-motor-with-an-arduino&ei=EypoVdnxEYecugT6oYKwBg&psig=AFQjCNG94RFVXNbxG8VFQ9nbctk97jBPMA&ust=1432976282185110" rel="nofollow">https://www.google.co.in/url?sa=i&amp;rct=j&amp;q=&amp;esrc=s&amp;...</a></p>
Thanks Surya. I will check this out. Thanks for hour time.
<p>Do u have any video on this project?</p>

About This Instructable

83,149views

80favorites

License:

More by Surya Krishnakumar:Arduino HCSR04 leds distance warner Arduino DC motor speed control potentiometer Arduio Dc motor speed control serial monitor ..(no l293d) 
Add instructable to: