Source: https://mokxi.com/libraries/stepper
Updated: 2026-11-02

Libraries / Motion
Arduino library · Motion

# The Arduino Stepper library and the 28BYJ-48

Stepper.h is the small stepper library that comes with the Arduino IDE. It knows how many steps make one turn, a speed in revolutions per minute, and a coil pattern, and step(n) walks the motor n steps through that pattern, blocking until it is done. It has no acceleration and no position counter: it is for moving a motor a set number of steps at a steady speed.

Open the example in the editor See the calls

Built in on Mokxi: #include <Stepper.h> and it builds, with nothing to install. Free, and no account needed.

## What Stepper does

Most people meet it with the 28BYJ-48 geared motor and its ULN2003 driver board from a starter kit. In the library’s full-step mode that motor needs 2048 steps for one turn of the output shaft, and it will not follow much faster than about 15 rpm before it starts missing steps.

The part every kit lesson gets people to type without explaining is the pin order. The library’s four-wire sequence was written for a bipolar motor on an H bridge, so for the ULN2003 inputs IN1 to IN4 the constructor must be given IN1, IN3, IN2, IN4. With pins 8, 9, 10 and 11 in plain order the motor energizes opposite coils and just hums.

Library Manager name | Stepper

Author | Arduino

Include | #include <Stepper.h>

Boards | every board Mokxi compiles for but ATtiny85

In the simulator | Simulated: it runs against the part the way it does on the bench.

Parts it drives | Stepper motor, 28BYJ-48 with ULN2003

## Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <Stepper.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "Stepper" by Arduino from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add Stepper to lib_deps in PlatformIO. Mokxi follows the calls of release 1.1.3, so a sketch written here builds there too.

ESP32-C3 · Arduino Uno · Arduino Nano · Arduino Mega 2560 · Arduino Leonardo · SparkFun Pro Micro · Arduino Micro · ESP32-C6 · Raspberry Pi Pico · Raspberry Pi Pico W · Seeed XIAO SAMD21 · STM32 · STM32 Nucleo-F411RE · STM32 Blue Pill · micro:bit V2 · Arduino Uno R4 · ESP32 DevKit · ESP32-S3-DevKitC-1 · ESP8266 NodeMCU · Arduino Pro Mini 3.3 V · Seeed XIAO ESP32-C3 · ESP32-C3 SuperMini · Seeed XIAO ESP32-C6 · ESP32-DevKitC V4 · LOLIN32 Lite · Wemos D1 R32 · Cheap Yellow Display · TTGO T-Display · Seeed XIAO ESP32-S3 · Arduino Nano ESP32 · Arduino Nano RP2040 Connect · Seeed XIAO RP2040 · Waveshare RP2040-Zero · Arduino Uno R4 WiFi

## The calls you will use

In the order a sketch meets them.

### Stepper myStepper(2048, 8, 10, 9, 11)

Steps per revolution, then the four driver inputs in the order IN1, IN3, IN2, IN4 for a 28BYJ-48 on a ULN2003 board.

### Stepper myStepper(200, 8, 9)

The two-pin form, for a motor behind a driver that takes two control lines.

### myStepper.setSpeed(10)

Sets the speed in rpm. The library turns it into the gap between steps; it changes nothing until the next step().

### myStepper.step(2048)

Makes that many steps, negative for the other direction, and returns only when it has finished. Nothing else in loop() runs meanwhile.

### myStepper.version()

Returns the library version number, handy only for checking which Stepper a sketch was built against.

## Example: ULN2003 board stepping its LEDs

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino · Arduino Uno R3

Open it in the editor, wired and ready to run · ULN2003 board stepping its LEDs: the project page

## Common errors and how to fix them

### The 28BYJ-48 hums or vibrates but does not turn

The pins are in the wrong order for the library’s coil pattern. Pass them as IN1, IN3, IN2, IN4 (for example 8, 10, 9, 11), and keep setSpeed() at 15 rpm or below for this motor.

### The motor turns only half or a quarter of a revolution

The steps-per-revolution number does not match the motor. A 28BYJ-48 in full steps is 2048 for one output turn; a 1.8 degree NEMA 17 is 200. Use the right one in the constructor and in step().

### Buttons and Serial stop responding while the motor moves

step() blocks until every step is made. Move in small chunks of a few steps per pass of loop(), or switch to AccelStepper, whose run() makes one step at a time and returns.

### The motor and ULN2003 board get hot while standing still

The library leaves the last coils switched on so the shaft holds its position. If holding torque is not needed, write the four pins LOW after the move to let the motor go cold.

## Projects that use Stepper

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Stepper follows a knob (pins 2 to 5) A 28BYJ-48 on its ULN2003 board with IN1 to IN4 on pins 2 to 5 follows a potentiometer on A0: turn the knob and the shaft turns to match. Stepper motor on pins 8 to 11 A 28BYJ-48 on its ULN2003 board with IN1 to IN4 on pins 8 to 11: the Stepper library turns the shaft one full turn one way, then back. Knob stepper A rotary encoder on pins 2, 3 and 4 steers a 28BYJ-48 click for click; press the knob and the shaft goes home. Remote stepper An IR receiver on pin 12 and a 28BYJ-48 on its ULN2003 board: VOL+ turns the shaft a quarter turn and VOL- turns it back. Access control: RFID card opens a stepper door An RC522 reader (SS 10, RST 9) checks each card against the one it knows; the right card turns a 28BYJ-48 stepper on pins 2 to 5 a quarter turn to open the door, and an I2C LCD says who may pass.

## Keep going

### Learn

- Arduino Stepper Motor: 28BYJ-48 and ULN2003
- Stepper Motor Vibrating but Not Turning: Fixes
- ULN2003 Simulator: Darlington Driver and COM Pin

### Parts

- Stepper motor, 28BYJ-48 with ULN2003

### More motion libraries

- Servo
- AccelStepper
- L298N
- Adafruit PWM Servo Driver Library
- Adafruit Motor Shield V2 Library

Every built-in library · Open the editor

## Try Stepper without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
