ESP32 UNO - Stepper Motor A4988 Driver
Rolling cable or 3D-printer filament onto a spool by hand is slow, and around turn eleven you have already lost count. A stepper motor is a good helper here. It moves in small equal steps, and 200 of them make one full turn, so "20 turns" is just a number in your sketch. The DIYables A4988 module sits between the motor and the ESP32 Uno form board: the board sends two small signals, and the module sends the strong current to the motor. At the end of this page you have a winder that starts softly, stops softly and reports how many turns it has wound.
The route from here:
- Read the sixteen pins of the A4988 and see what STEP and DIR do
- Find the two coils of a NEMA 17 motor
- Choose the step size and set the current limit
- Connect everything, with the expansion board or with the module alone
- Spin the spool without a library, then wind 20 turns with AccelStepper

Components You Need
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Good to know: the expansion board is optional. The module then needs a few more wires and one extra capacitor, and this page shows that version too. In both versions the 12V adapter feeds only the motor, and the ESP32 Uno runs from USB.
Meet the A4988 Driver
Ten minutes of reading here, and no pin on this little red board will surprise you later.
Its shape is the well-known StepStick: a board the size of a stamp (roughly 20 x 15 mm) on sixteen pins, and the pins come soldered. The A4988 chip in the middle drives one bipolar stepper motor. That is a motor with four wires, or one with six wires when you use only four of them. The small heat sink in the package sticks on top of the chip.

| Item | Value |
|---|---|
| Power for the motor, on VMOT | any DC supply from 8V to 35V, 12V in this project |
| Power for the logic, on VDD | 3V to 5.5V, here the 3.3V of the ESP32 Uno |
| Most current per coil | around 1A bare, 2A with the heat sink and a good air flow |
| Five step sizes | from full steps down to 1/16 of a step |
| Wires for control | 2, STEP and DIR |
| Built-in protection | switches off when too hot or when the supply is too low, and prevents crossover current (a short inside its own outputs) |
| Fault output | none, this module has no FAULT pin |
The Sixteen Pins
Hold the module so that the pin EN is at the top left. Eight pins run down the left side, eight down the right side.
| Pin | Side | Its Job |
|---|---|---|
| EN | Left | Motor outputs on or off. LOW or no wire = on, HIGH = off and the shaft turns freely |
| MS1, MS2, MS3 | Left | Step size. A pin without a wire counts as LOW |
| RST | Left | Reset when LOW. Nothing holds this pin, it floats, so join it to SLP |
| SLP | Left | Sleep when LOW. The module pulls it HIGH by itself |
| STEP | Left | One change from LOW to HIGH = one step |
| DIR | Left | Turning direction |
| VMOT | Right | Power for the motor |
| GND, next to VMOT | Right | Ground of the motor power |
| 2B and 2A | Right | The two ends of coil 2 |
| 1A and 1B | Right | The two ends of coil 1 |
| VDD | Right | Power for the logic |
| GND, next to VDD | Right | Ground of the logic |
The two GND pins are one and the same net, joined on the module. On the top side of the board, the coil pins carry the labels B2, A2, A1 and B1. Turn the module over and you read 2B, 2A, 1A and 1B. Both mean the same pins.
Two Signals Do the Work
Imagine a hand counter with a click button. Every click on STEP moves the shaft by one step, and DIR decides if the clicks go up or down. The "click" is the moment the pin changes from LOW to HIGH. A stepper motor needs its coils switched in a fixed order, and a part of the chip called the translator knows that order by heart. So the sketch never has to think about coils.
The chip watches the coil current as well. It chops the current, which means it switches it off and on very quickly, so the current stays at the limit you set. So do not worry when the label of your motor says 2V to 4V: the chip, not the 12V adapter, decides how much current flows.
Each pulse must be HIGH for at least 1 us (one millionth of a second) and LOW for at least 1 us. An ESP32 can switch a pin faster than that, so both sketches on this page wait a little in each half of the pulse.
VDD Must Be 3.3V on the ESP32 Uno
Some drivers take their logic power from the motor supply. This one does not. With no wire on VDD the motor never moves, even when VMOT has 12V. The second point is the level: seven tenths of VDD (0.7 x VDD) is the border, and a signal has to be higher than that to pass as HIGH.
| VDD | HIGH Starts at | A 3.3V Pulse from the ESP32 Uno |
|---|---|---|
| 3.3V | 2.31V | clearly HIGH |
| 5V | 3.5V | below the line, steps can get lost |
So VDD, or the V pin of the expansion board, goes to the 3V3 pin. Never use 5V for it on this board.
What the Expansion Board Adds
The expansion board for DRV8825 / A4988 is a 42 x 42 mm carrier. The module plugs into two 8-pin sockets, and the board brings the pins out in a friendlier way.
- G V S header: three rows named EN, STEP and DIR. S takes the signal, V leads to VDD and G is ground. V is one shared line for all three rows, and G is another one. Bring a single wire to each of them, in whichever row is easy to reach.
- VIN and GND screws: the 12V supply goes here (the board is marked 12-24V). A 100uF / 35V capacitor next to the supply is already fitted.
- White motor plug: a 4-pin XH connector in the order 2B, 2A, 1A, 1B.
- DIP switch: three small switches for MS1, MS2 and MS3.
- RST and SLP: joined on the board, nothing for you to do.
A DRV8825 in these sockets works without the V wire. An A4988 does not: the V wire is a must.
WARNING
The module fits in both directions, but only one is right. Look for the small "VIN" arrow on the board: the VMOT pin must end up there. The EN to DIR row is then on the same side as the G V S header. With the module the wrong way round, 12V reaches the wrong pins and may burn it.
The NEMA 17 and Its Two Coils
NEMA 17 is the name of the motor's front plate size. The motor on this page is bipolar: it has two separate coils, and each coil is one pair of wires. Each full step is 1.8°, and 200 of them add up to one turn. On a spool with a 5 cm core, one turn takes up about 15.7 cm of cable, so a single step is less than 1 mm of cable.

