How to wire a 28BYJ-48 stepper to an Arduino Nano
To wire a 28BYJ-48 stepper to an Arduino Nano, connect IN1 to pin 8, IN2 to pin 9, IN3 to pin 10, IN4 to pin 11, VCC to 5V and GND to GND. The ULN2003 board carries the coil current, so the Arduino Nano’s pins only drive its four inputs. The sketch below uses the Stepper (Stepper.h) library. It turns the shaft a quarter turn forward and a quarter turn back.
- 5 V logic
- Library: Stepper.h
- 6 wires
28BYJ-48 stepper to Arduino Nano 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 | Arduino Nano pin | Wire color | Why |
|---|---|---|---|
| IN1 | pin 8 | amber | Coil A, through the ULN2003’s first Darlington. |
| IN2 | pin 9 | green | Coil B. |
| IN3 | pin 10 | violet | Coil C. |
| IN4 | pin 11 | cyan | Coil D. |
| VCC (+) | 5V | 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 Arduino Nano
Logic level
The Arduino Nano’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.
Supply
The 28BYJ-48 stepper takes 5 V from 5V. That is the Arduino Nano’s 5 V rail, so the part shares the current the board can supply.
This pair
The ULN2003 board carries the coil current, so the Arduino Nano’s pins only drive its inputs. The motor’s 5 V comes from the 5V pin here; on a real bench a separate 5 V supply with the grounds joined keeps the board from resetting.
Pins to leave alone
A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.
The working code for the Arduino Nano
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, 8, 10, 9, 11);
void setup() {
Serial.begin(9600);
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 9600 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 an Arduino Nano
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.