What is the NEMA17?
A NEMA 17 is a stepper motor with a 42.3 mm (1.7 inch) square faceplate. It turns in exact steps, usually 1.8° per step (200 steps per revolution), with no encoder needed, which is why it sits in almost every desktop 3D printer, small CNC router, plotter and pick-and-place machine. Most are bipolar: two coils, four wires. The name describes the frame, not the performance: two NEMA 17 motors can differ widely in torque, current and length, so the numbers on your motor's label matter more than the name.
You cannot connect one directly to an Arduino or ESP32. Each coil needs roughly 1 to 2 A, a GPIO gives tens of milliamps, so the motor needs a stepper driver (A4988, DRV8825 or TMC2209) and its own 12 to 24 V supply. The driver turns two cheap signals, STEP and DIR, into the right current in the coils. This guide covers the specifications, how to pick the body length, how to wire and identify the coils, how to set the driver current (Vref) without burning anything, microstepping, why torque falls with speed, and the faults you will meet. When you are ready to build, the Arduino Uno guide and the ESP32 guide take you from wiring to homing and speed control.
Specifications
| Parameter | Typical value |
|---|---|
| Frame size | 42.3 mm (1.7 in) square |
| Step angle | 1.8° (200 steps per revolution) |
| Winding | 4-wire bipolar, two coils |
| Rated current | 1 to 2 A per coil (set by the model) |
| Mounting holes | 4 × M3, 31 mm apart |
| Centring boss | 22 mm diameter |
| Shaft | 5 mm diameter, often with a flat (D-shaft) |
| Holding torque | About 40 to 85 N·cm, depends on body length |
| Body length | About 34 to 63 mm (see the table below) |
| Step accuracy | ±5 % of a full step (±0.09°) per the PBC datasheet |
| Supply (via driver) | 12 to 24 V typical; up to 36 V with a suitable driver |
| Case temperature | Datasheets allow up to about 80 °C rise at rated current |
Wires and coil pairs
| Wire | Name | Description |
|---|---|---|
| 1 | A+ | Coil A, one end. Pair it with A− using the datasheet or a multimeter |
| 2 | A− | Coil A, other end |
| 3 | B+ | Coil B, one end |
| 4 | B− | Coil B, other end |
Wiring & code
Setting up NEMA17 with Arduino Uno
Library
AccelStepper by Mike McCauley
Arduino IDE > Tools > Manage Libraries > search "AccelStepper" > install "AccelStepper" by Mike McCauley
This guide drives a NEMA 17 from an Arduino Uno through an A4988 (or DRV8825) driver, using the AccelStepper library for smooth acceleration. Three sketches build up from a back-and-forth move to potentiometer speed control and a homing routine with a limit switch that moves in millimetres. For the motor itself, torque, microstepping and the Vref formula, read the NEMA 17 overview first.
What you need
1Arduino Uno R3 (or Nano)
- Notes
- 5 V logic
1NEMA 17 stepper motor
- Notes
- Rated about 1 to 2 A per coil; note the rated current from its label
1A4988 or DRV8825 driver module
- Notes
- Check the sense-resistor marking for the Vref formula
112 to 24 V DC power supply
- Notes
- 2 A or more; not from the Uno
1100 µF electrolytic capacitor
- Notes
- Rated above the supply voltage, across VMOT and GND at the driver
110 kΩ potentiometer
- Notes
- Sketch 2
1Limit switch (microswitch)
- Notes
- Sketch 3
1Breadboard and jumper wires
Wiring (A4988)
| A4988 pin | Uno pin | Notes |
|---|---|---|
| STEP | D2 | One pulse = one (micro)step |
| DIR | D3 | Sets the direction |
| ENABLE | D4 | Active LOW; optional (leave unconnected to keep the driver always on) |
| VDD | 5V | Logic supply (A4988 only; the DRV8825 has no VDD pin) |
| GND (logic) | GND | Common ground with the supply and the motor ground |
| RESET and SLEEP | Join them together | Tie RESET to SLEEP with a jumper wire, or the driver will not run |
| MS1, MS2, MS3 | 5V (all three) | Selects 1/16 microstepping. Leave all low for full steps |
| VMOT and GND (motor) | 12 to 24 V supply | Add the 100 µF capacitor across these pins. Never from the Uno |
| 1A, 1B, 2A, 2B | Motor coil leads | Coil 1 on 1A/1B, coil 2 on 2A/2B. Identify the pairs first |
| Potentiometer (Sketch 2) | A0 | Outer legs to 5V and GND, centre to A0 |
| Limit switch (Sketch 3) | D9 | One side to D9, the other to GND (uses INPUT_PULLUP) |
Warning
Set the driver current (Vref) before connecting the motor, using the formula in the overview: Vref = I × 8 × Rs for an A4988, I × 5 × Rs for a DRV8825, at about 70 to 80 % of the motor's rated current. Switch everything off before connecting or disconnecting the motor, and never power the motor from the Uno's 5V pin.
- 1Identify the two coil pairs with a multimeter and mark them.
- 2Wire the driver as in the table. Leave the motor disconnected.
- 3Power the 12 to 24 V supply (not the motor yet), and adjust the trimmer until Vref matches your calculated value.
- 4Power off, then connect the motor coils (coil 1 to 1A/1B, coil 2 to 2A/2B).
- 5In the Arduino IDE open Tools > Manage Libraries, search for AccelStepper by Mike McCauley and install it.
- 6Select the Uno and its port, upload Sketch 1, then power the motor supply. The shaft should turn one revolution, pause, and come back.
Sketch 1 - Back and forth, one revolution each way
With all three MS pins high (1/16 microstepping) the driver needs 3,200 steps per revolution. The sketch sets the speed so that one revolution takes about a second, and accelerates smoothly in and out.
#include <AccelStepper.h>
const int STEP_PIN = 2;
const int DIR_PIN = 3;
const int ENABLE_PIN = 4;
const int MICROSTEPS = 16; // MS1-MS3 high on an A4988
const long STEPS_PER_REV = 200L * MICROSTEPS; // 3200
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);
void setup() {
pinMode(ENABLE_PIN, OUTPUT);
digitalWrite(ENABLE_PIN, LOW); // LOW enables the driver outputs
stepper.setMaxSpeed(STEPS_PER_REV); // steps per second: 1 revolution per second
stepper.setAcceleration(STEPS_PER_REV); // steps per second per second
stepper.moveTo(STEPS_PER_REV); // one revolution forward
}
void loop() {
if (stepper.distanceToGo() == 0) {
delay(500);
stepper.moveTo(-stepper.currentPosition()); // reverse each time it arrives
}
stepper.run(); // must be called as often as possible
}Sketch 2 - Potentiometer speed and direction
The potentiometer sets both speed and direction: centre is stopped, either side speeds up in that direction. The pot is read every 20 ms rather than on every loop, because analogRead is slow and would otherwise limit the step rate.
#include <AccelStepper.h>
const int STEP_PIN = 2;
const int DIR_PIN = 3;
const int ENABLE_PIN = 4;
const int POT_PIN = A0;
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);
unsigned long lastRead = 0;
void setup() {
pinMode(ENABLE_PIN, OUTPUT);
digitalWrite(ENABLE_PIN, LOW);
stepper.setMaxSpeed(3000); // steps per second (about 56 RPM at 1/16)
}
void loop() {
if (millis() - lastRead >= 20) {
lastRead = millis();
long speed = map(analogRead(POT_PIN), 0, 1023, -3000, 3000);
if (abs(speed) < 150) speed = 0; // dead zone around the centre
stepper.setSpeed(speed);
}
stepper.runSpeed(); // constant speed, no acceleration
}Why such a modest top speed? At 1/16 microstepping, 3,000 steps per second is only about 56 RPM. The plain AccelStepper library on a 16 MHz Uno tops out around 4,000 steps per second. For faster moves, use 1/4 or 1/8 microstepping, which needs fewer pulses per revolution.
Sketch 3 - Home to a limit switch, then move in millimetres
A stepper does not know where it is, so axes home at start-up: drive towards a switch until it clicks, then call that position zero. This sketch homes, backs off 2 mm, and then moves between 0 and 50 mm. It assumes a T8 lead screw (8 mm per revolution), which gives 200 × 16 ÷ 8 = 400 steps per millimetre at 1/16 microstepping. Change SCREW_LEAD_MM to match your screw or belt.
#include <AccelStepper.h>
const int STEP_PIN = 2;
const int DIR_PIN = 3;
const int ENABLE_PIN = 4;
const int HOME_PIN = 9; // switch to GND, pressed = LOW
const float SCREW_LEAD_MM = 8.0; // mm per revolution (T8 lead screw)
const int MICROSTEPS = 16;
const float STEPS_PER_MM = 200.0 * MICROSTEPS / SCREW_LEAD_MM; // 400
AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN);
void moveToMm(float mm) {
stepper.runToNewPosition((long)(mm * STEPS_PER_MM)); // blocks until it arrives
}
void homeAxis() {
stepper.setMaxSpeed(1500);
stepper.setSpeed(-800); // towards the switch
while (digitalRead(HOME_PIN) == HIGH) {
stepper.runSpeed();
}
stepper.setCurrentPosition(0); // touching the switch = zero for now
stepper.setAcceleration(1000);
moveToMm(2.0); // back off 2 mm
stepper.setCurrentPosition(0); // this is the true zero
}
void setup() {
pinMode(HOME_PIN, INPUT_PULLUP);
pinMode(ENABLE_PIN, OUTPUT);
digitalWrite(ENABLE_PIN, LOW);
Serial.begin(9600);
homeAxis();
stepper.setMaxSpeed(2000);
stepper.setAcceleration(1500);
Serial.println("Homed");
}
void loop() {
moveToMm(50.0);
Serial.println("At 50 mm");
delay(1000);
moveToMm(0.0);
Serial.println("At 0 mm");
delay(1000);
}Tip
Test the home direction with the carriage a few centimetres from the switch. If it drives away from the switch, flip the sign of the homing speed (or swap one coil's wires). If the switch is wired normally-closed, change the test to LOW and add a debounce, which is safer because a broken wire then stops the move.
Uno notes
- Pins. D2, D3 and D4 are plain digital pins. If you add a second axis, use D5 and D6 for its STEP and DIR. See the Arduino Uno pinout guide.
- Don't block the loop. AccelStepper's
run()must be called very often. Longdelay()calls between moves are fine in a demo, but a real project should usemillis(). - Idle heat. The driver holds the coils at full current even when still. Set ENABLE high (or call
stepper.disableOutputs()) when the axis does not need holding. - Three or more axes are better handled by GRBL with a CNC shield than by hand-written AccelStepper code.
Uno-specific problems
Nothing moves, no hold torque
- Likely cause
- RESET and SLEEP not joined, no motor supply, or ENABLE high
- Fix
- Jumper RESET to SLEEP; check VMOT; drive ENABLE low
Motor buzzes but does not turn
- Likely cause
- Coil wires crossed, speed too high at start, or Vref too low
- Fix
- Re-check pairs; lower the speed or acceleration; raise Vref slightly
Revolution is not 360°
- Likely cause
- Microstep pins do not match the code
- Fix
- Match MS1 to MS3 with the MICROSTEPS constant
Axis loses position over time
- Likely cause
- Skipped steps (speed, load or Vref too high or low)
- Fix
- Lower the top speed and acceleration, use 24 V, recheck Vref
Top speed stops at about 4,000 steps/s
- Likely cause
- Uno and AccelStepper limit
- Fix
- Use a lower microstep setting or a faster controller
Driver hot, shuts down
- Likely cause
- Vref too high or no heatsink
- Fix
- Lower Vref, add a heatsink and a fan
Uno resets when the motor starts
- Likely cause
- Supply sag or noise
- Fix
- Use a separate supply, add the capacitor, keep grounds joined
Homing runs away from the switch
- Likely cause
- Direction reversed
- Fix
- Flip the sign of the homing speed
Arduino Uno FAQ
Can the Uno power the motor? No. Power the driver's VMOT from a 12 to 24 V supply; the Uno only supplies logic.
Can I use a DRV8825 instead? Yes. The STEP and DIR wiring is the same. The DRV8825 has no VDD pin, uses I × 5 × Rs for Vref, and sets 1/16 microstepping with M0 low, M1 low and M2 high.
How do I make it quieter? Use 1/16 microstepping or a TMC2209 driver.
Does it work with an Arduino Nano? Yes. The wiring and sketches are identical.
How do I control more than one motor? Create one AccelStepper object per motor and call run() on each in the loop. Past two axes, switch to a CNC shield and GRBL.
Next: the NEMA 17 overview covers torque, the Vref formula and choosing a driver. For Wi-Fi control and faster moves see the ESP32 guide.








