How to wire a 28BYJ-48 stepper to a Raspberry Pi Pico
To wire a 28BYJ-48 stepper to a Raspberry Pi Pico, connect IN1 to GP10 (physical pin 14), IN2 to GP11 (physical pin 15), IN3 to GP12 (physical pin 16), IN4 to GP13 (physical pin 17), VCC to VBUS (5 V from USB) and GND to GND. The motor runs from the 5 V pin while IN1 to IN4 come from 3.3 V pins, and the ULN2003 driver switches happily from 3.3 V, so no level shifter is needed. The sketch below uses the Stepper (Stepper.h) library. It turns the shaft a quarter turn forward and a quarter turn back.
- 3.3 V logic
- Library: Stepper.h
- 6 wires
28BYJ-48 stepper to Raspberry Pi Pico wiring table
Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.
| 28BYJ-48 stepper pin | Raspberry Pi Pico pin | Wire color | Why |
|---|---|---|---|
| IN1 | GP10 (physical pin 14) | amber | Coil A, through the ULN2003’s first Darlington. |
| IN2 | GP11 (physical pin 15) | green | Coil B. |
| IN3 | GP12 (physical pin 16) | violet | Coil C. |
| IN4 | GP13 (physical pin 17) | cyan | Coil D. |
| VCC (+) | VBUS (5 V from USB) | red | The motor’s 5 V supply: a couple of hundred milliamps, more than USB likes to spare. |
| GND (-) | GND | blue | Common ground. |
Power and logic levels for 28BYJ-48 stepper and Raspberry Pi Pico
Logic level
The Raspberry Pi Pico’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.
Supply
The 28BYJ-48 stepper takes 5 V from VBUS (5 V from USB). That is the Raspberry Pi Pico’s 5 V rail, so the part shares the current the board can supply.
This pair
The motor runs from VBUS (5 V from USB), while IN1 to IN4 come from 3.3 V pins. The ULN2003 switches happily from 3.3 V, so no level shifting is needed. On a real bench, a stepper on USB power can brown out the board when it starts; a separate 5 V supply with the grounds joined is safer.
Pins to leave alone
The numbers in the code are GP numbers, not the physical pin numbers printed beside the header: GP15 is pin 20. GP23 to GP25 are used on the board itself, and GP25 is the LED.
The working code for the Raspberry Pi Pico
Library: Stepper (Stepper.h). This is the sketch the circuit above runs.
#include <Stepper.h>
// The 28BYJ-48 through its ULN2003 board: 2048 full steps a turn.
const int STEPS_PER_TURN = 2048;
// Note the order: IN1, IN3, IN2, IN4. The Stepper library's sequence
// matches the motor's coils that way.
Stepper motor(STEPS_PER_TURN, 10, 12, 11, 13);
void setup() {
Serial.begin(115200);
motor.setSpeed(12); // rpm; the 28BYJ-48 tops out near 15
Serial.println("Stepper ready");
}
void loop() {
Serial.println("Quarter turn forward");
motor.step(STEPS_PER_TURN / 4);
delay(300);
Serial.println("Quarter turn back");
motor.step(-STEPS_PER_TURN / 4);
delay(300);
}
What you should see
The shaft turns a quarter turn forward and then a quarter turn back; the 28BYJ-48 needs 2048 steps for a full turn. The serial monitor, at 115200 baud, prints Stepper ready, then Quarter turn forward and Quarter turn back.
A motor that hums but does not turn has its coil order wrong: with the Stepper library the constructor lists the four pins in the order IN1, IN3, IN2, IN4, and this sketch does the same.
The serial monitor prints this, recorded from the circuit above running for three seconds:
Stepper ready
Quarter turn forward
Quarter turn backCommon mistakes wiring a 28BYJ-48 stepper to a Raspberry Pi Pico
The pin order in the constructor
Stepper(steps, IN1, IN2, IN3, IN4) makes the 28BYJ-48 vibrate without turning. The order has to be IN1, IN3, IN2, IN4, as in the sketch.
Asking for more than 15 rpm
The gearbox makes this motor slow. Above about 15 rpm it skips steps or stalls, and because nothing reports the shaft’s position, the sketch never knows. Keep setSpeed() low.
Assuming the motor knows where it is
A stepper has no sensor: the sketch counts the steps it sent. After a stall or a power cycle that count is wrong, which is why real machines home against a limit switch at start-up.
Build your own 28BYJ-48 stepper project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.