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
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | A4988 stepper driver | Each 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−. |
| 1 | Stepper Motor | A bipolar stepper, 200 steps a turn. Drive coil A (A+/A−) and coil B (B+/B−) in sequence, usually from an A4988. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno pin 3 | A4988 stepper driver STEP |
| 2 | Arduino Uno pin 4 | A4988 stepper driver DIR |
| 3 | Arduino Uno GND | A4988 stepper driver ENABLE |
| 4 | A4988 stepper driver RESET | A4988 stepper driver SLEEP |
| 5 | Arduino Uno 5V | A4988 stepper driver SLEEP |
| 6 | Arduino Uno 5V | A4988 stepper driver VDD |
| 7 | Arduino Uno GND | A4988 stepper driver GND |
| 8 | A4988 stepper driver 1A | Stepper Motor A+ |
| 9 | A4988 stepper driver 1B | Stepper Motor A- |
| 10 | A4988 stepper driver 2A | Stepper Motor B+ |
| 11 | A4988 stepper driver 2B | Stepper Motor B- |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add an A4988 stepper driver and a stepper motor from the parts palette.
- Wire 1. Connect Arduino Uno pin 3 to A4988 stepper driver STEP.
- Wire 2. Connect Arduino Uno pin 4 to A4988 stepper driver DIR.
- Wire 3. Connect Arduino Uno GND to A4988 stepper driver ENABLE.
- Wire 4. Connect A4988 stepper driver RESET to A4988 stepper driver SLEEP.
- Wire 5. Connect Arduino Uno 5V to A4988 stepper driver SLEEP.
- Wire 6. Connect Arduino Uno 5V to A4988 stepper driver VDD.
- Wire 7. Connect Arduino Uno GND to A4988 stepper driver GND.
- Wire 8. Connect A4988 stepper driver 1A to Stepper Motor A+.
- Wire 9. Connect A4988 stepper driver 1B to Stepper Motor A-.
- Wire 10. Connect A4988 stepper driver 2A to Stepper Motor B+.
- Wire 11. Connect A4988 stepper driver 2B to Stepper Motor B-.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- 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
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator