In this tutorial, we'll be looking at how to power and drive a DC motor with an L293D and an Arduino (we're using the Arduino MKR 1000 here, but you can use any Arduino that provides enough voltage for your motor, and has 2 digital output pins). The L293D is a 16-pin Motor Driver IC which can control up to two DC motors simultaneously, in any direction.
- Arduino board of your choice
- Micro USB cable
- L293D motor driver
- DC motor
- Jumper wires
First, let's hook up the components on the breadboard. Below you'll see a pin diagram of the L293D - note the location of each of the pins, relative to the notch at the top.
Since we're just driving one motor for this tutorial, we won't be using all of the motor driver's pins.
- Start by plugging your Arduino into a power source (such as your computer)
5Von the Arduino to one side of the breadboard, and extend to the other side with jumper wires
- Place the L293D in the center of the breadboard, with half of the pins on either side of the breadboard
Vson the L293D
- Connect digital output pins (we're using 6 and 7) to
input 2on the L293D
- Connect your Arduino's
GNDpins on the same side of the L293D
- Finally, connect
output 2of the L293D to your motor pins
Vspin on the motor driver supplies power to the motor. If your motor requires more voltage than your Arduino can provide, you can hook up an external battery or battery pack. Simply connect the negative lead to GND on the breadboard, and the positive lead to the
Vspin of the L293D.
Once that's all connected, it should look a little something like this:
Note: If you are completely unfamiliar with the Arduino IDE, watch this video to give you a better understanding of how it works.
In the Arduino IDE:
- Make sure the correct port is selected under
Tools > Port
- Make sure the correct Arduino board is selected under
Tools > Board
- Click on File > New to create a new Sketch
- Copy and paste the code below labeled 'Arduino IDE', replacing the
motorPin2values if you're using output pins other than 6 and 7 on your Arduino
- Go to
Sketch > Uploadto upload the code to your Arduino
Once the sketch is uploaded successfully, the motor will turn in one direction. If you want to change the direction, simply reverse
LOW in the