Skip to content
Buy 10+ on select items — save 10% auto-applied
Free US shipping on orders $35+
Order by 3pm ET — ships same-day from the US
Skip to main content

Arduino A4988: Control a NEMA 17 Stepper Motor | ShillehTek

May 14, 2026 18 views

Arduino A4988: Control a NEMA 17 Stepper Motor | ShillehTek
Project

Build an Arduino Nano and A4988 setup to control a NEMA 17 stepper motor with simple STEP/DIR wiring and code, using parts from ShillehTek.

30 min Intermediate (motor power re3 parts

Project Overview

Arduino + A4988 stepper driver: In this build, an Arduino Nano drives an A4988 stepper driver to spin a NEMA 17 stepper motor a controlled number of steps in each direction. The A4988 is a compact, about 2 A-per-coil bipolar stepper driver used in many entry-level 3D printers and CNC machines, and it only needs two control pins (STEP and DIR) while handling microstepping in hardware.

  • Time: ~30 minutes
  • Skill level: Intermediate (motor power requires care)
  • What you will build: An Arduino spinning a NEMA 17 a controlled number of steps in each direction.
Arduino Nano and A4988 stepper driver connected to a NEMA 17 stepper motor for basic motion control
A4988 + NEMA 17 + Arduino, the building block of many 3D printer and CNC axes.

Parts List

From ShillehTek

External

  • NEMA 17 (or similar bipolar 4-wire) stepper motor
  • 12 V power supply ≥ 1 A
  • 100 µF electrolytic capacitor across motor power (essential)

Note: Never connect or disconnect a stepper while the driver is powered. Doing so can blow the A4988 instantly.

Step-by-Step Guide

Step 1 - Identify the Pins

Goal: Understand the A4988 pin groups so you wire power, motor outputs, and control signals correctly.

What to do: Locate the logic side (VDD and GND, plus STEP/DIR/EN and MS1/MS2/MS3) and the motor power side (VMOT and GND) on your A4988 module. Confirm the position of the trim-pot used to set current limiting.

Close-up of an A4988 stepper driver module showing the 16-pin header and current-limit trim potentiometer
Tiny board, 16 pins, one trim-pot for current limiting.
A4988 stepper driver pinout diagram labeling VMOT, GND, VDD, STEP, DIR, EN, and MS1 MS2 MS3 pins
Power on the right, signals on the left. MS1/MS2/MS3 set microstepping.

Expected result: You can point to each required pin (VMOT, GND, VDD, STEP, DIR, EN, 1A/1B/2A/2B) before any wiring begins.

Step 2 - Set the Current Limit

Goal: Protect the motor and driver by setting a safe coil current limit before running the motor.

What to do: Set the current limit using the trim-pot and the formula Vref = Imax × 8 × Rs (Rs = 0.1 Ω on most boards). For a 1 A motor coil, target Vref ≈ 0.8 V measured between the trim-pot wiper and GND. Adjust carefully and re-measure until you are close to your target.

Expected result: Vref is set to match your motor coil current target, reducing the risk of overheating or damage.

Step 3 - Wire It Up

Goal: Connect motor power, logic power, control pins, and the stepper coils correctly.

What to do: Wire the A4988 to the Arduino and the stepper motor using the connections below. Place the 100 µF capacitor across VMOT and GND close to the driver.

Wiring diagram of Arduino connected to an A4988 driver with STEP and DIR signals, plus VMOT power, capacitor, and NEMA 17 coil connections
Two control pins (STEP, DIR), four motor pins, and motor power.
  • VMOT → 12 V supply +
  • GND (motor side) → supply - and Arduino GND
  • VDD → 5 V (logic), GND (logic) → Arduino GND
  • STEP → D3, DIR → D4
  • EN → GND (always enabled) or Arduino pin if you want to disable
  • 1A/1B/2A/2B → the four motor coils (consult motor datasheet)
  • 100 µF cap across VMOT & GND, close to the driver

Expected result: The A4988 has logic power and shared ground with the Arduino, the motor has a stable VMOT supply with a nearby capacitor, and STEP/DIR are connected to the Arduino pins.

Step 4 - Upload the Sketch

Goal: Generate STEP pulses while toggling DIR so the motor turns one revolution forward and one revolution backward.

What to do: Paste the sketch below into the Arduino IDE and upload it to your Arduino Nano.

Code:

const int STEP = 3;
const int DIR  = 4;
const int STEPS_PER_REV = 200;   // 1.8° motor

void setup() {
  pinMode(STEP, OUTPUT);
  pinMode(DIR, OUTPUT);
}

void rotate(int steps, bool forward, int delay_us) {
  digitalWrite(DIR, forward ? HIGH : LOW);
  for (int i = 0; i < steps; i++) {
    digitalWrite(STEP, HIGH);
    delayMicroseconds(delay_us);
    digitalWrite(STEP, LOW);
    delayMicroseconds(delay_us);
  }
}

void loop() {
  rotate(STEPS_PER_REV, true,  800);  // one rev forward
  delay(500);
  rotate(STEPS_PER_REV, false, 800);  // one rev reverse
  delay(500);
}

Expected result: The Arduino outputs step pulses on D3 and sets direction on D4, commanding one forward and one reverse revolution repeatedly.

Step 5 - Watch It Step

Goal: Confirm smooth, repeatable rotation under A4988 control.

What to do: Apply motor power (VMOT) and observe the motor. If you want to change speed, increase delay_us to slow down or decrease it to speed up.

NEMA 17 stepper motor rotating while driven by an A4988 module controlled by an Arduino
Smooth rotation; raise delay_us to slow down, lower to speed up.

Expected result: The motor rotates one revolution forward, pauses, then rotates one revolution backward, repeating continuously.

Step 6 - Where to Take It Next

Goal: Build on the same wiring and code pattern for more advanced motion projects.

What to do: Try any of the following expansions using the same STEP/DIR approach:

  • Add microstepping (set MS1/MS2/MS3 HIGH) for 1/16 step smoothness
  • Drive a leadscrew for a linear actuator
  • Hook up an end-stop and home the axis on boot
  • Move to a TMC2209 (silent, sensorless homing) for printer-grade work

Expected result: You have a clear path to improve smoothness, add axis control features, and upgrade drivers as your project grows.

Conclusion

You built an Arduino Nano and A4988 stepper driver setup that spins a NEMA 17 stepper motor a controlled number of steps in both directions. Once you have one motor moving reliably, you can apply the same foundation to CNC axes, 3D printer motion, and other automation projects.

Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building motion-control firmware for your product, check out our IoT consulting services.