Codey OnlineArduino & ESP32 component library › NEMA17 Stepper Motor
NEMA17 Stepper Motor
Actuators

NEMA17 Stepper Motor

A NEMA17 stepper motor converts step pulses into precise angular movement via two electromagnetic coils. It is typically driven by a stepper driver using the motor’s four coil terminals (commonly labeled A+/A− and B+/B−), while the remaining labeled terminals on the connector correspond to the same coil connections in different pin groupings. Use appropriate stepper-driver wiring to energize the A and B coils in sequence.

Width: 53.6 mm

Pinout — NEMA17 Stepper Motor

Pin Signal Description
1A power Stepper coil 1 terminal A — connect to one output of motor driver phase A
1B power Stepper coil 1 terminal B — connect to the other output of motor driver phase A
2A power Stepper coil 2 terminal A — connect to one output of motor driver phase B
2B power Stepper coil 2 terminal B — connect to the other output of motor driver phase B

Example wiring diagram — NEMA17 Stepper Motor

From To Wire
board:5V x2:VDD red
board:GND x2:GND black
board:D2 x2:STEP green
board:D3 x2:DIR blue
board:D4 x2:EN yellow
board:5V x3:CW red
board:GND x3:CCW black
board:A0 x3:WIPER purple
x2:1A x1:1A cyan
x2:1B x1:1B magenta
x2:2A x1:2A brown
x2:2B x1:2B pink

Example Arduino code — NEMA17 Stepper Motor

This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.

// Canonical NEMA17 stepper motor example using an A4988-style driver.
// Wiring:
// Arduino D2 -> STEP
// Arduino D3 -> DIR
// Arduino D4 -> EN (active LOW)
// Arduino 5V -> VDD
// Arduino GND -> GND
// Potentiometer CW -> 5V, CCW -> GND, WIPER -> A0
// Motor coils -> driver outputs 1A/1B and 2A/2B

const int STEP_PIN = 2;
const int DIR_PIN  = 3;
const int EN_PIN   = 4;
const int POT_PIN  = A0;

void stepMotor(long steps, bool direction, unsigned int stepDelayMicros) {
  digitalWrite(DIR_PIN, direction ? HIGH : LOW);

  for (long i = 0; i < steps; i++) {
    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(stepDelayMicros);
    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(stepDelayMicros);
  }
}

void setup() {
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  pinMode(EN_PIN, OUTPUT);

  digitalWrite(STEP_PIN, LOW);
  digitalWrite(DIR_PIN, LOW);
  digitalWrite(EN_PIN, HIGH); // disable driver at start

  Serial.begin(9600);
  while (!Serial) { }

  Serial.println("NEMA17 stepper motor demo with A4988 driver");
  Serial.println("Turn the potentiometer to change speed.");
  Serial.println("The motor alternates direction after each full rotation.");
}

void loop() {
  int pot = analogRead(POT_PIN);
  unsigned int stepDelayMicros = map(pot, 0, 1023, 2000, 300);
  const int stepsPerRevolution = 200; // typical 1.8 degree NEMA17 motor

  digitalWrite(EN_PIN, LOW); // enable driver

  Serial.print("Speed control pot=");
  Serial.print(pot);
  Serial.print("  step delay(us)=");
  Serial.println(stepDelayMicros);

  Serial.println("Rotating clockwise...");
  stepMotor(stepsPerRevolution, true, stepDelayMicros);
  delay(500);

  Serial.println("Rotating counterclockwise...");
  stepMotor(stepsPerRevolution, false, stepDelayMicros);
  delay(500);
}

Related components

A4988 Stepper Driver

A4988 Stepper Driver

DRV8825 Driver Board

DRV8825 Driver Board

L298N Motor Driver Board

L298N Motor Driver Board

Left DC Motor

Left DC Motor

Build your Arduino or ESP32 project with AI

Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.

Start for free