ESP32: Stepper + A4988
ESP32: 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
ESP32: Stepper + A4988
This example spins a bipolar stepper motor through an A4988 driver using nothing but two GPIOs: GPIO26 pulses STEP, GPIO27 holds DIR high. The loop bit-bangs one pulse every 1.6 ms — about 625 steps per second — with no stepper library involved. Open it and the motor turns; the Serial Monitor just confirms it is running.
| Board | ESP32 DevKit (Xtensa LX6, 240 MHz) |
|---|---|
| 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
// ESP32 + A4988 stepper driver (STEP/DIR)
// GPIO26 -> STEP, GPIO27 -> DIR.
const int STEP_PIN = 26, DIR_PIN = 27;
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
digitalWrite(DIR_PIN, HIGH);
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 A4988 does the hard work. You present a direction level on DIR and one pulse per step on STEP, and the driver’s internal translator sequences the two motor coils with chopper current control. The ESP32’s entire job is being a pulse generator — which is exactly what makes STEP/DIR drivers friendly to any MCU.
The pulse generator is four lines: STEP HIGH, delayMicroseconds(800), STEP LOW, delayMicroseconds(800). A 1.6 ms period is 625 pulses per second; on a common 1.8° motor in full-step mode that is roughly 3.1 revolutions per second. delayMicroseconds() is used because delay() cannot time sub-millisecond edges.
DIR is written HIGH once in setup() and never touched again, so the motor turns one way forever. Serial at 115200 baud only prints “A4988 stepper running” — the real output of this sketch is motion, not text.
Before you build it for real
The simulator’s driver wakes up ready to run; a real A4988 does not. RESET and SLEEP must be tied together (or pulled high) — left floating, the driver sleeps forever with no motion, no heat and no error message. Second, set the current limit with the onboard pot before wiring a motor, and put a 100 µF capacitor across VMOT near the board; the factory pot position is random and inductive spikes kill these drivers. Third, this sketch jumps straight to 625 steps per second with no ramp — a real motor under load will stall and buzz. Use AccelStepper or FastAccelStepper once you move past the demo.
Get the parts
Related examples
FAQ
How fast is the motor actually turning?
The pulse period is 800 µs high plus 800 µs low — 1.6 ms, or about 625 steps per second. With a typical 1.8°-per-step motor in full-step mode (200 steps per revolution) that is roughly 3.1 revolutions per second, about 188 RPM. Halve both delays to double it, until the motor’s torque gives out.
Why no AccelStepper library?
To show you exactly what the driver needs: one clean pulse per step. For real projects use AccelStepper or FastAccelStepper — they add acceleration ramping and non-blocking motion, both of which this delayMicroseconds() loop cannot do.