| Coil | Wire | You May Also See | Colour in the Picture | Goes to A4988 Pin |
|---|---|---|---|---|
| First | A | A+ | black | 2B |
| First | C | A-, or A with a bar | green | 2A |
| Second | B | B+ | red | 1A |
| Second | D | B-, or B with a bar | blue | 1B |
Wires A and C belong to one coil, wires B and D to the other. Your motor may have other colours, so look at its datasheet first. No datasheet? There are two easy tests:
- With a multimeter in ohms mode: go through the wires two at a time. A pair that reads a few ohms is a coil.
- With your fingers only: twist two bare wire ends together and try to turn the shaft. Harder to turn than before? Then you have found a pair.
Good to know: A and C in swapped places do no harm, the spool just winds in the other direction. A wire from each coil on 2B and 2A is worse. Then the motor only hums and trembles, and the spool stays where it is.
Two Settings Before the First Spin
Both settings live on the hardware, not in the code. Do them now, and the first test is calm.
Step Size
MS1, MS2 and MS3 choose how far one pulse moves the shaft. On the expansion board you set them with the DIP switch. A switch that is ON gives HIGH. The order is upside down, so do not trust the numbers: 3 belongs to MS1, 2 to MS2 and 1 to MS3.
| MS1 | MS2 | MS3 | DIP Switches ON | Step Size | Pulses per Turn |
|---|---|---|---|---|---|
| LOW | LOW | LOW | none | full | 200 |
| HIGH | LOW | LOW | 3 | 1/2 | 400 |
| LOW | HIGH | LOW | 2 | 1/4 | 800 |
| HIGH | HIGH | LOW | 3 and 2 | 1/8 | 1600 |
| HIGH | HIGH | HIGH | 3, 2 and 1 | 1/16 | 3200 |
Small steps make the winder quieter and smoother, but every turn needs more pulses. Start with all three switches OFF. When you change them later, change MICROSTEPS in the sketch to the same number (1, 2, 4, 8 or 16).
Current Limit
How much current may each coil take? The answer sits in the tiny trimmer of the module. You do not measure the current itself. You measure a voltage called VREF, and the rule is VREF = 8 x Rs x current. The two small resistors on the DIYables module are printed R100, so Rs is 0.1 ohm and the rule gets short: VREF = 0.8 x current.
| Current per Coil | VREF with R100 |
|---|---|
| 0.4A | 0.32V |
| 0.6A | 0.48V |
| 0.7A | 0.56V |
| 0.9A | 0.72V |
| 1A | 0.80V |
- Wire the circuit first (next sections) and plug in only the USB cable. VDD now has power, and the 12V adapter stays out.
- Read VREF with a multimeter in DC volts mode. Hold the black probe on a GND pin. The trimmer has a metal top, and the red probe touches it.
- Use a small screwdriver and move the trimmer by a hair, then read the voltage again. Keep the tip away from the parts around it.
- Begin low, for example at 0.32V. Go up only when the motor slips, and stay at or below the current printed on your motor.
Is your module from another maker? Read its two resistors first. With R050 the rule is VREF = 0.4 x current.
Good to know: a motor that stands still also gets current. For a winder that is useful, because it holds the spool in place. It also means that the motor and the driver become warm while nothing moves.
ESP32 Uno Pinout
Two signal pins are used: D4 and D3. The board has no D labels, so count from the corner where the Uno header begins. RX0, TX0, IO26, IO25 and IO17 sit in the places of D0, D1, D2, D3 and D4. The sketches use the numbers 17 and 25.

