Arduino AccelStepper with A4988: Wiring, Code and Simulator

To build this Arduino AccelStepper with A4988 project you need an Arduino Uno and an A4988 stepper driver and a stepper motor. AccelStepper ramps a stepper up and down through an A4988 driver. Make the 11 connections in the wiring table, upload the Arduino C++ code, and raise setAcceleration() and watch the move get quicker.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1A4988 stepper driverEach rising edge on STEP moves one full step; DIR picks the way. ENABLE LOW, SLEEP and RESET HIGH, VDD 5V. Wire 1A/1B to A+/A−, 2A/2B to B+/B−.
1Stepper MotorA bipolar stepper, 200 steps a turn. Drive coil A (A+/A−) and coil B (B+/B−) in sequence, usually from an A4988.

Wiring

#FromTo
1Arduino Uno pin 3A4988 stepper driver STEP
2Arduino Uno pin 4A4988 stepper driver DIR
3Arduino Uno GNDA4988 stepper driver ENABLE
4A4988 stepper driver RESETA4988 stepper driver SLEEP
5Arduino Uno 5VA4988 stepper driver SLEEP
6Arduino Uno 5VA4988 stepper driver VDD
7Arduino Uno GNDA4988 stepper driver GND
8A4988 stepper driver 1AStepper Motor A+
9A4988 stepper driver 1BStepper Motor A-
10A4988 stepper driver 2AStepper Motor B+
11A4988 stepper driver 2BStepper Motor B-

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an A4988 stepper driver and a stepper motor from the parts palette.
  3. Wire 1. Connect Arduino Uno pin 3 to A4988 stepper driver STEP.
  4. Wire 2. Connect Arduino Uno pin 4 to A4988 stepper driver DIR.
  5. Wire 3. Connect Arduino Uno GND to A4988 stepper driver ENABLE.
  6. Wire 4. Connect A4988 stepper driver RESET to A4988 stepper driver SLEEP.
  7. Wire 5. Connect Arduino Uno 5V to A4988 stepper driver SLEEP.
  8. Wire 6. Connect Arduino Uno 5V to A4988 stepper driver VDD.
  9. Wire 7. Connect Arduino Uno GND to A4988 stepper driver GND.
  10. Wire 8. Connect A4988 stepper driver 1A to Stepper Motor A+.
  11. Wire 9. Connect A4988 stepper driver 1B to Stepper Motor A-.
  12. Wire 10. Connect A4988 stepper driver 2A to Stepper Motor B+.
  13. Wire 11. Connect A4988 stepper driver 2B to Stepper Motor B-.
  14. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  15. Run it. Press Run. Raise setAcceleration() and watch the move get quicker.

Arduino C++ code

// AccelStepper: accelerate a stepper through an A4988 (STEP 3, DIR 4) to 100 steps.
#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 3, 4);

void setup() {
  Serial.begin(9600);
  stepper.setMaxSpeed(800);
  stepper.setAcceleration(1600);
  stepper.moveTo(100);
}

void loop() {
  stepper.run();
  static bool told = false;
  if (!told && stepper.distanceToGo() == 0) {
    told = true;
    Serial.print("Arrived at ");
    Serial.println(stepper.currentPosition());
  }
}

What to try

Raise setAcceleration() and watch the move get quicker.

Frequently asked questions

How do I wire the AccelStepper with A4988 project on an Arduino Uno?

Make 11 connections: Arduino Uno pin 3 to A4988 stepper driver STEP; Arduino Uno pin 4 to A4988 stepper driver DIR; Arduino Uno GND to A4988 stepper driver ENABLE; A4988 stepper driver RESET to A4988 stepper driver SLEEP; Arduino Uno 5V to A4988 stepper driver SLEEP; Arduino Uno 5V to A4988 stepper driver VDD; Arduino Uno GND to A4988 stepper driver GND; A4988 stepper driver 1A to Stepper Motor A+; A4988 stepper driver 1B to Stepper Motor A-; A4988 stepper driver 2A to Stepper Motor B+; A4988 stepper driver 2B to Stepper Motor B-.

What parts do I need for this Arduino project?

An Arduino Uno and an A4988 stepper driver and a stepper motor.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

AccelStepper ramps a stepper up and down through an A4988 driver.

More Arduino Uno projects