In this guide, we will walk you through controlling a 28BYJ-48 stepper motor using an Arduino and a ULN2003 driver. This tutorial aims to provide a hands-on experience for enthusiasts and beginners in the field of electronics and robotics. For a detailed explanation and additional resources, visit my blog post at Stepper Motor Control with Arduino.
Materials Needed
Arduino UNO
28BYJ-48 Stepper Motor
ULN2003 Driver Module
Jumper Wires
Breadboard (optional)
Power Supply (optional)
Understanding the Components
28BYJ-48 Stepper Motor: This stepper motor is known for its low cost and reliability. It has a 5-wire interface that connects to the ULN2003 driver.
ULN2003 Driver Module: The ULN2003 is a Darlington transistor array used to drive the stepper motor. It provides the necessary current and voltage to the motor from the Arduino signals.
Circuit Connections
Connecting the Motor to the Driver
Connect the 5-wire connector of the 28BYJ-48 stepper motor to the ULN2003 driver module.
Connecting the Driver to the Arduino
- Connect the IN1 pin on the ULN2003 to the digital pin 7 on the Arduino.
- Connect the IN2 pin on the ULN2003 to the digital pin 6 on the Arduino.
- Connect the IN3 pin on the ULN2003 to the digital pin 5 on the Arduino.
- Connect the IN4 pin on the ULN2003 to the digital pin 4 on the Arduino.
- Connect the GND pin on the ULN2003 to a GND pin on the Arduino.
- Connect the VCC pin on the ULN2003 to the 5V pin on the Arduino.
Arduino Code
Upload the following code to your Arduino
#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
}
Top comments (0)