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

Libraries / Motion
Arduino library · Motion

# AccelStepper: smooth stepper moves that ramp up and down

AccelStepper, by Mike McCauley, is the library people move to once the built-in Stepper library is not enough. It ramps a motor up to speed and back down again, keeps track of the absolute position in steps, and never blocks: you tell it where to go with moveTo() and then call run() over and over, and each call makes at most one step when one is due.

Open the example in the editor See the calls

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

## What AccelStepper does

It drives a STEP and DIR driver such as the A4988, DRV8825 or TMC2209 (AccelStepper::DRIVER), or four pins straight to a ULN2003 board for a 28BYJ-48 (FULL4WIRE or HALF4WIRE, pins in the order IN1, IN3, IN2, IN4). The speeds are in steps per second and the acceleration in steps per second per second.

Because the step timing lives inside run(), loop() has to come back to it far more often than the motor steps. A delay(), a long Serial print or a blocking sensor read in loop() shows up as a motor that stutters. The math is floating point, so an Uno tops out around 4000 steps a second.

Library Manager name | AccelStepper

Author | Mike McCauley

Include | #include <AccelStepper.h>
#include <MultiStepper.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 driver, A4988, 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 <AccelStepper.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "AccelStepper" by Mike McCauley from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add AccelStepper to lib_deps in PlatformIO. Mokxi follows the calls of release 1.64, 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.

### AccelStepper stepper(AccelStepper::DRIVER, 3, 2)

A motor on a STEP/DIR driver: the STEP pin first, then DIR.

### AccelStepper small(AccelStepper::HALF4WIRE, 8, 10, 9, 11)

A 28BYJ-48 on a ULN2003 board in half steps, 4096 to a turn, pins as IN1, IN3, IN2, IN4.

### stepper.setMaxSpeed(1000)

The top speed in steps per second that run() will ramp up to. Set it before the first move.

### stepper.setAcceleration(500)

How fast the speed changes, in steps per second per second. Without it the motor cannot start moving under run().

### stepper.moveTo(2000)

Sets an absolute target position. move(n) does the same relative to where the motor is now.

### stepper.run()

Makes one step if one is due and returns true while the motor still has somewhere to go. Call it on every pass of loop().

### stepper.distanceToGo()

Steps left to the target, negative when the target is behind. Zero means the move is finished.

### stepper.currentPosition()

Where the motor is, in steps from zero. setCurrentPosition(0) makes the present spot the new zero, as after homing.

### stepper.setSpeed(400); stepper.runSpeed()

Constant speed with no ramp and no target, for a motor that just keeps turning.

### stepper.runToPosition()

Blocks until the target is reached. Handy in setup(), but it stops everything else just like Stepper.step().

## Example: Stepper turntable

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 · Stepper turntable: the project page

## Common errors and how to fix them

### The motor does not move at all after moveTo()

Either run() is not being called again and again in loop(), or setMaxSpeed() and setAcceleration() were never set. Both are needed before run() will start a move; the defaults leave the motor standing.

### The stepper stutters or moves much slower than setMaxSpeed()

Something in loop() is keeping run() from being called often enough: a delay(), a slow display update or a lot of Serial output. Do those every few hundred milliseconds with millis(), not every pass.

### runSpeed() turns the motor but run() does not

runSpeed() uses the speed from setSpeed() and ignores the target. run() uses the target from moveTo() or move(); if the motor is already at its target, run() has nothing to do.

### An A4988 motor only moves in one direction

The STEP and DIR pins are swapped in the constructor, or DIR is not wired. AccelStepper::DRIVER takes STEP first and DIR second, so AccelStepper(AccelStepper::DRIVER, stepPin, dirPin).

## Questions and answers

### How do I move two motors so they arrive together?

Use MultiStepper, which comes with AccelStepper: add both motors, give it an array of targets with moveTo(), and call runSpeedToPosition(). It scales the speeds so both finish at the same moment, without acceleration.

## Projects that use AccelStepper

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

Stepper speed control with a TMC2209 and a knob A knob on A0 sets the speed and direction of a NEMA 17 on a quiet TMC2209 with AccelStepper: stop in the middle, up to 120 rpm either way, eased. Satellite tracker A stepper and a servo point a small dish at a satellite on a demo pass, from a simplified circular-orbit model, with an LCD counting down to rise and set.

## Keep going

### Learn

- AccelStepper Arduino Library: Examples and Homing
- Arduino A4988 and NEMA 17 Stepper: Wiring and Code
- Stepper Motor Wiring: 4, 5 and 6 Wire Motors

### Parts

- Stepper driver, A4988
- Stepper motor, 28BYJ-48 with ULN2003

### More motion libraries

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

Every built-in library · Open the editor

## Try AccelStepper without installing anything

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

Start building free

Open the editor
