By Rohan Easterbrook Fact-checked by Hugo Lindgren Published
The 1.8° step on almost every NEMA 17 comes from 50 rotor teeth and two coils that a driver switches back and forth hundreds of times a second. A bipolar stepper motor has those two coils and no centre taps, so the driver has to reverse the current through each coil. That is the reason it needs an H-bridge driver and not a simple transistor array. Below you’ll find how the motor works, how to find the coil pairs, which driver to pick, how to set the current limit, and working code for one or two steppers on Arduino, ESP32 and Raspberry Pi.
Key takeaways
- A bipolar stepper has two coils and four wires, and it needs an H-bridge driver such as the A4988, DRV8825 or TMC2209.
- A multimeter finds the coil pairs fastest (a few ohms within a pair, open between pairs). Shorting two wires and feeling the shaft also works.
- Set the current with Vref, using the sense resistor on your own board. Clone boards differ, so a copied Vref can be off by a factor of two.
- A motor rated at 2.8 V running from 12 V or 24 V is normal, as long as the driver limits the current.
- To run two steppers, give each one its own driver and STEP/DIR pins, and share the motor supply and ground.
Fact-checked
We checked these key facts against the sources named, on November 18, 2026:
- As Wevolver explains, a 1.8° closed-loop motor still has 200 full steps per revolution, because the encoder doesn’t add resolution (source: wevolver.com)
- It’s also why the DRV8825 and A4988 run each coil at about 70% of the current limit in full-step mode: the two coil currents combine to the full vector (source: ti.com)
- A unipolar motor uses only half of each winding at a time, but it can be driven with four simple low-side switches (source: ti.com)
What is a bipolar stepper motor?
A bipolar stepper motor is a two-phase stepper with two separate windings (coil A and coil B), four leads and no centre tap. The driver moves the rotor by pushing current through each coil in one direction, then the other, in a fixed sequence. Each coil needs its own H-bridge to reverse the current, so a bipolar driver contains two H-bridges.
Quick summary: four wires form two coils. The driver energises them in turn, the rotor’s magnetised teeth line up with whichever stator poles are active, and every change moves the shaft one step. Steppers are the motors and servos family member you use when you need positions you can count without a feedback sensor.
Why “bipolar” means current flows both ways
“Bipolar” describes the drive current, not the magnet. In a bipolar motor each stator pole becomes north or south depending on which way current flows through the whole winding. A unipolar motor gets the same reversal by splitting each winding at a centre tap and energising one half or the other, always in the same direction.
An H-bridge is four switches arranged around the coil. Close one diagonal pair and current flows A+ to A−. Close the other pair and it flows A− to A+. Modern driver chips such as the A4988 from Allegro MicroSystems, the DRV8825 from Texas Instruments and the TMC2209 from Trinamic (now part of Analog Devices) each pack two of these bridges, plus current sensing, into one integrated circuit.
Bipolar vs hybrid vs permanent-magnet: what the terms really describe
These words answer different questions, which is why spec sheets look confusing:
- Bipolar / unipolar describes how the windings are connected and driven.
- Hybrid / permanent-magnet / variable reluctance describes how the rotor is built.
A typical NEMA 17 is a hybrid bipolar motor. “Hybrid” means the rotor combines a permanent magnet with toothed iron cups, which gives a fine 1.8° step and good torque. The cheap 28BYJ-48 is a permanent-magnet unipolar motor with a gearbox. You can rewire some unipolar motors as bipolar, but you can’t change a motor’s rotor type. For the rest of the hardware inside a stepper (stator, rotor, bearings), the electric motor parts are the same ones found in other brushless motors.
How a bipolar stepper moves, one step at a time
The rotor moves in steps because the driver energises the coils in a repeating four-state sequence, and each state pulls the rotor teeth into a new stable position. Four full steps move the rotor exactly one tooth pitch. On a standard hybrid motor that adds up to 200 steps per revolution.
The 4-step full-step sequence
The simplest sequence is wave drive, where one coil is on at a time:
| Step | Coil A | Coil B | Rotor angle |
|---|---|---|---|
| 1 | + (A+ to A−) | Off | 0° |
| 2 | Off | + (B+ to B−) | 1.8° |
| 3 | − (A− to A+) | Off | 3.6° |
| 4 | Off | − (B− to B+) | 5.4° |
| 1 again | + | Off | 7.2° (one tooth pitch) |
Real drivers usually run “two-phase on” full stepping, where both coils are energised at once and the rotor settles between the wave-drive positions. That gives more torque per step. It’s also why the DRV8825 and A4988 run each coil at about 70% of the current limit in full-step mode: the two coil currents combine to the full vector. To reverse direction, the driver runs the same table backwards.
Why 200 steps per revolution
According to NMB Technologies’ stepping-motor engineering reference, a hybrid rotor has two 50-tooth cups on either side of a permanent magnet. 360° divided by 50 teeth gives a 7.2° tooth pitch. Each full step moves a quarter of a pitch, so 7.2° / 4 = 1.8°, and 360° / 1.8° = 200 steps per revolution.
Did you know?
The 1.8° step angle is pure geometry. NMB Technologies explains that a 50-tooth rotor has a 7.2° tooth pitch, and each full step moves the rotor exactly a quarter of that pitch.
Microstepping: smoother and quieter, but not proportionally more precise
Microstepping makes the driver set each coil current to intermediate values along a sine and cosine curve, so the rotor stops between full-step positions.
| Mode | Steps per revolution (1.8° motor) | Typical use |
|---|---|---|
| Full step | 200 | Maximum torque per step, rough and noisy |
| Half step | 400 | Simple drivers, less vibration |
| 1/16 | 3,200 | A4988 maximum, common in 3D printers |
| 1/32 | 6,400 | DRV8825 maximum |
| 1/256 | 51,200 | TMC2209 (native or interpolated) |
There is a trade-off. Microstepping smooths motion and cuts resonance a lot, but the torque change between two adjacent microsteps is small. A light load or friction can keep the rotor from landing exactly on each microstep. So 1/16 gives smoother movement, but you can’t count on 3,200 truly accurate positions. For positioning, plan on full-step accuracy and treat microsteps as smoothing.
Bipolar vs unipolar stepper motors
At low and medium speed a bipolar motor gives more torque from the same copper, because the whole winding carries current all the time. A unipolar motor uses only half of each winding at a time, but it can be driven with four simple low-side switches. The engineering comparison published by Tech Briefs puts the bipolar advantage at √2, roughly 40% more torque, for the same copper losses.
| Feature | Bipolar | Unipolar |
|---|---|---|
| Wires | 4 (or 8 wired as 4) | 5 or 6 |
| Winding use | Whole coil, current reversed | Half coil at a time, one direction |
| Low-speed torque, equal copper loss | About √2 (≈40%) higher | Baseline |
| High-speed torque, voltage drive | Falls off earlier (higher inductance) | Can be higher, since current rises faster in half a coil |
| Drive circuit | Two H-bridges (8 switches) | 4 low-side switches |
| Typical driver | A4988, DRV8825, TMC2209 | ULN2003 |
| Typical motor | NEMA 17 in printers and robots | 28BYJ-48 |
When unipolar still makes sense
Unipolar wins in two narrow cases. The first is cost and simplicity: a ULN2003 board and a 28BYJ-48 are hard to beat for a slow dial or vent flap. The second is speed under plain voltage drive. Tech Briefs notes that at high step rates without a chopper driver, a unipolar motor can give more torque, because each half coil has lower inductance and its current rises faster. With a modern current-chopping driver and a higher supply voltage, that advantage mostly goes away, which is why 3D printers and CNC machines run bipolar.
Converting a 5- or 6-wire motor to bipolar
On a 6-wire motor, leave the two centre taps unconnected and insulated, and use the four coil ends. It now behaves as a 4-wire bipolar motor. A 5-wire motor has both centre taps joined inside, so you have to open the motor and cut that joint first.
Did you know?
Hackaday reported that cutting a single PCB trace inside a 28BYJ-48 turned it into a bipolar motor. Measured torque went from about 380 g·cm in unipolar mode to about 800 g·cm after the change.
After the conversion the ULN2003 board no longer works with that motor. You need a bipolar driver with a low current limit, set to suit the small coils.
Identify the coil pairs on any stepper (4, 6 or 8 wires)
Two wires belong to the same coil if a multimeter shows a few ohms between them. Wires from different coils show an open circuit. Without a meter, short two wires together and turn the shaft by hand. If the shaft suddenly feels notchy and stiff, those two wires are a coil pair.
| Wires | Type | Expected readings | How to wire as bipolar |
|---|---|---|---|
| 4 | Bipolar | Two pairs of a few ohms each, open between pairs | Pair 1 to A1/A2, pair 2 to B1/B2 |
| 5 | Unipolar, common joined inside | Common to every other wire reads the same value | Only after opening the motor and splitting the common (e.g. 28BYJ-48) |
| 6 | Unipolar with centre taps | End to end = 2× centre to end (e.g. 4 Ω vs 2 Ω) | Use the two ends of each coil, insulate the centre taps |
| 8 | Four separate half-windings | Four pairs of equal resistance | Join halves in series or parallel to make two coils |
4-wire motors
Set your meter to its lowest resistance range (or continuity mode). If continuity testing with a multimeter is new to you, practise on a known resistor first. Touch one probe to a wire, then try the other three. One of them reads a few ohms, close to the “phase resistance” on the spec sheet, and that’s the partner. The remaining two wires form the second coil.
This is the answer to a very common forum question: “Which wires are the coil pairs on my 4-wire stepper? The colours don’t match the diagram.” Colours aren’t standardised between makers, so measure every time. Polarity within a pair only affects direction.
6-wire motors: find and ignore the centre taps
Each coil has three wires. Buildbotics’ wiring guide gives the pattern: the centre tap reads half the end-to-end resistance, for example 2 Ω centre-to-end and 4 Ω end-to-end. Find the two wires with the highest reading in each group of three. Those are the coil ends. Cap or heat-shrink the centre taps separately so they can’t touch anything.
You can also run “half-coil” by using one end and the centre tap. You get less torque but lower inductance, which helps at high speed.
8-wire motors: series vs parallel
Eight wires means each phase is split into two half-windings that you join yourself:
- Series: connect the two halves end to end. Inductance and resistance go up, low-speed torque is strong, and the current rating drops. This suits slow, heavily loaded axes and drivers with low current limits.
- Parallel: connect the halves side by side. Inductance is lower, high-speed torque is better, and the motor needs more current.
Use the maker’s diagram to get each half-winding’s polarity right. If you join one half backwards, its magnetic field cancels the other half’s.
Salvaged motors with no datasheet
Small steppers from old inkjet printers and the sled steppers in DVD drives are almost always 4-wire bipolar. Find the pairs with a meter (or by shorting the wires), then start with a low current limit of a few hundred milliamps. Raise it slowly until the motor moves reliably without getting hot. Tiny DVD motors have thin flex leads, so solder short wires to them before connecting a driver.
Maker tip
If the motor turns the wrong way, swap the two wires of one coil only (A1 with A2). Swapping both pairs leaves the direction unchanged. Changing the DIR logic in code works just as well.
Choosing a driver: A4988 vs DRV8825 vs TMC2209
The TMC2209 is the quietest of the three, the DRV8825 accepts supplies up to 45 V and steps down to 1/32, and the A4988 steps down to 1/16 and is the cheapest working setup on an Arduino Uno. All three use the same STEP/DIR interface and similar 16-pin “StepStick” footprints, so you can swap them on a CNC Shield.
| Driver | Supply voltage | Continuous / peak current | Max microstep | Noise | Best for |
|---|---|---|---|---|---|
| A4988 (Allegro; Pololu carrier) | 8–35 V | ~1 A per phase without heatsink, up to 2 A with cooling | 1/16 | Audible whine | Cheap Uno builds, learning |
| DRV8825 (Texas Instruments; Pololu carrier) | 8.2–45 V | 1.75 A RMS / 2.5 A peak with heatsinking (24 V, 25 °C) | 1/32 | Audible, sometimes harsher at low speed | 24–36 V machines, higher speed |
| TMC2209 (Trinamic / Analog Devices) | 4.75–29 V chip; boards often 28 V | 2 A RMS / 2.8 A peak | 1/256 | Near silent in StealthChop2 | Quiet printers, ESP32 and Pi robots |
Figures come from Pololu’s product pages, the RepRap DRV8825 wiki and the Analog Devices TMC2209 datasheet rev 1.08.
A4988: cheap and simple
The A4988 accepts 3–5.5 V logic, so it works with a 5 V Uno and a 3.3 V ESP32 alike. Pololu rates its carrier at about 1 A per phase without a heatsink. Past that it needs cooling, and it hits thermal shutdown sooner than the others. MS1–MS3 all low gives full step, and all high gives 1/16. It’s a good learning driver, but the high-pitched chopping whine is noticeable in a quiet room.
DRV8825: higher voltage, 1/32 step
Pololu’s DRV8825 carrier accepts up to 45 V and offers six step resolutions down to 1/32. A higher supply voltage makes coil current rise faster, so top speed improves. Pololu recommends keeping an uncooled carrier at 1.5 A per phase or below to avoid thermal shutdown. The pinout matches the A4988 closely, but the current formula is different (covered below), and that catches people out.
TMC2209: silent StealthChop and UART tuning
The TMC2209 is the default quiet choice in maker printers. The Analog Devices datasheet lists 2 A RMS and 2.8 A peak coil current, plus two chopper modes: StealthChop2, which is near silent at low and medium speed, and SpreadCycle, which gives better torque at high speed. In standalone mode MS1 and MS2 select 1/8, 1/16, 1/32 or 1/64 steps, and the chip interpolates to 1/256. Over its single-wire UART (PDN_UART pin) you can set current, standstill current and microstepping in software. The TMCStepper Arduino library is the usual way to do that.
Check the module rating, not just the chip. The BIGTREETECH wiki lists its TMC2209 boards at 4.75–28 V or 5.5–28 V depending on version, slightly below the chip’s 29 V.
Is the TMC2209 worth it over the A4988 for a quiet build? Yes. Noise is the main reason to pay more, and the gap is obvious in a living room or a desk robot. It also lowers holding current automatically at standstill (when configured over UART), which keeps motors cooler. If the machine lives in a garage and noise doesn’t matter, the A4988 does the job.
Drivers to avoid for bipolar motors
- ULN2003: a Darlington array that can only sink current to ground. It can’t reverse current through a coil, so it can’t drive a bipolar motor at all. It’s meant for unipolar motors like the 28BYJ-48.
- L298N: it is a dual H-bridge, so it will turn a bipolar motor. But its bipolar transistors drop a couple of volts and turn that into heat. The common red modules also have no current regulation, so you have to match the supply voltage to the motor’s rated voltage. That gives poor torque at speed, and a 2.8 V motor on 12 V burns. Any of the three chopper drivers above is better and smaller.
What you need before wiring
You need a matched motor, driver, supply and controller, plus a multimeter for Vref. Here’s a typical single-axis kit:
| Part | Example | Notes |
|---|---|---|
| Bipolar stepper | NEMA 17, e.g. 17HS4401 | Check rated current per phase |
| Driver | A4988, DRV8825 or TMC2209 module | Heatsink above ~1 A |
| Controller | Arduino Uno, ESP32 DevKitC, or Raspberry Pi | 3.3 V logic is fine for all three drivers |
| Motor supply | 12 V or 24 V DC, enclosed adapter | At least 2 A for one or two NEMA 17s |
| Bulk capacitor | 100 µF electrolytic, rated 35 V or more | Across VMOT and GND at the driver |
| Multimeter | Any DC voltmeter | For coil pairs and Vref |
| Optional | Arduino CNC Shield V3 | Holds up to four drivers on an Uno |
Power check
Keep motor voltage inside the module’s rating (A4988 35 V, DRV8825 45 V, BTT TMC2209 28 V) with margin for spikes. Use an enclosed DC adapter. If you’re using an open-frame supply with exposed mains terminals, have a qualified electrician wire the AC side.
Build steps
- Find the two coil pairs with a meter or by shorting the wires.
- With everything unpowered, wire logic, motor supply, capacitor and motor.
- Set microstep pins (or leave them low for the default).
- Power up and adjust Vref to your target current.
- Upload the test code and watch for smooth rotation.
- After a few minutes, check motor and driver temperature.
Wiring a bipolar stepper to Arduino, ESP32 and Raspberry Pi
Every setup follows the same pattern: the controller sends STEP and DIR pulses, the driver gets a separate motor supply on VMOT, and every ground is shared. The motor’s two coils go to the driver’s A and B outputs (labelled 1A/1B and 2A/2B on Pololu-style boards).
Maker tip
Never connect or disconnect the motor while the driver is powered. The coil’s inductive voltage spike can destroy an A4988 or DRV8825 instantly. A loose motor plug causes the same failure.
Arduino Uno + A4988
The pins below match the X axis of the Arduino CNC Shield (STEP D2, DIR D5, enable D8), so the same code works with or without the shield.
| From (Uno) | To (A4988) | Purpose |
|---|---|---|
| D2 | STEP | Step pulses |
| D5 | DIR | Direction |
| D8 | EN | Enable (LOW = on) |
| 5V | VDD | Logic supply |
| GND | GND (logic side) | Logic ground |
| 12 V supply + | VMOT | Motor power |
| 12 V supply − | GND (motor side) | Motor ground, also tied to Uno GND |
| 100 µF cap | Across VMOT and GND | Spike absorption, observe polarity |
| A4988 RESET | A4988 SLEEP | Bridge together so the driver stays awake |
| Coil pair 1 | 1A, 1B | Motor phase A |
| Coil pair 2 | 2A, 2B | Motor phase B |
With MS1–MS3 unconnected the A4988 runs full step. Tie all three to 5 V for 1/16.
ESP32 + TMC2209
The TMC2209 works directly with 3.3 V logic on VIO. On an ESP32 DevKitC, use ordinary GPIOs. Avoid strapping pins (GPIO 0, 2, 5, 12, 15) and the input-only pins 34–39.
| From (ESP32 DevKitC) | To (TMC2209 module) | Purpose |
|---|---|---|
| GPIO 25 | STEP | Step pulses |
| GPIO 26 | DIR | Direction |
| GPIO 27 | EN | Enable (LOW = on) |
| 3V3 | VIO | Logic supply |
| GND | GND | Shared ground |
| 24 V supply + | VM | Motor power (board max 28 V) |
| 24 V supply − | GND | Motor ground |
| 100 µF / 35 V cap | Across VM and GND | Spike absorption |
| Coil pair 1 | A1, A2 (or 1A, 1B) | Phase A |
| Coil pair 2 | B1, B2 (or 2A, 2B) | Phase B |
With MS1 and MS2 both low, the TMC2209 datasheet’s standalone table gives 1/8 microstepping, interpolated to 1/256 internally. Most modules default to StealthChop in this mode.
Raspberry Pi + DRV8825
The DRV8825 has no logic-supply pin and accepts 3.3 V signals, so it pairs easily with the Pi’s GPIO.
| From (Raspberry Pi) | To (DRV8825) | Purpose |
|---|---|---|
| GPIO 21 (physical pin 40) | STEP | Step pulses |
| GPIO 20 (physical pin 38) | DIR | Direction |
| GPIO 16 (physical pin 36) | EN | Enable (LOW = on) |
| 3V3 (physical pin 1) | RST and SLP | Keep the driver awake |
| 3V3 (physical pin 1) | M0 and M1 | Selects 1/8 step |
| GND (physical pin 39) | GND | Shared ground |
| 24 V supply + | VMOT | Motor power |
| 24 V supply − | GND | Motor ground |
| 100 µF / 35 V cap | Across VMOT and GND | Spike absorption |
| Coil pairs | A1/A2, B1/B2 | Motor phases |
Never power the motor from the Pi’s 5 V pins. The Pi only shares ground and logic signals with the driver.
Setting the current limit (Vref) correctly
Vref is the voltage on the driver’s trimmer that sets the maximum coil current. You measure it with a multimeter between GND and the trimmer’s wiper (the metal top of the pot) while the driver is powered, then turn the trimmer until it reads your target. The formula depends on the chip and on the sense resistor (Rs) fitted to your specific board.
Find your sense resistor
For the A4988 the relationship is Imax = Vref / (8 × Rs). Rs is printed on the two small resistors next to the chip:
- R068 or 68L0 = 0.068 Ω, found on some Pololu A4988 carriers.
- R050 = 0.050 Ω, found on older Pololu boards.
- R100 = 0.100 Ω.
This explains the question “My A4988 Vref formula gives a different number than the tutorial, which Rs do I use?” Use the value printed on your own board, never the one in a tutorial.
Maker tip
Photograph the sense resistors with your phone and zoom in before you calculate anything. A 0.05 Ω board set to a Vref meant for 0.1 Ω pushes twice the intended current through the motor.
Worked example for a 1.5 A NEMA 17
Take a 1.5 A motor and aim for about 1.2 A (80% of rating), which keeps it cooler with little torque loss.
| Driver / board | Formula | Vref for 1.2 A |
|---|---|---|
| A4988, Rs 0.068 Ω (some Pololu boards) | Vref = 8 × I × Rs | 0.65 V |
| A4988, Rs 0.1 Ω (many clones) | Vref = 8 × I × Rs | 0.96 V |
| A4988, Rs 0.05 Ω (older boards) | Vref = 8 × I × Rs | 0.48 V |
| DRV8825, Pololu 0.1 Ω | Vref = I / 2 | 0.60 V |
| TMC2209, BTT/FYSETC 0.11 Ω (standalone) | Vref ≈ Irms × 1.41 | ≈1.2 V for 0.85 A RMS |
The mix-up is easy to see in numbers. Set 0.96 V on a 0.05 Ω board and you get 0.96 / 0.4 = 2.4 A, well above the motor’s rating and enough to overheat the driver. Set 0.65 V on a 0.1 Ω board and you get only 0.81 A, which can leave the motor weak.
The TMC2209 formula uses RMS current. FYSETC and BTT documentation for 0.11 Ω boards gives Vref = Irms × 2.5 / 1.77, about Irms × 1.41. A rated current of 1.2 A per phase works out to roughly 0.85 A RMS (1.2 / √2), so 1.2 V is a safe start. In UART mode the software setting generally takes over from the pot.
Why a 12 V motor on 24 V (or a 2.8 V motor on 12 V) is fine
A stepper’s “rated voltage” is simply rated current × coil resistance. For example, 1.7 A × 1.65 Ω ≈ 2.8 V. A chopper driver applies the full supply voltage so current builds quickly, then switches off and on to hold it at the Vref limit. A higher supply voltage just means current reaches the limit sooner each step, which keeps torque up at speed.
So yes, you can use a 12 V supply for a motor rated 2.8 V, as long as the driver limits current. That only holds for current-limiting drivers. On an L298N module with no chopper, the same motor would draw several amps and cook.
Too high vs too low: the symptoms
| Vref setting | What you notice |
|---|---|
| Too high | Driver too hot to touch, thermal shutdown (motor stops and restarts), motor very hot, extra noise |
| Correct | Smooth motion, motor warm, driver warm with heatsink |
| Too low | Weak torque, missed steps under load, buzzing without motion |
“Motor buzzes and then stops after I lowered Vref” is the too-low case. The coils are still energised, but there’s not enough torque to overcome load, friction or detent at that speed. Raise Vref in small steps (about 0.05 V), and lower speed or acceleration in code. On a DRV8825 in full-step mode, remember the coils only see about 70% of the limit.
Code that works: AccelStepper and plain STEP/DIR
Every STEP pulse moves the motor one microstep in the direction set by DIR. Start with a bare pulse loop to prove the wiring, then switch to the AccelStepper library (install it from the Arduino IDE Library Manager), which adds acceleration so the motor doesn’t stall at speed.
Minimal STEP/DIR sketch
Assumes the Uno wiring above with the A4988 at 1/16 (MS1–MS3 to 5 V).
const int STEP_PIN = 2;
const int DIR_PIN = 5;
const int EN_PIN = 8;
const int STEPS_PER_REV = 200 * 16; // full steps x microstep setting
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW); // LOW enables the driver
}
void spin(bool forward) {
digitalWrite(DIR_PIN, forward ? HIGH : LOW);
for (int i = 0; i < STEPS_PER_REV; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(5); // pulse width, well above the driver minimum
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(300); // sets speed: about 1 rev per second here
}
}
void loop() {
spin(true);
delay(1000);
spin(false);
delay(1000);
}
AccelStepper with acceleration
\#include <AccelStepper.h>
const int EN_PIN = 8;
AccelStepper stepper(AccelStepper::DRIVER, 2, 5); // STEP pin, DIR pin
void setup() {
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW);
stepper.setMaxSpeed(2000); // steps per second
stepper.setAcceleration(1500); // steps per second squared
stepper.moveTo(3200); // one revolution at 1/16
}
void loop() {
if (stepper.distanceToGo() == 0) {
stepper.moveTo(-stepper.currentPosition()); // bounce back and forth
}
stepper.run(); // call as often as possible; never use delay() here
}
On an ESP32 the same sketch works if you change the pins to AccelStepper stepper(AccelStepper::DRIVER, 25, 26); and EN_PIN = 27. Remember 1/8 microstepping, so one revolution is 1,600 steps.
Python on the Pi
On the Raspberry Pi 5, the old RPi.GPIO library can’t reach the GPIO pins, because they sit behind the RP1 I/O chip. gpiozero comes preinstalled on Raspberry Pi OS and uses the lgpio backend on the Pi 5 automatically. This script works on Pi 3, 4 and 5.
from gpiozero import DigitalOutputDevice
from time import sleep
STEP = DigitalOutputDevice(21)
DIR = DigitalOutputDevice(20)
EN = DigitalOutputDevice(16, initial_value=False) # pin LOW = driver enabled
STEPS_PER_REV = 200 * 8 # DRV8825 at 1/8 step (M0 and M1 high)
DELAY = 0.0005 # seconds per half-pulse
def spin(revs, forward=True):
DIR.value = forward
for _ in range(int(revs * STEPS_PER_REV)):
STEP.on()
sleep(DELAY)
STEP.off()
sleep(DELAY)
try:
spin(1, True)
sleep(1)
spin(1, False)
finally:
EN.on() # pin HIGH disables the driver so the motor cools
Linux isn’t a real-time system, so Python timing jitters. It’s fine for slow positioning. For smooth high-speed motion, let a microcontroller generate the pulses and send it commands from the Pi.
Steps per mm and the expected result
Steps per mm converts motor steps into machine travel:
- GT2 belt, 20-tooth pulley, 1/16: (200 × 16) / (2 mm × 20) = 80 steps/mm
- T8 lead screw with 8 mm lead, 1/16: 3,200 / 8 = 400 steps/mm
When everything is right, the shaft turns one full revolution per 200 × microstep pulses, reverses cleanly, and runs without grinding. After ten minutes the motor case is warm and the driver is warm, not scorching. If you see anything else, go to the troubleshooting table below.
How to run two steppers from one board
To run two steppers, give each motor its own driver and its own STEP and DIR pins, power both drivers from the same motor supply, and connect all grounds together. In code, create two AccelStepper objects and call run() on both in every loop. If both motors must arrive at the same moment, use MultiStepper.
Two drivers, separate STEP/DIR
On an Uno with a CNC Shield, the Y axis uses STEP D3 and DIR D6, and D8 enables all drivers. Without a shield, wire a second driver exactly like the first, on two spare pins.
\#include <AccelStepper.h>
const int EN_PIN = 8;
AccelStepper stepperX(AccelStepper::DRIVER, 2, 5); // X: STEP D2, DIR D5
AccelStepper stepperY(AccelStepper::DRIVER, 3, 6); // Y: STEP D3, DIR D6
void setup() {
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW);
stepperX.setMaxSpeed(1500);
stepperX.setAcceleration(1000);
stepperY.setMaxSpeed(1000);
stepperY.setAcceleration(800);
stepperX.moveTo(3200);
stepperY.moveTo(-1600);
}
void loop() {
if (stepperX.distanceToGo() == 0) stepperX.moveTo(-stepperX.currentPosition());
if (stepperY.distanceToGo() == 0) stepperY.moveTo(-stepperY.currentPosition());
stepperX.run();
stepperY.run();
}
Each motor accelerates on its own profile, which is ideal for two independent mechanisms such as a pan-tilt head or the two drive wheels of a robot. A 16 MHz Uno shares its pulse budget between both motors, so keep combined speeds modest. An ESP32 has much more headroom.
Coordinated moves with MultiStepper
MultiStepper ships inside the AccelStepper package and handles up to 10 motors as a group. It makes them start and finish together, but it uses constant speed with no acceleration.
\#include <AccelStepper.h>
\#include <MultiStepper.h>
AccelStepper stepperX(AccelStepper::DRIVER, 2, 5);
AccelStepper stepperY(AccelStepper::DRIVER, 3, 6);
MultiStepper both;
void setup() {
pinMode(8, OUTPUT);
digitalWrite(8, LOW);
stepperX.setMaxSpeed(1000);
stepperY.setMaxSpeed(1000);
both.addStepper(stepperX);
both.addStepper(stepperY);
}
void loop() {
long target[2] = {3200, 1600};
both.moveTo(target);
both.runSpeedToPosition(); // blocks until both arrive
delay(1000);
long home[2] = {0, 0};
both.moveTo(home);
both.runSpeedToPosition();
delay(1000);
}
For drawing machines with diagonal lines, GRBL firmware on a CNC Shield is the next step up, with proper acceleration-planned coordinated motion.
Two motors on one axis
Gantries often need two motors doing the same job. You have three options:
- Two drivers sharing STEP and DIR. Each motor gets its own current limit. This is the best option, and the CNC Shield’s A-axis jumpers can clone X, Y or Z this way.
- Two motors in series on one driver. Each motor sees the full set current, but the combined inductance needs a higher supply voltage for speed.
- Two motors in parallel on one driver. Current splits unevenly between the motors. Avoid it on small drivers.
If one motor on a shared axis runs backwards, flip one coil pair on that motor only.
Power budget for two steppers
A chopper driver works like a step-down converter, so the supply draws less current than the coil current setting. For two NEMA 17s at about 1.2 A each, a 12 V 3 A or 24 V 2 A supply leaves comfortable headroom. Put a 100 µF capacitor at each driver, not one for the whole board.
Reading a NEMA 17 spec sheet (and what 42-34 vs 42-40 means)
NEMA 17 sets only the faceplate: 1.7 inches, about 42 mm square, with standard mounting holes. Torque, current and length vary widely. NEMA 23 is the next common size up at about 57 mm. Five figures on a spec sheet matter:
| Spec | What it means | Why you care |
|---|---|---|
| Holding torque | Torque at standstill with rated current, e.g. 40 N·cm | Upper bound; usable torque at speed is lower |
| Rated current (per phase) | Max continuous coil current | Sets your Vref ceiling |
| Phase resistance | Coil DC resistance | Confirms coil pairs; rated voltage = I × R |
| Inductance | Coil inductance in mH | Higher means torque drops sooner with speed |
| Body length | Depth of the motor, e.g. 40 mm | Longer usually means more torque |
42-34 vs 42-40 vs 42-48
These names give the frame size and body length in millimetres. “42-34” is a 42 mm NEMA 17 with a 34 mm body, and “42-40” has a 40 mm body. JLCMC’s NEMA size guide lists NEMA 17 bodies from about 34 mm to 60 mm, with 33–40 mm in the low-torque tier and 40–47 mm in the standard tier. Longer bodies hold more copper and a deeper rotor stack, so more torque.
Choose by load. A 42-34 suits extruders, light robot arms and camera sliders where weight matters. A 42-40 is the all-rounder for printer axes. A 42-48 suits heavier gantries and Z axes lifting a bed. If even that runs out of torque, move up to NEMA 23 and a driver that can supply its higher current.
Why inductance limits top speed
Every step needs the coil current to reverse, and inductance slows that down. As step rate rises, the current never reaches the set limit, so torque falls. A low-inductance motor, or a higher supply voltage on the same motor, pushes that drop-off to a higher speed. That’s the practical reason makers run 24 V supplies with the DRV8825 and TMC2209.
Spec conflicts on cheap motors
The 17HS4401 is a typical case. Datasheet listings agree on 1.8° steps and 40 N·cm (56 oz·in) holding torque, but sellers quote 1.5 A or 1.7 A rated current. So if one seller says 1.5 A and another says 1.7 A, which is right? You can’t tell from the listing. Do two things:
- Measure the phase resistance and compare it with the seller’s figure. A large mismatch means a different winding.
- Set Vref for the lower figure, 1.5 A or below. Most builds run fine at 1.0–1.3 A, and the motor runs cooler.
Are closed-loop steppers worth it?
For most hobby printers, plotters and robots, no. A closed-loop stepper adds an encoder that detects lost steps and corrects them. As Wevolver explains, a 1.8° closed-loop motor still has 200 full steps per revolution, because the encoder doesn’t add resolution. Sizing the motor properly, setting Vref correctly and keeping acceleration sensible solves the same missed-step problem for less money.
Closed loop pays off when:
- a missed step ruins expensive material, such as a CNC router cutting hardwood or aluminium
- the load varies unpredictably and you can’t afford homing between moves
- you want the motor to run cooler, since many closed-loop drivers cut current when the load is light
There’s also a cheaper middle ground. The TMC2209’s StallGuard4 feature can detect a stall without an encoder, which is enough for sensorless homing on many printers.
Troubleshooting bipolar steppers
Most stepper faults come down to three things: coil wiring, current setting and acceleration. Start at the top of the table and work down.
| Symptom | Likely cause | Fix |
|---|---|---|
| Vibrates or buzzes but doesn’t turn | Coil pairs mixed (one wire from each coil on the same output), or Vref far too low or high | Re-measure pairs; put each pair on 1A/1B and 2A/2B; reset Vref |
| Turns the wrong way | Coil polarity | Swap one coil’s two wires, or invert DIR in code |
| Turns erratically, back and forth | One coil open or a loose crimp | Check continuity of each pair at the driver end |
| Motor too hot to touch at standstill | Full holding current flows when stopped; Vref above rating | Lower Vref; disable via EN when idle; use TMC2209 standstill reduction |
| Driver very hot or shutting down | Current above the driver’s uncooled limit | Add heatsink and airflow; reduce Vref |
| Missed steps at high speed | Not enough torque at speed (inductance), acceleration too high | Lower acceleration; raise supply to 24 V; switch to SpreadCycle on TMC2209 |
| Loud whine or resonance | A4988/DRV8825 chopping noise, mid-band resonance | Use microstepping; try a TMC2209 in StealthChop2; change speed |
| Driver died instantly | Motor plugged in or unplugged while powered, or reverse polarity on VMOT | Replace driver; only connect with power off |
“Stepper motor vibrating but not turning, what am I doing wrong?” is the most common question on the Arduino forum, and the thread answers usually point to a miswired coil pair or a badly set current limit. Measure the pairs first, because colour charts are wrong so often.
“My NEMA 17 gets too hot to touch even when it’s not moving” is usually normal behaviour taken too far. Steppers draw full current while holding, so a case around 70–80 °C can be within spec. That’s still uncomfortable, and it can soften PLA mounts. Lower Vref to 70–80% of rated current, or disable the driver when holding torque isn’t needed.
Power check
A stepper can get hot enough to burn skin and deform 3D-printed mounts. Keep the driver’s current at or below the motor rating, and fit a heatsink to any driver running above about 1 A.
Your next build with a bipolar stepper
Once one motor runs smoothly at the right current, the next step is mechanical: fit a GT2 belt or a lead screw, calculate steps per mm, and add a limit switch so the code can home to a known zero. With two axes running, a pen plotter or a camera slider with pan is a natural first project. If you want a screen showing position or speed, a small liquid crystal display LCD on I2C pairs easily with the Uno or ESP32 code above.
FAQ
What is the difference between 42-40 and 42-34 stepper motors?
Both are 42 mm NEMA 17 motors. The second number is body length in millimetres: 40 mm vs 34 mm. The longer 42-40 holds more copper and rotor, so it gives more holding torque. The shorter 42-34 is lighter and better suited to extruders and small moving parts.
What is a hybrid step motor?
A hybrid stepper combines a permanent-magnet rotor with toothed iron cups, usually 50 teeth each. That pairing gives the fine 1.8° (200-step) resolution typical of hybrid stepper motors, including many NEMA 17 and NEMA 23 motors. Most hybrid motors used by makers are wired bipolar.
Are closed loop steppers worth it?
Rarely, for hobby builds. The encoder catches and corrects lost steps but doesn’t increase resolution beyond 200 full steps. It’s worth it on CNC machines where a missed step ruins material. For printers and robots, correct current and acceleration settings usually do the job.
How do stepper motors work?
The driver energises the stator coils in a fixed sequence. The rotor’s magnetised teeth line up with whichever poles are active. Each change in the sequence moves the shaft one step, 1.8° on a standard motor, so the controller knows the position by counting pulses.
What is the difference between bipolar and unipolar stepper motors?
A bipolar motor has two coils and four wires, and it needs an H-bridge to reverse current. A unipolar motor has centre-tapped coils (5 or 6 wires) and can be driven by simple switches. At equal copper loss, bipolar gives about 40% more torque.
Can I drive a bipolar stepper motor with a ULN2003?
No. The ULN2003 can only pull current to ground in one direction, and a bipolar coil needs its current reversed. Use an A4988, DRV8825 or TMC2209.
How do I know if my stepper motor is bipolar?
Count the wires and measure them. Four wires that form two pairs of a few ohms each, with no connection between the pairs, means a bipolar motor. Six-wire and eight-wire motors can usually be wired as bipolar. Five-wire motors can’t, unless you modify them inside.
Can a 6-wire unipolar stepper be used as bipolar?
Yes. Find the centre taps (they read half the end-to-end resistance), leave them unconnected and insulated, and connect the two ends of each coil to the driver’s outputs.
Which driver is best for a NEMA 17 bipolar stepper?
The TMC2209 is the best all-round choice: 2 A RMS, near-silent StealthChop2 and 3.3 V logic. Choose the DRV8825 for supplies above 28 V, and the A4988 for the lowest cost.
How do I set Vref on an A4988 or TMC2209?
Power the driver, then measure between GND and the trimmer’s wiper. For the A4988, Vref = 8 × current × Rs, using the sense resistor value printed on your board. For a BTT or FYSETC TMC2209 with 0.11 Ω resistors, Vref ≈ RMS current × 1.41. In UART mode, set the current in software instead.
Notes on this article
- Fact-checked by Hugo Lindgren against the sources listed below before publication.
- Published
Fact-checking
- Researched from 8 sources, listed below.
- Every claim is checked by Hugo Lindgren; anything we cannot confirm is corrected, labelled or removed.
Sources (8)
- Bipolar and Unipolar Drives for Stepper Motors: A Comparison (Tech Briefs) (techbriefs.com)
- Changing Unipolar Steppers to Bipolar (Hackaday) (hackaday.com)
- TMC2209 Datasheet rev1.08 (Analog Devices) (wcm-cce.cldnet.analog.com)
- TMC2209-LA-T listing (datasheets.com)
- BIGTREETECH TMC2209 wiki (bttwiki.com)
- FYSETC Silent2209 (fysetc.github.io)
- Pololu A4988 Stepper Motor Driver Carrier (pololu.com)
- Pololu A4988 Stepper Motor Driver Carrier (sense resistor and Vref) (pololu.com)









