skip navigational linksPJRC
Shopping Cart Download Website
Home Products Teensy Blog Forum
You are here: Teensy Teensyduino Libraries AccelStepper

PJRC Store
Teensy 4.1, $28.60
Teensy 4.0, $22.80
Teensy LC, $11.65
Main Page
Getting Started
How-To Tips
Code Library

AccelStepper Library

The AccelStepper library allows you to connect multiple stepper motors with controlled acceleration and deceleration.

Download: Included with the Teensyduino Installer
Latest Developments on this page

Hardware Requirements

AccelStepper is compatible with all Teensy boards. It can output signals to control transistors, or Step & Direction signals to stepper motor driver boards.

AccelStepper on Teensy++ 2.0 with Pololu A4988 Drivers

Basic Usage

You can create multiple AccelStepper objects, giving a unique name to each motor. AccelStepper can manage any number of motors, as long as you repetitively call their "run" functions.

Defining & Configuring Motors

AccelStepper mystepper(1, pinStep, pinDirection);

A stepper motor controlled by a dedicated driver board.

AccelStepper mystepper(2, pinA, pinB);

A bipolar stepper motor controlled by an H-Bridge circuit.

AccelStepper mystepper(4, pinA1, pinA2, pinB1, pinB2);

A unipolar stepper motor, controlled by 4 transistors.


Sets the maximum speed. The default is very slow, so this must be configured. When controlled by setting position, the stepper will accelerate to move at this maximum speed, and decelerate as it reaches the destination.


Sets the acceleration to be used, in steps per second per second.

Position Based Control


Move the motor to a new absolute position. This returns immediately. Actual movement is caused by the run() function.


Move the motor (either positive or negative) relative to its current position. This returns immediately. Actual movement is caused by the run() function.


Read the motor's current absolution position.


Read the distance the motor is from its destination position. This can be used to check if the motor has reached its final position.;

Update the motor. This must be called repetitively to make the motor move.


Update the motor, and wait for it to reach its destination. This function does not return until the motor is stopped, so it is only useful if no other motors are moving.

Speed Based Control


Set the speed, in steps per second. This function returns immediately. Actual motion is caused by called runSpeed().


Update the motor. This must be called repetitively to make the motor move.

Example Program

#include <AccelStepper.h>

//AccelStepper Xaxis(1, 2, 5); // pin 2 = step, pin 5 = direction
//AccelStepper Yaxis(1, 3, 6); // pin 3 = step, pin 6 = direction
//AccelStepper Zaxis(1, 4, 7); // pin 4 = step, pin 7 = direction

AccelStepper Xaxis(1, 3, 6); // pin 3 = step, pin 6 = direction
AccelStepper Yaxis(1, 4, 7); // pin 4 = step, pin 7 = direction
AccelStepper Zaxis(1, 5, 9); // pin 5 = step, pin 8 = direction

void setup() {

void loop() {  

AccelStepper on Teensy 3.0 with Pololu A4988 Drivers

More Details

Please refer to the official AccelStepper library documentation for more details.