Rachana Jain
Published © Apache-2.0

How to Control 28BYJ-48 Stepper Motor with Arduino

In this article, we’ll learn about stepper motors, the 28BYJ-48 motor, and how to control it using Arduino.

BeginnerFull instructions provided2 hours142
How to Control 28BYJ-48 Stepper Motor with Arduino

Things used in this project

Hardware components

28BYJ-48 stepper motor
×1
Arduino UNO R3
×1
ULN2003 driver module
×1
Jumper wires (generic)
Jumper wires (generic)
×1
5V power supply
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Arduino Code

Arduino
/* 
Interfacing Stepper Motor with Arduino UNO using Stepper Library using ULN 2003 Motor driver board by www.playwithcircuit.com 
*/
#include <Stepper.h>
//define Input pins of the Motor
#define OUTPUT1   7                // Connected to the Blue coloured wire
#define OUTPUT2   6                // Connected to the Pink coloured wire
#define OUTPUT3   5                // Connected to the Yellow coloured wire
#define OUTPUT4   4                // Connected to the Orange coloured wire
// Define the number of steps per rotation
const int stepsPerRotation = 2048;  // 28BYJ-48 has 2048 steps per rotation in full step mode as given in data sheet
// Initialize the stepper motor with the sequence of control pins OUTPUT1, OUTPUT3, OUTPUT2, IN4
// OUTPUT1 and OUTPUT3 are connected to one coil and OUTPUT2 and OUTPUT4 are connected to one Coil
Stepper myStepper(stepsPerRotation, OUTPUT1, OUTPUT3, OUTPUT2, OUTPUT4);  
void setup() {
  // Set the speed of the motor in RPM (adjust as needed)
  myStepper.setSpeed(15);  // 15 RPM
}
void loop() {
  // Rotate in One Direction and complete one complete rotation i.e 2048 steps
  myStepper.step(stepsPerRotation);  
  delay(1000);  // Delay between rotations
  // For Rotation in opposite direction provide the variable to the parameter with negative Sign
  myStepper.step(-stepsPerRotation);  
  delay(1000);  // Delay between rotations
}

Credits

Rachana Jain
10 projects • 8 followers
I'm an avid Arduino and electronics enthusiast with a passion for tinkering, experimenting, and bringing innovative ideas to life.
Contact

Comments

Please log in or sign up to comment.