Good to know: neither GPIO17 nor GPIO25 takes part in the start of the ESP32. You can leave the driver connected during every upload.
How to Connect
Think of three small jobs: four wires to the ESP32 Uno, two wires to the 12V supply, four wires to the motor. Pick one of the two versions below. The sketches are the same for both.
With the Expansion Board
Plug the A4988 into the sockets, then follow the drawing. GND starts at the GND hole next to D13, and 3V3 comes from the power header. Any other GND hole of the board works too.

This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
Finish all the wiring before any power is on, and plug in the 12V adapter last. The four colours between the plug and the motor (brown, yellow, pink, purple) are only drawing colours. Go by the coil table above, not by the colours.
| Expansion Board | Wire It To |
|---|---|
| S pin, STEP row | D4 (GPIO17) |
| S pin, DIR row | D3 (GPIO25) |
| V pin, any row | 3V3 |
| G pin, any row | GND |
| S pin, EN row | no wire, the driver is on |
| VIN screw | DC power jack + (12V adapter) |
| GND screw | DC power jack - (12V adapter) |
The four motor wires end in the white plug:
| Motor Plug | Motor Wire | Example Colour |
|---|---|---|
| 2B | A | black |
| 2A | C | green |
| 1A | B | red |
| 1B | D | blue |
A winding motor makes everything on the table tremble, and a loose jumper wire ruins the turn count. Put a Proto Screw Terminal Block Shield or a Screw Shield V2 on the ESP32 Uno and clamp the four wires in it. You use the same four pins, as the next drawing shows.

This image is created using Fritzing. Click to enlarge image
WARNING
12V belongs on the VIN screw of the expansion board and nowhere else. The ESP32 Uno also has a hole named VIN: leave it empty. Its GPIO pins are made for 3.3V, and 12V on one of them can destroy the board. The motor plug has a rule too: leave it alone as long as 12V is on. A coil that loses its wire while current flows hits back with a high voltage, and that is how many A4988 chips die.
Without the Expansion Board
The module alone takes the same two signals. What changes: you wire the coils pin by pin, you join RST and SLP yourself, and you add a capacitor.

