Stepper Motor with L293D Shield with Arduino Uno

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.

Subramanian
Subramanian

Subramanian MK, currently serving as a workshop instructor at Sakthi Polytechnic College, Erode Tamil Nadu. With a career spanning 25 + years, Subramanian MK has dedicated himself to advancing knowledge in Electronics and Communication Engineering (ECE). His passion for exploring new technologies has led to the development of numerous projects, showcasing expertise in IoT and PCB design.

Articles: 510

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

×

Hi, How can I help you?

×