Stepper Motors with L293D Shield
Let’s connect stepper motor to the L293D shield. Start by plugging the shield on the top of the Arduino.

28BYJ-48 unipolar stepper:
If you are using 28BYJ-48 unipolar stepper, those motors are rated at 5V and offer 48 steps per revolution. So, connect external 5V power supply to the EXT_PWR terminal.
Remember to remove the PWR jumper.

Now, connect the motor to either M1-M2(port#1) or M3-M4(port#2) stepper motor terminals. In our experiment we are connecting it to M3-M4.

NEMA 17 bipolar stepper:
If you are using NEMA 17 bipolar stepper, those motors are rated at 12V and offer 200 steps per revolution. So, connect external 12V power supply to the EXT_PWR terminal.
Remember to remove the PWR jumper.

Now, connect the motor to either M1-M2(port#1) or M3-M4(port#2) stepper motor terminals. In our experiment we are connecting it to M3-M4.

Arduino Code:
The following sketch will give you complete understanding on how to control a unipolar or bipolar stepper motor with L293D shield and is same for both the motors except.

#include 
// Number of steps per output rotation
// Change this as per your motor's specification
const int stepsPerRevolution = 48;
// connect motor to port #2 (M3 and M4)
AF_Stepper motor(stepsPerRevolution, 2);

void setup()
{
  Serial.begin(9600);
  Serial.println("Stepper test!");
  motor.setSpeed(10);  // 10 rpm   
}
void loop() 
{
  Serial.println("Single coil steps");
  motor.step(100, FORWARD, SINGLE); 
  motor.step(100, BACKWARD, SINGLE); 

  Serial.println("Double coil steps");
  motor.step(100, FORWARD, DOUBLE); 
  motor.step(100, BACKWARD, DOUBLE);

  Serial.println("Interleave coil steps");
  motor.step(100, FORWARD, INTERLEAVE); 
  motor.step(100, BACKWARD, INTERLEAVE); 

  Serial.println("Micrsostep steps");
  motor.step(100, FORWARD, MICROSTEP); 
  motor.step(100, BACKWARD, MICROSTEP); 
}

Two functions to control the speed and spinning direction of a motor.
setSpeed(rpm) function sets the speed of the motor, where rpm is how many revolutions per minute you want the stepper to turn.
step(#steps, direction, steptype) function is called every time you want the motor to move. #steps is how many steps you’d like it to take. direction is either FORWARD or BACKWARD, and valid values for step style are:

SINGLE – One coil is energized at a time.
DOUBLE – Two coils are energized at a time for more torque.
INTERLEAVE – Alternate between single and double to create a half-step in between. This can result in smoother operation, but because of the extra half-step, the speed is reduced by half too.
MICROSTEP – Adjacent coils are ramped up and down to create a number of ‘micro-steps’ between each full step. This results in finer resolution and smoother rotation, but with a loss in torque.

About the Author

Subramanian

Hello! My Dear Friends. I am Subramanian. I am writing posts on androiderode about Electronics testing and equipments.

View All Articles