This image is created using Fritzing. Click to enlarge image
| A4988 Pin | Wire It To |
|---|---|
| STEP | D4 (GPIO17) |
| DIR | D3 (GPIO25) |
| VDD | 3V3 |
| GND, next to VDD | GND |
| VMOT | DC power jack + (12V adapter) |
| GND, next to VMOT | DC power jack - (12V adapter) |
| 2B | motor wire A |
| 2A | motor wire C |
| 1A | motor wire B |
| 1B | motor wire D |
| RST | its neighbour SLP (orange jumper) |
| EN, MS1, MS2, MS3 | no wire |
With a screw shield on the ESP32 Uno, the module version looks like this:

This image is created using Fritzing. Click to enlarge image
Two things are easy to forget here:
- The short wire from RST to SLP (the orange one in the drawing). RST floats, and without this wire the motor may never move.
- A 100uF capacitor across VMOT and GND. It is not in the drawing. Choose one for 35V or more, keep it close to the module and put its + leg on VMOT.
Good to know: the ESP32 Uno, the module and the adapter must share one ground. The two GND pins of the module are joined, so the GND wire of the board and the minus of the adapter meet there.
ESP32 Uno Code - One Turn On, One Turn Back
The first sketch proves the wiring and needs no library. It sends 200 pulses, which is one turn, rests 1.5 seconds, changes DIR, and sends 200 pulses the other way. One pulse lasts 4 ms: 2000 us HIGH, then 2000 us LOW. So 200 pulses take 0.8 seconds, and the spool runs at 75 RPM (turns per minute). A motor can start at that speed with no acceleration.
Upload and Test
- Board fresh out of the bag? Prepare the Arduino IDE with ESP32 Uno - Getting Started.
- Check the DIP switches: all three OFF, so MICROSTEPS is 1.
- Check four wires again: D4 to STEP, D3 to DIR, 3V3 to V (or VDD), GND to G.
- Connect the USB Type-C cable. The 12V adapter is still out, and this is the best moment to set VREF.
- Choose the board ESP32 Dev Module and the CH340 COM port in Arduino IDE.
- Paste the sketch and click Upload.
- Stick a piece of tape on the motor shaft as a pointer, then plug in the 12V adapter.
- Bring up the Serial Monitor (9600 baud) and tap the reset (EN) button, so that the log begins at its first line:
- Pro tip: watch the tape. After each turn it must point to the same spot as before. If it wanders away, the motor is losing steps.
In full-step mode the motor shakes a little and you can hear it, and that is normal. With 1/4 steps on the DIP switch and MICROSTEPS set to 4, the sketch makes the delay four times shorter. The spool keeps its speed and runs more quietly.
ESP32 Uno Code - Wind 20 Turns, Soft Start and Soft Stop
A spool with filament on it is heavy. When the pulses start at full speed, the motor cannot follow: it hums and loses steps. The second sketch uses the AccelStepper library, which raises the speed bit by bit and lowers it again before the end. One job is 20 turns. After the job, the Serial Monitor reports the turns and the time, and you have six seconds to put on an empty spool.
With a top speed of 800 steps per second (4 turns per second) and an acceleration of 320, the job has three parts:
| Part of the Job | Turns | Time | What the Spool Does |
|---|---|---|---|
| Soft start | 0 to 5 | about 2.5 s | speeds up from zero to 4 turns per second |
| Steady run | 5 to 15 | 2.5 s | keeps 4 turns per second |
| Soft stop | 15 to 20 | about 2.5 s | slows down to zero |
Upload and Test
- Unplug the 12V adapter. The USB cable stays in.
- Get the library: click the Libraries button in the left bar.
- Search for "AccelStepper". Several results have this word in them, and the right one names Mike McCauley as its author.
- Click Install. Go on when the IDE lists it as installed.
- Search for AccelStepper created by Mike McCauley
and click the Install button.
- Paste the second sketch and click Upload.
- Plug in the 12V adapter when the upload is done.
- Press the reset (EN) button with the Serial Monitor open at 9600 baud:
- Pro tip: watch the rhythm of the lines. "turn 10" and "turn 15" come 1.25 seconds apart, and "turn 20" takes about twice as long. That is the soft stop at work.
The report counts the pulses that were sent. The A4988 gets no message back from the motor, so a spool that slips still shows 20.0 turns. Put a mark on the spool and count along once, and you know whether your speed is safe.
Video Tutorial
Code Explanation
| Code Part | What It Does |
|---|---|
| #define STEP_PIN 17 | D4 on the header is GPIO17, and DIR_PIN 25 is D3 |
| STEPS_PER_TURN | 200 full steps times MICROSTEPS |
| STEP_DELAY | 2000 us divided by MICROSTEPS, so the spool turns at the same speed with every step size |
| delayMicroseconds(5) in turnSpool() | Gives DIR a moment before the first pulse |
| DRIVER in the AccelStepper line | Tells the library that a STEP and DIR driver does the coil work |
| setMinPulseWidth(3) | Keeps each pulse HIGH for at least 3 us, the A4988 needs 1 us |
| moveTo() | Sets the goal in steps, nothing moves yet |
| run() | Sends one step when it is due, so the while loop calls it all the time |
| currentPosition() | Steps sent since setCurrentPosition(0), divided by 200 it gives the turns |
| delay(CHANGE_TIME) | Allowed here, because the motor has already stopped |
Never put a delay() inside the while loop. Each pause there is a missing pulse, and the spool would jerk.
ESP32 Uno vs UNO R4 for This Project
Both boards have the Uno shape, so the same two holes are used. The voltage on V is the trap.
| Item | Arduino UNO R4 | ESP32 Uno |
|---|---|---|
| Logic level | 5V | 3.3V |
| Wire on V (VDD) | 5V | 3V3, never 5V |
| STEP wire | D4 | D4 (GPIO17) |
| DIR wire | D3 | D3 (GPIO25) |
| Numbers in the code | 4 and 3 | 17 and 25 |
| 12V side and motor | no change | no change |
If you copy a sketch from a UNO R4 page, change the two pin numbers first. On the ESP32 chip, GPIO3 is the USB serial line and GPIO4 sits on the A1 hole.
A4988 or DRV8825?
STEP and DIR work in the same way on both, and the expansion board takes either of them.
| What You Compare | DRV8825 | A4988 |
|---|---|---|
| V wire to 3V3 | can stay away | must be there |
| Finest step size | 1/32 | 1/16 |
| Amps per coil, bare | about 1.5A | about 1A |
| Amps per coil, cooled | 2.2A | 2A |
| Volts on VMOT | 8.2V to 45V | 8V to 35V |
For a small winder with a 12V adapter the A4988 is enough. Choose the DRV8825 when the motor wants more current or a higher voltage.
Is a stepper the right motor at all? When something only has to spin, a DC motor with a BTS7960 driver is simpler. When something only has to swing to an angle, look at the servo motor.
Go Wireless: Order a Spool from Your Phone
WiFi and Bluetooth are already on the ESP32 Uno. A slider on the phone can choose the number of turns, and a text window can show the report of each spool.
windSpool() keeps the board busy until the spool is done. For a phone version, give up the while loop and call stepper.run() once in every pass of loop(), so the app gets its turn as well.
Try These Next
- Choose the turns by hand: a rotary encoder sets the number, an LCD I2C shows it.
- Stop button: press a button and call stepper.stop(). The spool slows down gently and does not stop with a jerk.
- End of cable: let the cable hold down the lever of a limit switch. When the cable runs out, the lever comes up and the job ends.
- Count real turns: a slotted disc and an IR slotted optical speed sensor tell you if the spool has slipped.
- Flat layers: a second A4988 on D5 (GPIO16) and D6 (GPIO27) can move a cable guide left and right while the spool turns.
Function References
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| Log is fine, shaft is loose and silent | No 12V, or the V (VDD) wire is missing | Plug in the adapter and check the wire from V to 3V3 |
| Module alone, motor never moves | RST is not joined to SLP | Add the short wire between the two pins |
| Log is fine, motor holds still but does not step | Sketch uses 4 and 3, or STEP is in the wrong hole | Use 17 and 25 in the code, STEP on D4, DIR on D3 |
| Motor hums or shakes | Wires of two coils are mixed | Find the pairs again, one pair on 2B and 2A, the other on 1A and 1B |
| Motor slips when the spool is heavy | Current too low, or the start is too quick | Raise VREF a little, then try ACCELERATION 160 |
| Spool turns the wrong way | The two wires of one coil are swapped | Swap 2A with 2B, with the power off |
| 20 turns in the report, 5 turns on the spool | DIP switch is on 1/4 but MICROSTEPS is 1 | Set both to the same step size |
| Driver too hot to touch | Too much current for a bare chip | Turn VREF down, fit the heat sink, leave the box open |
| Steps get lost at random | V is on 5V, or the GND wire is loose | Move V to 3V3 and push the GND wire in firmly |
| AccelStepper.h not found | Library not installed | Install AccelStepper by Mike McCauley |
| No COM port in the IDE | The PC does not know the CH340 chip, or the cable has no data lines | Install the CH340 driver, then try another USB-C cable |
| Strange signs before the first line | The ESP32 reports its own start at 115200 baud | No problem, read on from the first clear line |
FAQ
Why 3.3V and not 5V on the V pin?
With 5V on VDD, the A4988 takes a signal as HIGH only above 3.5V. The ESP32 Uno sends 3.3V, so it could miss pulses. With 3.3V on VDD the border is 2.31V, and every pulse is clear.
Does the 3V3 pin power the motor?
No. It only feeds the logic of the chip. The motor current comes from the 12V adapter through VMOT.
Can I use a 24V adapter?
Yes. The A4988 accepts 8V to 35V on VMOT, and the expansion board is marked 12-24V. The ESP32 Uno side stays the same, and the current limit still comes from VREF.
Why is the motor warm when the spool stands still?
The driver keeps current in the coils to hold the shaft. To let go, wire EN to a free pin, for example D5 (GPIO16), and set it HIGH. The spool then turns freely, so tie down the cable end first.
How much cable is on the spool after 20 turns?
Multiply the turns by the way around the core. A 5 cm core gives 15.7 cm per turn, so 20 turns in one layer are about 3.1 m. Each new layer is a little longer, because the spool grows.
Can I wind faster?
Raise MAX_SPEED in small steps, for example 800, 900, 1000, and test with your real spool. At some speed the motor begins to slip. Go back to the last good value and leave some reserve.
What changes in the second sketch with microsteps?
Set MICROSTEPS to match the DIP switch. With 1/4 steps the same 800 pulses per second give only one turn per second, so use MAX_SPEED 3200 and ACCELERATION 1280 to keep the old pace.
Can I use other pins for STEP and DIR?
Yes. D2 (GPIO26), D5 (GPIO16), D6 (GPIO27), D9 (GPIO13) and D11 to D13 (GPIO23, 19, 18) work as outputs. Do not take A2 to A5, because they are input only, or D0 and D1, which carry the USB serial. Skip D8 (GPIO12), D10 (GPIO5) and A0 (GPIO2) as well: they are boot strapping pins. D7 (GPIO14) sends out a signal while the ESP32 starts, and the motor could twitch.
Does WiFi disturb the DIR pin on GPIO25?
No. GPIO25 shares a part with WiFi only when you use it as an analog input. Here it is a digital output.
Can one ESP32 Uno drive two steppers?
Yes. Each motor needs an A4988 of its own, two free output pins and its own AccelStepper object in the code. Call run() for both objects all the time.