How to drive dc motor using L293D with arduino
First make ground and Vcc connections on the breadboard from arduino.
Before proceeding further it is recommended that you read and understand the pin diagram of L293D
Pin diagram of L293D

Connections
L293D |
Arduino |
|
Enable 1 |
5V |
|
Input 1 |
Digital output pin.Pin no is upto you (I have used 3) |
|
Output 1 |
motor wire 1 |
|
GND |
Ground |
|
GND |
Ground |
|
Output 2 |
Motor wire 2 |
|
Input 2 |
Digital output pin.Pin no is upto you(i have used 4) |
|
Vs |
Power supply for motors |
|
Vss |
5V |
The below image shows SN754410 H-bridge which is compatible with L293D and it is the pin to pin replacement.So that means we can use L293D in the circuit made using SN754410 and vice versa
Now make connections for driving the motor as shown in below figure
In this method we are using external power supply for the arduino board and the same power supply is being used by the motors.i.e we are powering the motors from Vin on arduino.
Note: Using the below circuit will power your motor with 9V so you should use a 9V or a higher voltage motor.

However you can also use the USB power to power the arduino board and an external power supply to power the motors directly
Other option is if you want to use two power(battery) supply you can just simply connect a 9V battery to the power plug of arduino board.In this way the arduino will get 9V and the motors will get 6V( or whatever voltage you used) through the second battery.(For the below circuit)

Code:
// Community of Robots//
//Dc motor example code//
int motorpin1 = 3; //define digital output pin no.
int motorpin2 = 4; //define digital output pin no.
void setup () {
pinMode(motorpin1,OUTPUT); //set pin 3 as output
pinMode(motorpin2,OUTPUT); // set pin 4 as output
}
void loop () {
digitalWrite(motorpin1,LOW);
digitalWrite(motorpin2,HIGH);
}
If you will copy paste the above code then motor will run in one direction.To drive the motor in opposite direction you just need to put HIGH instead of LOW and vice versa.
Got any problem ? post a comment













A question
Which software has been used to make the awesome illustrations of the Arduino and the breadboard layout above? I have searched and downloaded several but nothing looks this good.
MtaraM (aka Utkarsh)
Solution Architect by profession, Engineer by thought.
http://mtaram.com/blog
www.fritzing.org
www.fritzing.org
Thanks
:)
MtaraM (aka Utkarsh)
Solution Architect by profession, Engineer by thought.
http://mtaram.com/blog