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 angle | 1.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 type | Bipolar, 4-wire (two coil pairs — not compatible with unipolar 5/6-wire driver wiring) |
| Typical driver | A4988 or DRV8825, needing a separate 8V-35V motor supply plus 3.3V-5V logic |
NEMA17 Pinout
| Pin | Name | Description |
|---|---|---|
| 1 | A+ | Coil A, lead 1 — to driver 1A/1B terminal (order within the pair can be swapped to reverse that coil's direction) |
| 2 | A- | Coil A, lead 2 |
| 3 | B+ | Coil B, lead 1 — to driver 2A/2B terminal |
| 4 | B- | 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"
Wiring
| Component pin | ESP32 pin | Note |
|---|---|---|
| STEP (on A4988/DRV8825 driver) | GPIO25 | Pulses HIGH-LOW to advance one microstep each time |
| DIR (on driver) | GPIO26 | Sets rotation direction |
| ENABLE (on driver) | GPIO27 | Optional -- pull LOW to enable driver outputs; leave floating if unused |
| VDD (driver logic supply) | 3.3V | — |
| GND (driver logic) | GND | Common ground with the motor power supply is required |
| VMOT + GND (driver motor supply) | External 12-24V supply, not the ESP32 | NEMA17 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 terminals | Goes to the driver board, not directly to the ESP32 |
Example code
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

ESP32-CAM Web Server: Stream Live Video in 5 Minutes
A complete, no-guesswork walkthrough for flashing an AI-Thinker ESP32-CAM as a live MJPEG video stream -- wiring, Arduino IDE setup, the CameraWebServer sketch, and every failure mode that actually causes problems.

ESP32 MQTT Tutorial: Publish and Subscribe with Arduino IDE
A complete, broker-agnostic ESP32 MQTT tutorial -- topics, QoS, retained messages, Last Will and Testament, TLS security for production, and a working publish/subscribe example with PubSubClient.

Installing ESP8266 in Arduino IDE: NodeMCU (ESP-12E) Complete Setup Guide for Windows
From driver headaches to a blinking LED — the full Windows walkthrough for getting NodeMCU ESP8266 boards running in Arduino IDE, plus notes for Mac and the bare ESP-01 module.

ESP32 Pinout Guide: Every GPIO, ADC, PWM, and Restricted Pin Explained
Complete ESP32 pinout guide covering all GPIOs, input-only pins, strapping pins, flash-reserved pins, dual ADC channels, PWM via LEDC, I2C, SPI, UART, and deep sleep wake pins.