A4988 Stepper Motor Driver with ESP32: Wiring, Code and Microstepping
The A4988 Stepper Motor Driver with ESP32 is one of the cheapest ways to get precise, repeatable motion from a 3.3 V microcontroller. This guide is the hub for everything about the A4988 ESP32 combination: how to wire it, which GPIO pins to use, how to set the current limit, how microstepping works, working ESP32 stepper motor code, and which motor to buy. Each section links to a deeper, dedicated guide.
Quick answer – how to connect an A4988 to an ESP32
- Power the A4988 logic (
VDD) from the ESP32’s 3.3 V pin and join all grounds. - Feed
VMOTwith 8–35 V from a separate motor supply and add a 100 µF capacitor acrossVMOT/GND. - Join
RESETtoSLEEPwith a jumper wire. - Wire
STEPandDIRto two ESP32 GPIOs (this guide uses GPIO 26 and 27). - Set
Vreffor your motor’s current, then connect the two coils to1A/1Band2A/2B. - Upload the AccelStepper sketch below.
Table of Contents
Table of Contents
A4988 Stepper Motor Driver with ESP32: Parts you need
- ESP32 development board (ESP32-WROOM-32 DevKit or similar)
- A4988 stepper driver module (with heatsink)
- Bipolar stepper motor – a NEMA 17 is the usual choice
- Motor power supply, 8–35 V, sized for your motor current
- 100 µF electrolytic capacitor (rated above your supply voltage)
- Breadboard and jumper wires, a small screwdriver and a multimeter
Wiring the A4988 to the ESP32
The A4988 logic pins accept 3.0–5.5 V, so the ESP32’s 3.3 V outputs drive STEP and DIR directly – no level shifter is needed when VDD is powered from 3.3 V. The diagram shows the full connection; the table lists every wire.

| A4988 pin | Connects to | Notes |
|---|---|---|
| VDD | ESP32 3V3 | Logic supply |
| GND (logic side) | ESP32 GND | Common ground is mandatory |
| VMOT | Motor supply + | 8–35 V, 100 µF capacitor across VMOT/GND |
| GND (motor side) | Motor supply − | Internally joined to the other GND |
| STEP | GPIO 26 | One pulse = one (micro)step |
| DIR | GPIO 27 | HIGH/LOW sets direction |
| ENABLE | GPIO 25 | Active LOW – pull LOW to run |
| MS1 / MS2 / MS3 | GPIO 32 / 33 / 13 | Microstep selection |
| RESET + SLEEP | Jumper together | Leaving RESET floating can stop the driver working |
| 1A, 1B | Motor coil 1 | Find pairs with a multimeter |
| 2A, 2B | Motor coil 2 | Swap one coil’s wires to reverse direction |
Do not plug or unplug the motor while VMOT is powered. Disconnecting a motor under power can damage the A4988. Power down, rewire, then power up.
Choosing ESP32 GPIO pins for the A4988
Not every ESP32 pin is a good fit. Some are wired to the flash chip, some are input-only, and the strapping pins change the boot mode if they are pulled the wrong way at reset. The chart below shows safe choices for STEP, DIR, ENABLE and the MS pins. You can compare boards in our ESP32 pinout reference.

Setting the A4988 current limit (Vref)
The small trimmer on the A4988 sets the maximum current per coil. Set it too high and the driver and motor overheat; too low and the motor skips steps. The limit follows Imax = Vref ÷ (8 × Rcs), where Rcs is the sense resistor on your board (commonly 0.068 Ω or 0.1 Ω – read the marking, because clone boards differ).
Example: a 1.5 A motor on a board with 0.068 Ω sense resistors, run at about 1.2 A, needs Vref ≈ 1.2 × 0.544 ≈ 0.65 V.

Microstepping with MS1, MS2 and MS3
The three MS pins divide each full step into smaller ones. More microsteps mean smoother, quieter motion, but you need a proportionally faster STEP pulse rate for the same speed. The pins have internal pull-downs, so leaving them unconnected gives full-step mode. See A4988 microstep: mastering precision and control for torque trade-offs and practical settings.

