Controlling Stepper Motor With L293D
by TechMartian in Circuits > Electronics
10031 Views, 49 Favorites, 0 Comments
Controlling Stepper Motor With L293D
![Screen Shot 2017-08-23 at 10.01.59 AM.png](/proxy/?url=https://content.instructables.com/FM3/HOQK/J6MGIE9I/FM3HOQKJ6MGIE9I.png&filename=Screen Shot 2017-08-23 at 10.01.59 AM.png)
Most people don't work with stepper motor since they find it difficult to wire or code. However, stepper motors are one of the most important motor types used in Industry. The use cases for it is incredibly vast from calculating distances travelled using steps with extreme accuracy to precise robotic control by manipulating each magnetic pole of the motor.
The possibilities are endless! I wrote this to encourage everyone to use a stepper motor in their projects to improve the precision and accuracy by an order of magnitude and to show you that Yes! it can be this EASY!
Connect All VCC
![cAwgIFcmT8y2%+y9+LyX1A_thumb_769.jpg](/proxy/?url=https://content.instructables.com/F9H/0ODQ/J6MGHWA2/F9H0ODQJ6MGHWA2.jpg&filename=cAwgIFcmT8y2%+y9+LyX1A_thumb_769.jpg)
Connect all the pins requiring a 5V power with the breadboard wires. For the L293D these are pin 1, 8, 9 and 16, as found on the spec sheet.
Connect the Common Ground
![78sekKRPQaONxlOyixblUA_thumb_76a.jpg](/proxy/?url=https://content.instructables.com/FDE/A2M7/J6MGHW8G/FDEA2M7J6MGHW8G.jpg&filename=78sekKRPQaONxlOyixblUA_thumb_76a.jpg)
Connect pins 4, 5 12, and 13 all together and connect it to a common ground like the GND pin on an Arduino.
Connect the Signal Wires
![zRsPF5HzRJSinZesyC7nAA_thumb_76b.jpg](/proxy/?url=https://content.instructables.com/FT4/FDLT/J6MGHWD4/FT4FDLTJ6MGHWD4.jpg&filename=zRsPF5HzRJSinZesyC7nAA_thumb_76b.jpg)
![kv6aB+rmQr6f5iq5QFkLEg_thumb_76c.jpg](/proxy/?url=https://content.instructables.com/F6B/9NWR/J6MGHWBF/F6B9NWRJ6MGHWBF.jpg&filename=kv6aB+rmQr6f5iq5QFkLEg_thumb_76c.jpg)
Connect pins 2, 7, 10, and 15 to pins 9, 6, 5, and 3, respectively. Order is important, siren that is how polar motors are controlled like Steppers.
Connect the Stepper
![zadlEAZaTIOaBXZ0udHgEg_thumb_78b.jpg](/proxy/?url=https://content.instructables.com/FDL/4IMS/J6MGHWD3/FDL4IMSJ6MGHWD3.jpg&filename=zadlEAZaTIOaBXZ0udHgEg_thumb_78b.jpg)
![mx+m5yIkRuOUkk+GxvRC9g_thumb_78a.jpg](/proxy/?url=https://content.instructables.com/FVH/IP41/J6MGHWBK/FVHIP41J6MGHWBK.jpg&filename=mx+m5yIkRuOUkk+GxvRC9g_thumb_78a.jpg)
Connect pins 1 to 4 (from the black pin to the red pin) from the Stepper Motor to pins 3, 6, 11, and 14.
And you're done wiring it!
Coding
![Screen Shot 2017-08-23 at 10.00.04 AM.png](/proxy/?url=https://content.instructables.com/F5V/CJA0/J6MGIDG9/F5VCJA0J6MGIDG9.png&filename=Screen Shot 2017-08-23 at 10.00.04 AM.png)
Coding it is easy too, since the Arduino library did half of our job for us. You'll especially appreciate this if you have tried this in another micro controller board like PIC where you have code each pole for a half step, full step, etc.
#include <Stepper.h>
int in1Pin = 12; int in2Pin = 11; int in3Pin = 10; int in4Pin = 9; Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin); void setup() { pinMode(in1Pin, OUTPUT); pinMode(in2Pin, OUTPUT); pinMode(in3Pin, OUTPUT); pinMode(in4Pin, OUTPUT); // this line is for Leonardo's, it delays the serial interface // until the terminal window is opened Serial.begin(9600); motor.setSpeed(20); } void loop() { if (Serial.available()) { int steps = Serial.parseInt(); motor.step(steps); } }