Controlling a 28BYJ-48 Stepper Motor with Wemos D1 Mini and ULN2003A
Overview
Section titled “Overview”This guide demonstrates how to control a 28BYJ-48 stepper motor using a Wemos D1 Mini (ESP8266) board and ULN2003A driver module. The 28BYJ-48 is a popular, inexpensive stepper motor commonly used in DIY projects for precise positioning and automation.
Components Required
Section titled “Components Required”- Wemos D1 Mini (ESP8266 board)
- 28BYJ-48 stepper motor (5V or 12V version)
- ULN2003A stepper motor driver module
- Jumper wires
- Power supply (5V or 12V depending on motor)
- USB cable for programming
Wiring Diagram
Section titled “Wiring Diagram”flowchart LR
subgraph "Wemos D1 Mini"
D1[D1 GPIO5]
D2[D2 GPIO4]
D3[D3 GPIO0]
D4[D4 GPIO2]
end
subgraph "ULN2003A Driver"
IN1[IN1]
IN2[IN2]
IN3[IN3]
IN4[IN4]
VCC[VCC +]
GND[GND -]
end
subgraph "28BYJ-48 Motor"
BLUE[Blue Wire]
PINK[Pink Wire]
YELLOW[Yellow Wire]
ORANGE[Orange Wire]
RED[Red Wire +5V]
end
D1 --> IN1
D2 --> IN2
D3 --> IN3
D4 --> IN4
IN1 --> BLUE
IN2 --> PINK
IN3 --> YELLOW
IN4 --> ORANGE
VCC --> RED
Pin Connections
Section titled “Pin Connections”| Wemos D1 Mini Pin | ULN2003A Pin | Motor Wire Color |
|---|---|---|
| D1 (GPIO5) | IN1 | Blue |
| D2 (GPIO4) | IN2 | Pink |
| D3 (GPIO0) | IN3 | Yellow |
| D4 (GPIO2) | IN4 | Orange |
| 5V | VCC (+) | Red |
| GND | GND (-) | - |
Arduino IDE Setup
Section titled “Arduino IDE Setup”-
Install ESP8266 Board Support
Open Arduino IDE and go to File > Preferences. Add this URL to “Additional Boards Manager URLs”:
http://arduino.esp8266.com/stable/package_esp8266com_index.json -
Install ESP8266 Board
Go to Tools > Board > Boards Manager, search for “esp8266”, and install the ESP8266 package.
-
Select Board
Go to Tools > Board and select “LOLIN(WEMOS) D1 R2 & mini”.
-
Install Stepper Library
Go to Sketch > Include Library > Manage Libraries, search for “Stepper”, and install the built-in Stepper library.
Basic Control Code
Section titled “Basic Control Code”#include <Stepper.h>
// Define number of steps per revolutionconst int stepsPerRevolution = 2048; // 28BYJ-48 has 2048 steps per revolution
// Initialize stepper motor on pins D1, D2, D3, D4Stepper myStepper(stepsPerRevolution, D1, D3, D2, D4); // Note the pin order for proper sequence
void setup() { // Set the speed to 10 rpm myStepper.setSpeed(10);
// Initialize serial communication Serial.begin(115200); Serial.println("Stepper Motor Control Ready");}
void loop() { // Rotate clockwise 1 revolution Serial.println("Clockwise"); myStepper.step(stepsPerRevolution); delay(1000);
// Rotate counterclockwise 1 revolution Serial.println("Counterclockwise"); myStepper.step(-stepsPerRevolution); delay(1000);}Advanced Control Features
Section titled “Advanced Control Features”Speed Control
Section titled “Speed Control”// Different speeds for different applicationsmyStepper.setSpeed(5); // Slow for precisionmyStepper.step(512); // Quarter turn
myStepper.setSpeed(15); // Faster for quick movementsmyStepper.step(1024); // Half turnMicrostepping
Section titled “Microstepping”The 28BYJ-48 can be controlled with half-steps for smoother operation:
// Half-step mode (4096 steps per revolution)const int halfStepsPerRevolution = 4096;Stepper myStepper(halfStepsPerRevolution, D1, D3, D2, D4);Position Control
Section titled “Position Control”void rotateDegrees(float degrees) { // Calculate steps needed (2048 steps = 360 degrees) int steps = (degrees / 360.0) * stepsPerRevolution; myStepper.step(steps);}
// Example usagerotateDegrees(90); // Rotate 90 degrees clockwiserotateDegrees(-45); // Rotate 45 degrees counterclockwiseWiFi Control (ESP8266 Feature)
Section titled “WiFi Control (ESP8266 Feature)”Since the Wemos D1 Mini has WiFi capabilities, you can control the motor remotely:
#include <ESP8266WiFi.h>#include <ESP8266WebServer.h>#include <Stepper.h>
const char* ssid = "YourWiFiSSID";const char* password = "YourWiFiPassword";
ESP8266WebServer server(80);Stepper myStepper(stepsPerRevolution, D1, D3, D2, D4);
void setup() { myStepper.setSpeed(10);
WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); }
server.on("/clockwise", []() { myStepper.step(512); // Quarter turn server.send(200, "text/plain", "Rotated clockwise"); });
server.on("/counterclockwise", []() { myStepper.step(-512); server.send(200, "text/plain", "Rotated counterclockwise"); });
server.begin();}
void loop() { server.handleClient();}Applications
Section titled “Applications”Robotics and Automation
Section titled “Robotics and Automation”- Robot arm positioning
- CNC machine control
- Automated blinds/curtains
- Camera pan/tilt mechanisms
Measurement Devices
Section titled “Measurement Devices”- Precision gauges
- Antenna rotators
- Solar panel trackers
- Laboratory equipment
Consumer Products
Section titled “Consumer Products”- Vending machines
- ATM machines
- Printers and scanners
- DVD players
Troubleshooting
Section titled “Troubleshooting”Motor Not Moving
Section titled “Motor Not Moving”- Check power supply voltage (5V or 12V as required)
- Verify all connections are secure
- Ensure correct pin mapping in code
- Check if ULN2003A module has power
Motor Vibrating but Not Rotating
Section titled “Motor Vibrating but Not Rotating”- Wrong stepper motor type (unipolar vs bipolar)
- Incorrect coil sequence in code
- Insufficient power supply current
Motor Running Slowly
Section titled “Motor Running Slowly”- Increase speed setting in
setSpeed() - Check power supply capacity
- Reduce load on motor shaft
WiFi Connection Issues
Section titled “WiFi Connection Issues”- Verify SSID and password
- Check WiFi signal strength
- Ensure ESP8266 firmware is up to date
Performance Specifications
Section titled “Performance Specifications”| Parameter | Value |
|---|---|
| Step Angle | 5.625° / 64 (half-step mode) |
| Steps per Revolution | 2048 (full step), 4096 (half step) |
| Rated Voltage | 5V or 12V DC |
| Current per Phase | ~150mA |
| Holding Torque | 34.3mN·m (3.3kg·cm) |
| Operating Temperature | -10°C to +40°C |
Safety Considerations
Section titled “Safety Considerations”- Always disconnect power when making wiring changes
- Ensure proper ventilation for motor during extended operation
- Use appropriate power supply ratings
- Avoid overloading the motor shaft
- Keep motor away from flammable materials