Wiring guide

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
Raspberry Pi Pico · 28BYJ-48 stepperlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

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 pinRaspberry Pi Pico pinWire colorWhy
IN1GP10 (physical pin 14)amberCoil A, through the ULN2003’s first Darlington.
IN2GP11 (physical pin 15)greenCoil B.
IN3GP12 (physical pin 16)violetCoil C.
IN4GP13 (physical pin 17)cyanCoil D.
VCC (+)VBUS (5 V from USB)redThe motor’s 5 V supply: a couple of hundred milliamps, more than USB likes to spare.
GND (-)GNDblueCommon ground.
Voltage

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 sketch

The working code for the Raspberry Pi Pico

Library: Stepper (Stepper.h). This is the sketch the circuit above runs.

28BYJ-48 stepper on Raspberry Pi Pico
#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);
}
Output

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 back
Pitfalls

Common 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.