| MS1 | MS2 | MS3 | Resolution | Steps per rev (1.8° motor) |
|---|---|---|---|---|
| LOW | LOW | LOW | Full step | 200 |
| HIGH | LOW | LOW | 1/2 step | 400 |
| LOW | HIGH | LOW | 1/4 step | 800 |
| HIGH | HIGH | LOW | 1/8 step | 1,600 |
| HIGH | HIGH | HIGH | 1/16 step | 3,200 |
ESP32 stepper motor code (AccelStepper)
This sketch uses the AccelStepper library (install it from the Arduino IDE Library Manager). It sets 1/16 microstepping, enables the driver, and moves the motor one revolution forward and back with smooth acceleration. The pins match the wiring table above. A longer walkthrough with more examples is in A4988 ESP32 code: complete stepper motor control.
#include <AccelStepper.h>
// Pin map (see the wiring table)
const uint8_t STEP_PIN = 26;
const uint8_t DIR_PIN = 27;
const uint8_t EN_PIN = 25; // active LOW
const uint8_t MS1_PIN = 32;
const uint8_t MS2_PIN = 33;
const uint8_t MS3_PIN = 13;
const long STEPS_PER_REV = 200L * 16; // 1.8° motor at 1/16 microstepping
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);
void setup() {
pinMode(EN_PIN, OUTPUT);
pinMode(MS1_PIN, OUTPUT);
pinMode(MS2_PIN, OUTPUT);
pinMode(MS3_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW); // enable the driver
digitalWrite(MS1_PIN, HIGH); // MS1 + MS2 + MS3 HIGH = 1/16 step
digitalWrite(MS2_PIN, HIGH);
digitalWrite(MS3_PIN, HIGH);
stepper.setMaxSpeed(3200); // steps per second (1 rev/s at 1/16)
stepper.setAcceleration(3200); // steps per second squared
stepper.setMinPulseWidth(5); // microseconds
stepper.moveTo(STEPS_PER_REV);
}
void loop() {
// Reverse whenever the target is reached
if (stepper.distanceToGo() == 0) {
stepper.moveTo(stepper.currentPosition() == 0 ? STEPS_PER_REV : 0);
}
stepper.run(); // call as often as possible – avoid delay() here
}Why this sketch is safer than the common “Arduino Uno” example: many tutorials reuse pins 2 and 3, which on an ESP32 are a strapping pin and the UART receive pin. The pins above avoid those problems. Because stepper.run() must be called constantly, keep delay() and slow code out of loop(). For very high step rates, a hardware-timed library such as FastAccelStepper is a better fit than AccelStepper.
Which stepper motor to use with the A4988
NEMA 17
The standard match for the A4988: a bipolar motor with enough torque for 3D printers, CNC and robotics. See NEMA 17 A4988 for wiring, current settings and sketches.
28BYJ-48
A tiny, low-torque geared motor that is normally unipolar and paired with a ULN2003 board. Using it with an A4988 requires converting it to bipolar and a very low Vref – read the 28BYJ-48 stepper motor with A4988 driver guide first.
Whatever motor you choose, check that it is a bipolar motor (four wires), note its rated current, and measure coil pairs with a multimeter before connecting.
Using the A4988 with ESP8266 and STM32
The A4988 only needs a logic-level STEP pulse and a DIR level, so the wiring in this guide transfers to other 3.3 V boards. An ESP8266 stepper motor A4988 setup uses the same connections on its GPIO pins (watch its boot-strapping pins and limited number of free pins). For an A4988 STM32 build, use any output pin for DIR and a timer-driven pin for STEP to get stable step rates. Our ESP32 pinout guide helps when you move a design between boards.
Troubleshooting A4988 and ESP32 problems
| Symptom | Likely cause | Fix |
|---|---|---|
| Motor does nothing | RESET not tied to SLEEP, ENABLE held HIGH, or no VMOT | Add the jumper, drive ENABLE LOW, check supply |
| Motor buzzes or vibrates but doesn’t turn | Coil wires paired wrongly | Identify each coil with a multimeter and re-wire |
| Wrong direction | Coil polarity | Swap one coil’s two wires or invert the DIR logic |
| Skipped steps or stalls | Vref too low, acceleration too high | Raise Vref slightly, lower speed and acceleration |
| Driver gets very hot | Vref too high or no cooling | Lower Vref, add heatsink and airflow |
| ESP32 resets when the motor starts | Power noise or shared supply sag | Add the VMOT capacitor, shorten wires, power the ESP32 separately |
A4988 ESP32 FAQ
Can an ESP32 drive an A4988 directly?
Yes. With VDD at 3.3 V, the ESP32’s 3.3 V outputs meet the A4988’s logic-high threshold, so you can connect STEP and DIR straight to GPIO pins.
Which ESP32 pins should I use for STEP and DIR?
Choose general-purpose output pins such as GPIO 25, 26 or 27, and avoid the flash pins (6–11), UART0 pins (1 and 3), input-only pins (34–39) and strapping pins (0, 2, 5, 12, 15).
Why does my A4988 motor not move?
The most common causes are RESET not joined to SLEEP, ENABLE driven HIGH, a missing motor supply, or mis-paired coil wires. Work through the troubleshooting table above.
Does the A4988 need a heatsink?
For currents above roughly 1 A per coil, yes – and airflow is recommended for anything near the 2 A limit.
A4988 vs DRV8825 vs TMC2209 – which should I choose?
The A4988 is cheap and simple, with up to 1/16 microstepping. The DRV8825 reaches 1/32 microstepping and higher current, while the TMC2209 adds very quiet operation and finer interpolation. For a first ESP32 stepper project, the A4988 is a sensible starting point.
Get new guides in your feed. Follow Electrical Insights on LinkedIn for new electrical standards guides, calculators and design tips from Azad Circuit Hub.

I think this website has some real excellent information for everyone : D.