Sub topic 7
Wiring the motor and powering the driver
This chapter assumes you can write a basic Arduino sketch (setup, loop, digitalWrite, delayMicroseconds) and apply Ohm's law. It also assumes you can read a wiring diagram and use a breadboard with an external supply. The examples use a bipolar stepper motor and an A4988- or DRV8825-style STEP/DIR driver module, the common breakout boards for these chips. Check your own board's datasheet or silkscreen before applying power.
The three connections
A stepper setup has three separate electrical paths:
- Motor supply (VMOT and GND). This feeds the motor coils through the driver's power stage. It carries the large currents.
- Logic supply (VDD and GND). This powers the driver's control circuitry, normally from the Arduino's 5 V or 3.3 V pin.
- Control signals (STEP, DIR, and optionally ENABLE). These come from Arduino pins.
The Arduino cannot power the motor. A NEMA 17 motor can draw 1 A or more per coil, while an Arduino pin supplies about 20 mA. The motor needs its own supply, and the grounds of the two supplies must be joined.
Identifying the coil pairs
A bipolar motor has two coils and usually four wires. Each coil is a pair of wires. If you connect one wire from coil A and one from coil B to the same driver output, the motor will vibrate or hum without turning properly.
To find the pairs with a multimeter:
- Set the meter to resistance (ohms) or continuity.
- Touch two wires together on the probes. If you read a low resistance, typically 1 to 10 ohms, those two wires are one coil.
- If the meter shows an open circuit, those wires belong to different coils.
- Mark each pair and repeat to confirm the other two wires form the second pair.
If you have no meter, use the shorted-wire test. Spin the shaft by hand with the wires loose. Then twist the two ends of one suspected pair together and spin again. The shaft feels noticeably stiffer when you have shorted a real coil, because the shorted coil resists the induced current.
Wire colors vary by manufacturer. Many NEMA 17 motors use black and green for one coil and red and blue for the other, but you must confirm this against your datasheet or by measuring.
Motors with five, six, or eight wires are unipolar or configurable types. For a bipolar driver, leave any center-tap wires unconnected and use only the two ends of each coil. The chapter on motor types covers these variants.
Connecting the motor to the driver
The A4988 and DRV8825 modules share a pin layout. Motor outputs are labeled 1A, 1B, 2A, and 2B.
| Connection | Driver pin | Notes |
|---|---|---|
| Coil A, wire 1 | 1A | Swapping both wires of a coil reverses direction |
| Coil A, wire 2 | 1B | Must be the same coil as 1A |
| Coil B, wire 1 | 2A | |
| Coil B, wire 2 | 2B | Must be the same coil as 2A |
| Motor supply positive | VMOT | A4988 accepts 8 to 35 V. DRV8825 accepts 8.2 to 45 V |
| Motor supply negative | GND (next to VMOT) | |
| Arduino 5 V | VDD | Logic supply |
| Arduino GND | GND (next to VDD) | Shares ground with the motor supply |
| Arduino pin 3 | STEP | |
| Arduino pin 4 | DIR | |
| Arduino pin 8 | ENABLE | Optional. Active low, so LOW enables the outputs |
Two more pins need attention. First, RESET and SLEEP: on many modules RESET floats, and the driver stays disabled until you connect RESET to SLEEP, or tie both high. Second, MS1, MS2, and MS3 select the step mode. Leaving them unconnected or tied to GND gives full-step mode, which matches the sketches in this tutorial. Some modules have internal pull-downs on these pins, but tying them explicitly avoids surprises.
Choosing the motor supply
These drivers use current chopping. They switch the coil voltage on and off to hold the current at your set limit, so the supply voltage can be well above the motor's rated voltage. A motor rated 2.8 V at 1.7 A is normally run from 12 or 24 V. Higher voltage lets the current rise faster against the coil's inductance, which helps at high speed.
Choose the supply with these guidelines:
- Voltage within the driver's range, with margin. A 12 V supply is a common starting point. 24 V gives better high-speed torque.
- Current at least the motor's rated current per phase. Because the driver converts high voltage and low current into low voltage and high current, the supply draw is often lower than the coil current, but a supply rated 1.5 to 2 A suits a single NEMA 17.
- Type a regulated DC supply, not a battery pack that sags under load or a raw unregulated adapter whose voltage may be much higher than printed.
Protecting the driver
Bulk capacitor
Place an electrolytic capacitor of at least 47 µF, usually 100 µF, across VMOT and GND, as close to the driver as possible. Its voltage rating must exceed your supply voltage with margin, so use 35 V or higher for a 24 V supply. Observe polarity: the stripe marks the negative lead.
The capacitor absorbs voltage spikes that appear when the coil current switches. Long supply wires have inductance, and when you connect the supply to a driver already powered, the inrush can ring above the supply voltage. Without the capacitor, that spike can exceed the driver's maximum rating and destroy it.
Common ground
The Arduino ground and the motor supply ground must be connected. STEP and DIR are voltage levels measured relative to the driver's logic ground. Without a shared reference, the driver may miss steps or respond randomly. Join them at one point, either on the driver board (its two GND pins are not internally connected on every module, so wire both) or at the supply.
Power-up order
Prefer this sequence: wire everything with power off, connect the logic supply, then switch on the motor supply. Reverse the order when shutting down. Never leave the motor supply on with the logic side unpowered, since the driver's inputs are undefined then.
A first test sketch
This sketch verifies the wiring. It enables the driver, turns one full revolution in each direction (200 steps for a 1.8° motor in full-step mode), and pauses between moves.
const int STEP_PIN = 3;
const int DIR_PIN = 4;
const int ENABLE_PIN = 8;
void stepMotor(int count) {
for (int i = 0; i < count; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(1000);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(1000); // 2000 us period = 500 steps/s
}
}
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(ENABLE_PIN, OUTPUT);
digitalWrite(ENABLE_PIN, LOW); // active low: LOW enables the outputs
}
void loop() {
digitalWrite(DIR_PIN, HIGH);
stepMotor(200); // one revolution
delay(500);
digitalWrite(DIR_PIN, LOW);
stepMotor(200); // one revolution back
delay(500);
}At 500 steps per second this is 150 RPM for a 200-step motor, which is brisk on a lightly loaded shaft. If the motor stalls at this speed, lengthen both delays to 2000 µs. A stall at this point usually means the current limit is too low, a topic for the next chapter.
Wiring faults and their symptoms
| Symptom | Likely wiring cause |
|---|---|
| Motor hums or vibrates but does not turn | Coil pairs mixed up, or one wire loose |
| Motor spins the wrong way | One coil's wires swapped. Reverse either coil, or invert DIR in code |
| Motor does nothing, driver cool | RESET and SLEEP not tied, ENABLE held high, or no VMOT |
| Motor twitches randomly | Missing common ground |
| Driver resets or Arduino reboots | Motor supply dipping, or no bulk capacitor |
| Driver dead after a wiring change | Motor was connected or disconnected under power |
Exercise
A motor's four wires measure as follows with a multimeter: red to blue reads 3.2 ohms, black to green reads 3.2 ohms, and red to black reads open. Which wires go to 1A and 1B, and which go to 2A and 2B? What happens if you connect red and black to 1A and 1B instead?
Show answer
Red and blue form one coil, so they go to 1A and 1B in either order. Black and green form the other coil and go to 2A and 2B in either order. Swapping the two wires within one coil only reverses the rotation direction. If you connect red and black to 1A and 1B, each driver output feeds two different coils. The magnetic fields no longer step in the correct sequence, so the motor hums or vibrates and does not turn smoothly.