Introduction: Controlling Stepper Motor With L293D

Picture of Controlling Stepper Motor With L293D

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!

Step 1: Connect All VCC

Picture of Connect All VCC

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.

Step 2: Connect the Common Ground

Picture of Connect the Common Ground

Connect pins 4, 5 12, and 13 all together and connect it to a common ground like the GND pin on an Arduino.

Step 3: Connect the Signal Wires

Picture of Connect the Signal Wires

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.

Step 4: Connect the Stepper

Picture of Connect the Stepper

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!

Step 5: Coding

Picture of Coding

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);
  }
}

Comments

About This Instructable

1,095views

28favorites

License:

Bio: Aerospace Engineer working in Software Development with a passion for Hardware.
More by TechMartian:Flying Captain America's Shield - RC PlaneWide Angle ShotsLED Ping Pong With Shift Register
Add instructable to: