Skip to content
E

Motor

Controlling NEMA17 Motor with ESP32

What is the NEMA17?

The industry-standard stepper motor size for 3D printers, CNC routers, and precision positioning rigs, typically driven via A4988/DRV8825.

Specifications

Step angle1.8° per full step — 200 steps/revolution (microstepping via driver goes much finer, e.g. 3200 steps/rev at 1/16)
Holding torque~40-59 N·cm depending on model — check your specific motor's datasheet, this varies a lot between NEMA17 variants
Rated current~1.2A-1.7A per phase, model-dependent
Winding typeBipolar, 4-wire (two coil pairs — not compatible with unipolar 5/6-wire driver wiring)
Typical driverA4988 or DRV8825, needing a separate 8V-35V motor supply plus 3.3V-5V logic

NEMA17 Pinout

PinNameDescription
1A+Coil A, lead 1 — to driver 1A/1B terminal (order within the pair can be swapped to reverse that coil's direction)
2A-Coil A, lead 2
3B+Coil B, lead 1 — to driver 2A/2B terminal
4B-Coil B, lead 2

Coil pairs must be identified correctly before wiring to a driver — swap A+/A- or B+/B- and the direction of that coil simply reverses (harmless), but crossing a wire between the two different coil pairs (e.g. A+ to B-) will short the driver's H-bridge outputs together. If your specific motor's leads aren't labeled, use a multimeter in continuity mode: the two wires of each coil pair will show low resistance (a few ohms) to each other and effectively infinite resistance to the other pair's wires.

Setting Up NEMA17 with ESP32

Library

AccelStepper by Mike McCauley

Arduino IDE → Tools → Manage Libraries → search "AccelStepper"

Library guide

Wiring

Component pinESP32 pinNote
STEP (on A4988/DRV8825 driver)GPIO25Pulses HIGH-LOW to advance one microstep each time
DIR (on driver)GPIO26Sets rotation direction
ENABLE (on driver)GPIO27Optional -- pull LOW to enable driver outputs; leave floating if unused
VDD (driver logic supply)3.3V
GND (driver logic)GNDCommon ground with the motor power supply is required
VMOT + GND (driver motor supply)External 12-24V supply, not the ESP32NEMA17 coils draw far more current than the ESP32 can source -- never power them from the board itself
A+ / A- / B+ / B- (motor coil leads)Driver's 1A/1B/2A/2B screw terminalsGoes to the driver board, not directly to the ESP32

Example code

C++

Requires an external stepper driver (A4988, DRV8825, or similar) between the ESP32 and the motor -- the NEMA17 draws far more current than a GPIO can supply directly. Power the driver's motor rail from a separate 12-24V supply, not the ESP32.

Related Guides & Projects