ESP32 S3 - Stepper Motor A4988 Driver
Point a camera at the night sky, keep the shutter open for a minute, and every star becomes a short line. The sky did not jump. The Earth turned, and the camera turned with it. A barn door tracker solves this with two small boards and a hinge between them: a threaded rod pushes the boards apart, very slowly, and the camera on the upper board keeps looking at the same stars. What the rod needs is a calm motor. In this guide the ESP32 S3 drives a NEMA 17 stepper motor through a DIYables A4988 module. It turns the rod once per minute during the photo and winds it back quickly afterwards. For all the tests here, a bare motor on your desk is enough.
What you'll build in this tutorial:
- An A4988 module that is ready for work: 3.3V on VDD, a safe coil current, and the step size that fits your project
- A circuit with STEP on GPIO1, DIR on GPIO2, 3V3 and GND, plus a 12V adapter for the motor, once on an expansion board and once on the bare module
- A short test sketch, written with plain Arduino functions, that turns the rod once each way
- A tracker sketch with AccelStepper: slow 1/16 steps during the shot, then a rewind that speeds up and slows down softly

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables ESP32 S3 Starter Kit (ESP32 S3 included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
The expansion board is optional. In its place, the bare module asks for a 100uF capacitor and one more jumper, and the wiring part explains both.
Overview of A4988 Stepper Motor Driver

A GPIO pin is strong enough for a signal, not for a motor coil. So the work is shared. The ESP32 S3 says "one step now" and "this way", and the A4988 sends the real current into the coils. DIYables builds the chip onto a red board that measures about 20 x 15 mm. Makers know this shape under the name "StepStick". Its two rows of 8 pins need no soldering, and the package brings a small heat sink that sticks to the chip. Each module takes care of exactly one bipolar stepper motor with four wires. Does your motor have six? Four of them are enough, and the other two stay loose.
Key Specifications
The motor side accepts 8V to 35V DC, the logic side 3V to 5.5V. Expect about 1A per coil from a bare chip, and up to 2A once the heat sink is on and the air can carry its warmth away.
| Item | On this module |
|---|---|
| Motors | 1 bipolar stepper motor |
| Motor power on VMOT | 8-35V DC, here from a 12V adapter |
| Logic power on VDD | 3-5.5V, here from the 3V3 pin |
| Coil current | about 1A, up to 2A with good cooling |
| Step sizes | five of them, full step down to 1/16 step |
| STEP pulse | HIGH for 1 microsecond or more, LOW for 1 microsecond or more |
| Protection | shuts down when too hot or when the voltage is too low, guards against crossover current |
| Error output | none (there is no FAULT pin) |
A4988 Pinout
Lay the module on the table with EN at the top left. Read the left row from top to bottom, then the right row:
- EN — on/off switch of the motor outputs; LOW or no wire means on, HIGH lets the shaft turn freely (the module itself holds this pin LOW)
- MS1, MS2, MS3 — the three step size inputs; each one is LOW until you wire it
- RST — reset, acts at LOW; it floats, which means nothing on the module decides its level, so it has to be joined to SLP
- SLP — sleep, acts at LOW; the module pulls it up
- STEP — one move each time it goes from LOW to HIGH
- DIR — its level chooses the turning direction
- VMOT — plus of the motor supply
- GND (under VMOT) — return line of the motor supply
- 2B, 2A — output pair for one coil of the motor
- 1A, 1B — output pair for the coil that is left
- VDD — plus of the logic supply
- GND (under VDD) — logic ground; a track on the module links it with the GND above
You may search in vain for "2B" on the upper face of the real board. It says B2, A2, A1, B1 there, and 2B, 2A, 1A, 1B on the lower face. The pins are the same.
What One Pulse Does
A stepper motor moves when its coils get current in the right order, and the A4988 knows this order by heart. Its translator (so the block is named) holds the coil pattern of each step. A rising edge on STEP makes it go one pattern further. Your sketch only has to make edges and count them.
There is a second helper inside. When the current in a coil climbs to the limit, the chip cuts it for an instant, lets it climb again, and so on. This is named current chopping. Because of it, a 12V supply does not burn a motor that is rated for 2V to 4V.
VDD Goes to 3V3
The A4988 cannot make a logic voltage from the 12V, so VDD must get its own wire. VDD also decides which pulses count. A pulse is HIGH for the chip only when it rises over 0.7 x VDD. A GPIO of the ESP32 S3 reaches 3.3V. Let us compare the two supplies. With 3.3V on VDD, the chip wants 2.31V, and the GPIO beats that with ease. With 5V on VDD, it wants 3.5V, and 3.3V is too low for that, so pulses may be missed. The rule for this board is simple: VDD (or V on the expansion board) belongs on 3V3 and never on 5Vin.
Step Size and the Three DIP Switches
Picture the tracker in full steps. The rod makes 200 moves in its minute, one small kick every 0.3 seconds, and a long lens can show that as a blurred star. In 1/16 steps, the same minute holds 3200 tiny moves. The motor is smoother and quieter, but each turn costs more pulses. The expansion board has three small switches for this. ON gives HIGH, OFF gives LOW, and the numbering goes backward: look for MS1 at switch 3 and for MS3 at switch 1.
| Step size | MS1 (switch 3) | MS2 (switch 2) | MS3 (switch 1) | Pulses for 1 rod turn | Pulses per second at 1 turn per minute |
|---|---|---|---|---|---|
| full | OFF | OFF | OFF | 200 | 3.3 |
| 1/2 | ON | OFF | OFF | 400 | 6.7 |
| 1/4 | OFF | ON | OFF | 800 | 13.3 |
| 1/8 | ON | ON | OFF | 1600 | 26.7 |
| 1/16 | ON | ON | ON | 3200 | 53.3 |
For 1/16 you simply push all three switches to ON. On the bare module, a jumper from an MS pin to 3V3 does the job of an ON switch. The ESP32 S3 cannot read these switches. So each time you move them, write the same step size into MICROSTEPS in the sketch.
Set the Current Limit
A small screw on the module, the trimmer, sets the highest current that a coil may get. You check it with a multimeter, because the trimmer voltage (called VREF) tells you the limit: current = VREF / (8 x Rs). To know Rs, look at the two tiny sense resistors. The print R100 on the DIYables module stands for 0.1 ohm, so all you need is VREF = 0.8 x current. Boards from other makers can carry R050. For those, calculate VREF = 0.4 x current.
| Current you want | VREF with R100 | VREF with R050 |
|---|---|---|
| 0.4A | 0.32V | 0.16V |
| 0.7A | 0.56V | 0.28V |
| 1A | 0.80V | 0.40V |
- Keep the 12V adapter away for now. USB power is fine, because VDD only needs the 3V3 pin.
- Choose a DC voltage range on the multimeter. Hold one probe on GND and touch the metal top of the trimmer with the other.
- Give the trimmer a tiny turn with a small screwdriver, then look at the display again. Do not let the tip slide onto the parts around it.
- Start with a low value. Go up only if the motor loses steps, and stay below the current that the motor is made for.
Remember one thing about trackers: between two photos the rod waits, but the coils still get their holding current. So expect both the motor and the driver to get warm while nothing turns.
A4988 or DRV8825?
The two modules look like twins. STEP and DIR work alike, and the expansion board has one pair of sockets for either of them. Only the numbers tell them apart. A DRV8825 runs its motor from 8.2V to 45V, gives a coil about 1.5A or 2.2A when cooled, goes down to 1/32 step and does not need the logic supply wire. The A4988 stays between 8V and 35V, gives about 1A or 2A when cooled, ends at 1/16 step and does need that wire. A slow tracker with a light load is an easy task for both. If you want to try the other one, read ESP32 S3 - DRV8825 Stepper Motor Driver. It uses other GPIO numbers than this page, so correct the two pin lines in the sketch when you swap the modules.
Overview of Stepper Motor
Our NEMA 17 is a bipolar motor. It has two coils inside. A coil has one wire at its start and one at its end, so each coil is a pair, and four wires leave the case. A full step moves the shaft by 1.8 degrees, and after 200 of them it has come full circle.

| Colour on our motor | Wire | Other names | Belongs to |
|---|---|---|---|
| black | A | A+ / A | coil A-C |
| green | C | A- / A with a bar | coil A-C |
| red | B | B+ / B | coil B-D |
| blue | D | B- / B with a bar | coil B-D |
Each maker picks its own colours, so trust the datasheet more than any table. If you have none, a multimeter sorts the wires: where it reads a few ohms, you hold both ends of one coil. You can also do it by hand. Let two bare wire ends touch and twist the shaft with your fingers; when it turns harder than before, you have found a pair. A pair that is connected the other way round only changes the direction. Pairs that are mixed up give you a motor that hums and stays where it is.
Wiring Diagram
GPIO1 and GPIO2 share one header row of the ESP32 S3, side by side and close to a GND pin, and 3V3 is on the row across. The two are ordinary pins with no strapping, USB, PSRAM or serial duty, which makes them a good home for STEP and DIR.

This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
- An A4988 that sits backwards can be destroyed, so look twice. Its EN ... DIR edge belongs near the G V S pins, and its VMOT corner near the small arrow marked "VIN".
- Brown, yellow, pink and purple were chosen for the motor wires only to keep the picture clear. Follow the letters of your own motor.
| From | To the expansion board |
|---|---|
| GPIO1 | STEP row, S pin |
| GPIO2 | DIR row, S pin |
| 3V3 | V pin, any row (inside the board they are linked) |
| GND | G pin, any row (linked as well) |
| plus of the DC power jack | VIN screw terminal |
| minus of the DC power jack | GND screw terminal, below VIN |
| nothing | EN row, S pin (the driver is on) |
Pay attention to the V wire. With a DRV8825 in the sockets you could leave it out. With an A4988 you cannot, because nothing else feeds VDD. The motor has its own white plug on the board, with 2B at the top:
| Plug pin | Motor wire | Colour on our motor |
|---|---|---|
| 2B | A | black |
| 2A | C | green |
| 1A | B | red |
| 1B | D | blue |
A tracker is carried outside, set up in the dark and bumped now and then. Plug-in wires do not like that. Seat the ESP32 S3 in a Screw Terminal Block for ESP32 S3 and clamp all four wires:

This image is created using Fritzing. Click to enlarge image
Or keep the jumper wires and give them better labels. On a GPIO Breakout Board for ESP32 S3, every GPIO number is printed beside its pin, which helps you by the light of a small red torch:

This image is created using Fritzing. Click to enlarge image
Without the Expansion Board
The bare module uses the same two GPIO pins. Only the other ends of the wires move to the module itself:

This image is created using Fritzing. Click to enlarge image
With the ESP32 S3 in the screw terminal block, it becomes this:

This image is created using Fritzing. Click to enlarge image
And this is the breakout board version:

This image is created using Fritzing. Click to enlarge image
| A4988 pin | Other end of the wire |
|---|---|
| STEP | GPIO1 |
| DIR | GPIO2 |
| VDD | 3V3 |
| GND beside VDD | any ESP32 S3 GND |
| VMOT | plus of the DC power jack |
| GND beside VMOT | minus of the DC power jack |
| 2B | motor wire A |
| 2A | motor wire C |
| 1A | motor wire B |
| 1B | motor wire D |
| RST | SLP, with a short jumper (orange in the drawing) |
| EN, MS1, MS2, MS3 | open (driver on, full step) |
※ NOTE THAT:
- The RST-SLP jumper is a must here. If it is missing, the shaft never turns.
- Add one part that the drawing does not show: a capacitor of 100uF, close to the module. Choose one for 35V or more. Its + leg meets VMOT, the other leg the GND below. The expansion board has one already.
Safety Notes
Finish every wire first and leave the plug of the 12V adapter for last. While the adapter is on, do not connect or disconnect the motor: the coil kicks back with a high voltage, a spike, and can destroy the A4988 in an instant. The 12V wire ends at VIN (expansion board) or at VMOT (bare module) and touches no pin of the ESP32 S3. All grounds meet. The ESP32 S3, the module and the adapter minus share one line, otherwise the chip cannot tell HIGH from LOW. And let the driver cool for a moment before you touch its heat sink.
How To Program For A4988 Stepper Motor Driver
Making a step by hand is easy. STEP goes HIGH, the sketch waits, STEP goes LOW, and the sketch waits again. The function turnRod() of the first sketch sets DIR and then repeats this for each step. One pulse takes 2 x 2000 microseconds. This makes 250 steps per second or, in full steps, 75 RPM, and a NEMA 17 can jump to that speed from standstill.
The second sketch gives the pulses to the AccelStepper library. runSpeed() makes the even pace of the tracking, where the gap between two pulses never changes. For the way back, moveTo() sets the target, and run() makes the motor faster step by step and slower again near the end. Both functions send at most one pulse per call, so loop() has to come back to them quickly, and no delay() may run while the motor is turning.
ESP32 S3 Code - A4988 Stepper Motor Driver
This sketch is a check of the wiring. The rod goes one turn out, rests, comes one turn back and rests.
Detailed Instructions
- New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
- Choose full step: Push all three DIP switches to OFF. On the bare module, leave MS1, MS2 and MS3 open.
- Wire the logic side: Put in the STEP, DIR, 3V3 and GND wires, then set VREF over USB power as described above.
- Wire the power side: Pull out the USB cable. Connect the four motor wires and the DC power jack. The 12V adapter is still unplugged.
- Mark the shaft: Fold a strip of tape around it as a flag, because a bare turning shaft is hard to see.
- Upload: Plug the USB cable in again, choose ESP32S3 Dev Module and your COM port under Tools, and upload the sketch from the Arduino IDE.
- Switch on the motor power: Plug in the 12V adapter now.
- Read along: Start the Serial Monitor at 9600 baud with timestamps on, and compare each line with the flag.
- Pro Tip: Set MICROSTEPS to 16, push the three switches to ON, and upload again. It is still one turn, but it needs 3200 pulses and takes about 13 seconds.
A new line appears every 2.6 seconds: 0.8 seconds of turning (200 pulses x 4 ms) and 1.8 seconds of rest. Look at the flag during the rest. It should stop at the same place after each turn. During the rest, also try to move the shaft with two fingers. It resists, and that is the holding current at work.
ESP32 S3 Code - Star Tracker with AccelStepper
Why one turn per minute? Seen from the ground, the sky moves by about 0.25 degrees in a minute. An M6 threaded rod moves 1 mm per turn. When the rod is about 229 mm away from the hinge, 1 mm opens the boards by just these 0.25 degrees. For another rod or another distance, change TRACK_RPM. The sketch tracks for one turn, waits, rewinds and starts over.
Quick Steps for the Tracker
- Choose 1/16 step: With the 12V off, slide all three DIP switches to ON. The bare module needs HIGH (3.3V, the same as VDD) on MS1, MS2 and MS3. If you do not want these three extra wires, leave the pins open and set MICROSTEPS to 1. The tracker still works, only with bigger steps.
- Open the Library Manager: In the Arduino IDE, the icon with the books at the left edge shows the list of libraries.
- Install AccelStepper: Search for AccelStepper, look for the entry by Mike McCauley and press Install.
- Search for AccelStepper created by Mike McCauley
and click the Install button.
- Upload: Put the code above into a new sketch and press Upload.
- Motor power on: Plug the 12V adapter in again.
- Be patient: During the first minute, the flag goes round only once. You hear almost nothing.
- Watch the way back: The rewind needs only about 4 seconds. It starts gently and ends gently.
- Pro Tip: For a real photo, set TRACK_TURNS to the number of minutes you need, and start the camera two or three seconds after the rod begins to move.
The four progress lines should come 15 seconds apart, and 4 x 15 seconds is the full minute. Is your gap shorter or longer than that? Then compare TRACK_RPM with the value in the code above. Is the gap right, but the flag does more or less than one round? Then the DIP switches do not say 1/16. In the rewind, the speed climbs to 1200 pulses per second (22.5 turns per minute) and falls again before position 0.
Troubleshooting
The motor is silent and the shaft is loose.
The driver sleeps or has no logic power. On the bare module, look for the jumper from RST to SLP and for the VDD wire. On the expansion board, look for the V wire. Is the 12V adapter plugged in?
The motor hums or trembles and stays in its place.
Most often one wire of each coil has changed places with the other coil. Find the two pairs again with a multimeter. Are the pairs fine? Then give the coils a little more current with VREF. If only the rewind fails, it is too fast for your motor: lower REWIND_SPEED and REWIND_ACCEL.
The tracker follows the wrong way and the stars get longer.
Switch the 12V off, let the 2B and 2A wires trade places, and leave the other coil as it is. Software works as well: add rod.setPinsInverted(true, false, false); to setup() of the tracker sketch, and the library turns DIR around.
You cannot keep a finger on the heat sink.
The current limit is too high for this cooling. Turn VREF down and do not close the tracker box too tightly. If the heat sink is still in its bag, use it. An A4988 that overheats switches itself off, and a tracker that pauses like this loses the stars.
One turn in the sketch is not one turn of the rod.
MICROSTEPS and the DIP switches do not match. Remember the order, with MS1 at switch 3. Sixteen rounds in place of one means that the code says 16 and all switches are OFF.
Application and Project Ideas
A motor that counts its own steps can move more than a camera board.
- Moon time-lapse: Take one photo at the end of every fifth turn and let the ESP32 S3 press the shutter through a relay.
- Telescope focuser: Turn the focus knob by a few 1/16 steps, so your hand does not shake the telescope.
- Slow turntable: Show a model or a watch from all sides, with one very smooth round per minute.
- Panorama head: Rotate a camera by the same angle between shots and stitch the photos later.
- Sun follower for a plant: Turn a pot a little each hour, so all its leaves get light.
Challenge Yourself
- Beginner: Change TRACK_RPM to 2.0 and predict the time between two progress lines before you upload.
- Intermediate: Connect a button and start the tracking only when it is pressed.
- Advanced: Mount a limit switch at the closed position of the boards, and let the rod search for it at power-up, so position 0 is always the same point.
Video Tutorial
The video for this star tracker motor will be added here later.