Skip to content

Controlling a 28BYJ-48 Stepper Motor with Wemos D1 Mini and ULN2003A

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.

  • 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
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
Wemos D1 Mini PinULN2003A PinMotor Wire Color
D1 (GPIO5)IN1Blue
D2 (GPIO4)IN2Pink
D3 (GPIO0)IN3Yellow
D4 (GPIO2)IN4Orange
5VVCC (+)Red
GNDGND (-)-
  1. 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
  2. Install ESP8266 Board

    Go to Tools > Board > Boards Manager, search for “esp8266”, and install the ESP8266 package.

  3. Select Board

    Go to Tools > Board and select “LOLIN(WEMOS) D1 R2 & mini”.

  4. Install Stepper Library

    Go to Sketch > Include Library > Manage Libraries, search for “Stepper”, and install the built-in Stepper library.

#include <Stepper.h>
// Define number of steps per revolution
const int stepsPerRevolution = 2048; // 28BYJ-48 has 2048 steps per revolution
// Initialize stepper motor on pins D1, D2, D3, D4
Stepper 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);
}
// Different speeds for different applications
myStepper.setSpeed(5); // Slow for precision
myStepper.step(512); // Quarter turn
myStepper.setSpeed(15); // Faster for quick movements
myStepper.step(1024); // Half turn

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);
void rotateDegrees(float degrees) {
// Calculate steps needed (2048 steps = 360 degrees)
int steps = (degrees / 360.0) * stepsPerRevolution;
myStepper.step(steps);
}
// Example usage
rotateDegrees(90); // Rotate 90 degrees clockwise
rotateDegrees(-45); // Rotate 45 degrees counterclockwise

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();
}
  • Robot arm positioning
  • CNC machine control
  • Automated blinds/curtains
  • Camera pan/tilt mechanisms
  • Precision gauges
  • Antenna rotators
  • Solar panel trackers
  • Laboratory equipment
  • Vending machines
  • ATM machines
  • Printers and scanners
  • DVD players
  • 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
  • Wrong stepper motor type (unipolar vs bipolar)
  • Incorrect coil sequence in code
  • Insufficient power supply current
  • Increase speed setting in setSpeed()
  • Check power supply capacity
  • Reduce load on motor shaft
  • Verify SSID and password
  • Check WiFi signal strength
  • Ensure ESP8266 firmware is up to date
ParameterValue
Step Angle5.625° / 64 (half-step mode)
Steps per Revolution2048 (full step), 4096 (half step)
Rated Voltage5V or 12V DC
Current per Phase~150mA
Holding Torque34.3mN·m (3.3kg·cm)
Operating Temperature-10°C to +40°C
  • 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