AccelStepper
by Mike McCauley
AccelStepper controls stepper motors (via driver boards like A4988/DRV8825, or direct 4-wire drive) with smooth acceleration and deceleration ramps, unlike the basic Arduino `Stepper` library which only supports constant speed. It runs as a non-blocking state machine — you call `run()` on every loop iteration and it steps the motor exactly as much as the current speed/acceleration profile calls for at that instant, without ever calling `delay()`. The catch that trips people up is that `run()` must be called as often as possible (every loop iteration, with nothing blocking in between) — anything that pauses execution, like a `delay()` elsewhere in your sketch, causes missed steps and lost position tracking, since the library relies on being polled continuously to hit its step timing.
Installation
Arduino IDE — Library Manager
Sketch → Include Library → Manage Libraries → search AccelStepper
PlatformIO
lib_deps = waspinator/AccelStepperSupported boards
Examples
Move to a target position with acceleration
Non-blocking pattern — run() must be called every loop iteration with nothing else blocking.
#include <AccelStepper.h>
AccelStepper stepper(AccelStepper::DRIVER, 3, 4); // step, dir pins
void setup() {
stepper.setMaxSpeed(1000);
stepper.setAcceleration(500);
stepper.moveTo(2000);
}
void loop() {
stepper.run();
}