Arduino Uno: Stepper + A4988
Arduino Uno: Stepper + A4988 is a runnable microcontroller simulation example on SensBench — open the wired circuit, inspect the code, and compile real firmware in your browser, no install needed. Last updated Aug 14, 2026.
FREE SIMULATOR EXAMPLE · INTERMEDIATE
Arduino Uno: Stepper + A4988
This example spins a bipolar stepper motor from an Arduino Uno through an A4988 driver: the Uno pulses STEP on pin 3 every 800 µs and holds DIR on pin 4 high, while the driver does the heavy lifting on the coils. One pulse equals one step, so the rotor turns at 625 steps per second — about three revolutions a second on a typical 200-step motor.
| Board | Arduino Uno (ATmega328P, 16 MHz, 5 V logic) |
|---|---|
| Difficulty | intermediate |
| Category | motors |
| Libraries | None — just the Arduino core |
| Runs in | Sensbench browser simulator — free, no account |

The exact circuit you get when you open this example — already wired, ready to run.
The sketch
// Arduino Uno + A4988 stepper driver (STEP/DIR)
// D3 -> STEP, D4 -> DIR. One STEP pulse = one step; DIR sets direction.
const int STEP_PIN = 3, DIR_PIN = 4;
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
digitalWrite(DIR_PIN, HIGH); // HIGH = clockwise
Serial.begin(115200);
Serial.println("A4988 stepper running");
}
void loop() {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(800);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(800);
}
How it works
The division of labor is the whole architecture. The loop is just digitalWrite(STEP_PIN, HIGH), delayMicroseconds(800), LOW, another 800 µs — a clean 625 Hz square wave. The A4988 counts rising edges and sequences current through the motor’s two phases in the right order, with current chopping and flyback protection on board. The MCU never has to think about coils.
Direction is a level, not a command: digitalWrite(DIR_PIN, HIGH) runs once in setup() and stays there, so the same pulse train turns clockwise forever — drive DIR low and the rotor reverses. The timing uses delayMicroseconds() rather than delay() because delay() counts whole milliseconds: at 1 ms granularity you could not reach half this step rate. Serial runs at 115200 baud and prints a single startup banner — after that, the pulse loop owns the CPU.
Before you build it for real
Real A4988 wiring punishes shortcuts. The driver needs two supplies: VMOT at 8–35 V for the motor and 5 V for the logic — plus a 100 µF capacitor across VMOT right at the board, because coil voltage spikes kill these chips without one. The little onboard potentiometer sets the coil current limit and ships wherever the factory left it: too high and the driver thermal-shuts down mid-run (the rotor stutters in a way that looks exactly like a wiring fault), too low and the motor skips steps. Look up the VREF formula and set the limit before blaming your code. Two more rules: never plug or unplug the motor while VMOT is live — that is the classic way to fry the driver — and because this sketch never touches RESET or SLEEP, those two pins must be tied together in your wiring or the chip sleeps through every pulse.
Get the parts
Related examples
FAQ
Can I step faster than 625 steps per second?
The A4988 accepts STEP pulses down to about 1 µs wide, so electrically yes — but a real rotor has inertia. Slam a stopped motor with a fast pulse train and it stalls and buzzes instead of turning. The fix is acceleration: start slow, shrink the delay step by step. The AccelStepper library does that math for you.
Why not drive the coils straight from the Uno?
A stepper phase wants an amp or more; an ATmega328P pin safely sources 20 mA, so direct drive is out before you start. You would also have to sequence the four-step pattern in software and add flyback diodes. The A4988 packs all of that into a cheap module — the Uno’s job shrinks to when and which way.