How to Use the L293D Motor Driver - Arduino Tutorial

257,844

279

45

Introduction: How to Use the L293D Motor Driver - Arduino Tutorial

About: Arduino Tutorials by Codebender.cc Team

The L293D is a 16-pin Motor Driver IC which can control a set of two DC motors simultaneously in any direction. The L293D is designed to provide bidirectional drive currents of up to 600 mA (per channel) at voltages from 4.5 V to 36 V (at pin 8!). You can use it to control small dc motors - toy motors. Sometimes it can be extremely hot.

In this tutorial you will learn how to use it with Arduino uno to control two dc motors.

Step 1: What You Will Need

For this project you will need:

  • Arduino uno
  • Breadboard
  • L293D Motor Driver IC
  • 2x (small) DC motors

Step 2: The Circuit

The connections are easy, see the image above with the breadboard circuit schematic.

Tip: You can connect an external power source to L293D pin 8, up to 36V! Make sure not to "burn" your motors!

Step 3: The Code

Here's the code, embedded using codebender!

Try downloading the codebender plugin and clicking on the Run on Arduino button to program your Arduino with this sketch. And that's it, you've programmed your Arduino board!


You can keep playing with that by clicking the "Edit" button and start making your own modifications to the code. For example try to combine parts of code to move both motors simultaneously.

Try to use analogWrite(pin, PWM value) instead digitalWrite(pin, HIGH/LOW) to control the speed of motors!

Step 4: Well Done!

You have successfully completed one more Arduino "How to" tutorial and you learned how to use the L293D motor driver IC to control two dc motors with the Arduino uno board.

I hope you liked this, let me know in the comments.
There will be more of them, so make sure to click Follow button!

2 People Made This Project!

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Automation Contest

    Automation Contest
  • Make it Glow Contest

    Make it Glow Contest

45 Comments

0
cia-21
cia-21

4 years ago

Hey, can I make a variable speed driver with L293D?

0
cia-21
cia-21

4 years ago

Hey, can I make a variable speed driver with L293D?

0
PramêshB1
PramêshB1

Reply 3 years ago

Yeah, using analogwrite instead of digitalwrite & assigning values

0
naimulislam19149
naimulislam19149

Question 3 years ago on Introduction

I am new to electronics and I am not understanding exactly, why I need to use a motor controller IC? Can't I use my arduino only to run a DC motor?

0
R4Y Arduino
R4Y Arduino

Answer 6 months ago

you dont need it but if you have strong motor, you should use it. if you dont use it the motor can pull too much power from your arduino and break it

0
vicwealth
vicwealth

Question 2 years ago on Step 4

How can I make the motors change direction of movement. to the left or right

0
R4Y Arduino
R4Y Arduino

Answer 6 months ago

you can change it in the code

0
merenguele
merenguele

Answer 2 years ago

Look that there are 4 motor wires, 2 by each motor. When turning in one direction you put HIGH and LOW (ex: pin1: HIGH, pin2: LOW) and the other direction the reverse (ex: pin1: LOW, pin2: HIGH). Never HIGH,HIGH.

Notice that LOW/LOW: Is a stoped motor.

0
hanskarthaus
hanskarthaus

10 months ago

Guten Tag, mein erster Arduino uno und ich habe es auf Anhieb geschafft, die beiden Motoren zum arbeiten zu bewegen. Danke, sogar einen Motor Stop kann ich programmieren und begreife so langsam das Prinzip.Ich brauche das Programm um auf meiner Modelleisenbahn einen Kranwagen zu steuern.30 Grad nach rechts, dann Gewicht am Haken ab und auf, dann wieder Kran zurück schwenken und wieder Gewicht ab und auf. Dies soll sich 4 x wiederholen. Auslöser ist ein Taster.
Herzliche Grüße.
HJK

0
SatyaD4
SatyaD4

1 year ago

i connected Arduino uno to L293 IC its working, and want to design a toxic detector robot in mines to avoid death loses this is my mini project and i used MQ135, servo motor,sensor Arduino uno, 2 Gear motors and robot chassis and i write the code using ( if ) condition but it not working well, could have any alternate way to do this thank you
link: http://bigbelectronics.in/product.php?product=ic-l293dne-quadruple-half-h-driver

0
ShankarB11
ShankarB11

1 year ago

i connected Arduino uno to L293 IC its working, and want to design a toxic detector robot in mines to avoid death loses this is my mini project and i used MQ135, servo motor,sensor Arduino uno, 2 Gear motors and robot chassis and i write the code using ( if ) condition but it not working well, could have any alternate way to do this thank you

i buy L293D IC in this site it has very reasonable price in online electronics product

http://bigbelectronics.in/product.php?product=ic-l293dne-quadruple-half-h-driver

0
NayanP7
NayanP7

2 years ago

Can I use 300 RPM gear motors?

1
chandrajit_choudhary

Can I control the motors in both the directions using non PWM i/o terminals on the arduino uno

0
merenguele
merenguele

Reply 2 years ago

You can either use Digital output (High/Low) from arduino to go ON/Off to control the moto, and you can go further and apply PWM (need a PWM out + Digital out) to control speed. Digital turns on the motor in the direction you want and PWM tells at what speed.

0
Windnsails
Windnsails

Question 2 years ago

Is the code also applicable for the Nano?

0
merenguele
merenguele

Answer 2 years ago

Yes, you only have to look for pin equivalence. Remember that the number of the pins are not the same as the name of the ports. Ex: pin number 27 can be D10 (writing by memory). And you put in your code the pin number, not the port.

0
RashmiP12
RashmiP12

Question 2 years ago

Can I use three 100 rpm BO motor to connect with L293d?
Why L293d is required to interface BO motor to arduino, how much current required for BO motor and supplied by arduino.?

0
RahulS556
RahulS556

Answer 2 years ago

Hiii,

The following Code is for creating the robot with 2 DC motors.

const int motorPin1 = 5;

const int motorPin2 = 6;

const int motorPin3 = 7;

const int motorPin4 = 8;

void setup(){

//Set pins as outputs

pinMode(motorPin1, OUTPUT);

pinMode(motorPin2, OUTPUT);

pinMode(motorPin3, OUTPUT);

pinMode(motorPin4, OUTPUT);

}

void loop()

{

digitalWrite(motorPin1, HIGH);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, LOW);

delay(2000);

digitalWrite(motorPin1, LOW);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, HIGH);

delay(2000);

}