Arduino Nano 33 IoT - Stepper Motor A4988 Driver
Put a small solar panel on the window sill. If it never moves, the sun shines straight on it for only a short part of the day. If it turns a little toward the west every hour, it looks at the sun from morning to evening. This tutorial instructs you how to use Arduino Nano 33 IoT and an A4988 stepper motor driver to make a model of such a panel. A NEMA 17 motor carries the panel on its shaft, and a whole day passes in one minute on your desk. In detail, we will learn:
- Where every wire of the A4988 goes: to the board, to the adapter, to the motor or just to the pin next door
- Why VDD goes to the 3V3 pin of this board, and why the 5V (VUSB) pin is the wrong place for it
- How steps become degrees, how to make a step smaller, and how much current the motor should get
- How to wire it in four ways: carrier board or bare module, jumper wires or screw terminals
- How to write a first sketch without any library, and then a one-minute day: 12 small moves to the west and one smooth move back to the east

We suggest:
- Trying the Arduino Nano 33 IoT - Servo Motor tutorial if you want a toy-size panel. A servo needs no driver module, but it cannot make full turns.
- Going to the Arduino Nano 33 IoT - 28BYJ-48 Stepper Motor ULN2003 Driver tutorial if five wires come out of your stepper motor. That type has a driver of its own.
Hardware Preparation
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 .
One line above is optional: the expansion board. To go without it, have one more short wire and a 100uF capacitor ready. The panel can be a piece of cardboard taped to the motor shaft. Draw an arrow on it, so you can see where it looks.
Overview of the A4988 Driver and Its Pinout

The DIYables module is red and tiny, its sides measure about 20 and 15 mm. Boards of this shape are called StepStick, and many sockets are made for them. All 2 x 8 pins are soldered when you get it, and a small heat sink comes along. Stick it on the A4988 chip in the center. Give it a single bipolar stepper motor, the type with four wires. It also accepts a 6-wire motor when two of the six wires stay unused.
| A4988 Module | |
|---|---|
| Can drive | one bipolar stepper motor |
| Power for the motor | 8V to 35V DC on VMOT (12V here) |
| Power for the logic | 3V to 5.5V on VDD (3.3V here) |
| Current per coil | about 1A, or 2A at most when the heat sink keeps the chip really cool |
| Step | a full one, or the 2nd, 4th, 8th or 16th part of it |
| Pulse on STEP | 1 microsecond HIGH and 1 microsecond LOW, or longer |
| Safety features | goes off when it overheats, stays locked at too little voltage, blocks crossover current |
| FAULT output | does not exist on this chip |
In the table, the lines to the Arduino Nano 33 IoT come first. The adapter, the motor and two pins that meet each other follow:
| Pin | Must be connected to | Why |
|---|---|---|
| STEP | Nano 33 IoT, D4 | brings the pulses. The motor makes its step when the level jumps from LOW to HIGH |
| DIR | Nano 33 IoT, D3 | says which way the panel turns |
| VDD | Nano 33 IoT, 3V3 | keeps the logic part alive |
| GND (close to VDD) | Nano 33 IoT, any GND | ground for the three lines above |
| VMOT | 12V adapter, plus (+) | feeds the motor |
| GND (close to VMOT) | 12V adapter, minus (-) | ground of the motor power. A track on the module leads from here to the other GND |
| 2B and 2A | motor, one pair of wires | current for coil 2 |
| 1A and 1B | motor, the second pair of wires | current for coil 1 |
| RST | SLP | reset input. LOW stops the driver. No part of the module sets its level, so a free RST pin floats |
| SLP | RST | sleep input. LOW means sleep. This pin has a pull-up, and through the link RST is HIGH too |
The last four pins have no wire in this project:
- MS1, MS2 and MS3 pins: they choose how big a step is. Free means LOW, and three times LOW is a full step.
- EN pin: LOW means that the motor gets current, and the module holds this LOW by itself. A HIGH cuts the current, and your hand can turn the panel.
※ NOTE THAT:
Your eyes are fine: the coil pins really have two spellings. The chip side of the board prints B2, A2, A1, B1. Its back prints 2B, 2A, 1A, 1B. There are only four coil pins, not eight. A module from another shop can have its own labels, so always read the print before you wire it.
How STEP and DIR Move the Panel
To turn a stepper motor, somebody has to switch the current in its two coils in the right order. In this project, it is not your sketch. A block in the A4988 with the name "translator" keeps the coil pattern for every step. The Arduino Nano 33 IoT just tells it when (a pulse on STEP) and which way (the level on DIR).
The chip does one more thing. It measures the coil current all the time and interrupts it for a moment when it gets as high as your limit. People call this chopping. A motor made for 2V to 4V can therefore work from a 12V adapter: the voltage is higher, but the current never gets too big.
VDD Belongs to 3V3
The 12V on VMOT is for the coils and for nothing else. The brain of the A4988 has no supply until a second wire brings one to VDD. Which voltage is right? VDD is also the ruler for STEP and DIR: a level of more than 0.7 x VDD is a HIGH without any doubt. Let us try both power pins of the board:
- 3V3 pin: 0.7 x 3.3V = 2.3V. A HIGH from D4 or D3 is 3.3V, that is a full volt more. Good.
- 5V pin: 0.7 x 5V = 3.5V. Now 3.3V is too little. The panel may lose steps, or not move at all.
There is more against the 5V pin. On the Arduino Nano 33 IoT it is VUSB: it gives no voltage before you close a solder jumper on the bottom of the board. And the pins of this board are not 5V tolerant. With 5V on the V pins of a header, one wire in the wrong hole would be enough to hurt D4 or D3. Maybe you closed that jumper for the Arduino Nano 33 IoT - BTS7960 Motor Driver tutorial. That module wants 5V, the A4988 on this page does not.
How Much Current for the Motor
The small trimmer on the module decides the highest current for each coil. You set it by looking at a voltage, VREF, because a voltage is easy to measure. The math is limit = VREF / (8 x Rs). Rs is printed on the module, you only have to find it: the text R100 on two tiny resistors stands for 0.1 ohm. With this value, which is the one on the DIYables module, only VREF = 0.8 x limit is left of the math:
| Each coil gets up to | VREF on the meter | Fine for |
|---|---|---|
| 0.35A | 0.28V | a piece of cardboard |
| 0.65A | 0.52V | a real mini panel |
| 0.9A | 0.72V | a heavier panel, use the heat sink |
Do it like this:
- Leave the 12V adapter out. Only the 3V3 and GND wires of the module and the USB cable of the board are needed, because VREF asks for power on VDD, not on VMOT.
- Choose DC volts on a multimeter. Black goes to GND. Red goes to the trimmer, whose shiny top is the measuring point.
- Turn the trimmer with a small screwdriver, not more than one tick of a clock hand, then look at the number. Nothing else may come in contact with the metal tip.
- Stop at a low value. Later, if the panel skips steps, come back and give a bit more, but never more than your motor is rated for.
Modules with R050 resistors follow another rule, VREF = 0.4 x limit.
Between two moves the panel only waits, but its coils still get current, the holding current. It is the hand that holds the panel against a breeze. It is also a little heater, and it is normal that you can feel the warmth on the motor and on the driver. Too hot to touch is a reason to lower VREF.
The Stepper Motor and the Path of the Sun
The motor is a bipolar one, NEMA 17 in size. Two coils sit inside it. A coil has a beginning and an end, so one coil = one pair of wires, and the cable has four wires. The shaft does not run on and on like the one of a DC motor. It goes from one resting place to the next, and these places are 1.8 degrees apart. 360 / 1.8 = 200, so a full turn has 200 steps.
Now the sun. Seen from the earth, it moves on by about 15 degrees in one hour. What does that mean in steps?
- One hour: 15 / 1.8 = 8.3 steps. We round it to 8 steps, which is 8 x 1.8 = 14.4 degrees.
- From 6 o'clock to 18 o'clock: 12 hours x 8 steps = 96 steps, which is 172.8 degrees. That is almost half a turn, from east over south to west.
South of the equator, the sun passes in the north, but the numbers are the same.
Smaller Steps with MS1, MS2 and MS3
Eight full steps look like eight little jerks. The A4988 can cut each of them into microsteps, and the panel moves more softly and makes less noise:
| Step | MS1 (no. 3) | MS2 (no. 2) | MS3 (no. 1) | For one hour of sun | For a full turn |
|---|---|---|---|---|---|
| full | LOW | LOW | LOW | 8 | 200 |
| 1/2 | HIGH | LOW | LOW | 16 | 400 |
| 1/4 | LOW | HIGH | LOW | 32 | 800 |
| 1/8 | HIGH | HIGH | LOW | 64 | 1600 |
| 1/16 | HIGH | HIGH | HIGH | 128 | 3200 |
The last two columns are the steps. The numbers in the first row belong to the DIP block on the expansion board, where ON is HIGH. Look twice, the order is upside down: 3 stands for MS1, 2 for MS2 and 1 for MS3. A bare module has no switches, and there you make an MS pin HIGH with a wire to VDD.
Smaller steps have a price: it takes more pulses to reach the same place. A sketch cannot see the switches, so you have to tell it: MICROSTEPS = 4 goes with 1/4, for example. Here we keep all switches OFF and MICROSTEPS at 1.
Wiring Diagram
The Arduino Nano 33 IoT gives four wires: two signals, 3V3 and GND. The 12V of the adapter never goes to the board, not even to its VIN pin. Only the driver gets 12V.
Wiring with the Expansion Board
The A4988 sits in two 8-pin sockets of a square carrier, 42 mm on each side. The carrier leads the pins of the module to a header, a screw terminal, a motor socket and three switches:

This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
- The A4988 also fits the wrong way round, so compare it with the picture. Its EN ... DIR side looks to the G V S header on the left, and VMOT sits at the small arrow with the text "VIN". Turned around, the 12V arrives at the wrong pins and can destroy the module.
- The DIP switches are all at OFF.
- A DRV8825 on this board works without a wire on V. An A4988 does not, so do not leave it out.
| Pin on the G V S header | Arduino Nano 33 IoT |
|---|---|
| S, row STEP | D4 |
| S, row DIR | D3 |
| V, row EN | 3V3 |
| G, row DIR | GND (any GND pin) |
| S, row EN | free, so the driver is always on |
The letters mean ground (G), logic supply (V) and signal (S). A track connects the G pins with each other, another track does the same for the V pins. One black wire and one red wire are therefore enough, and it does not matter in which rows they sit. (The drawing has V in the EN row and G in the DIR row.)
The adapter plugs into the DC power jack. The + screw of the jack goes to VIN and the - screw goes to GND on the green terminal, where the print says 12-24V. Be careful with the name: the Arduino Nano 33 IoT has a VIN pin as well, and this one stays empty. The carrier also has a capacitor (100uF / 35V) on the 12V line, and RST is already tied to SLP. The G pins and the GND terminal are one net, so the Arduino Nano 33 IoT, the driver and the adapter have the same ground.
A panel travels from the desk to the window and back, and on such a trip a jumper wire falls out easily. Screws do not let go. A Screw Terminal Expansion Board for Arduino Nano has one for every pin: the Arduino Nano 33 IoT sits in the middle, and the wires go to the screws D4, D3, 3V3 and GND, the same pins as before:

This image is created using Fritzing. Click to enlarge image
Wiring table between the driver and the motor
The motor cable has its own white connector with 4 pins on the expansion board. From top to bottom, it is coil 2, coil 2, coil 1, coil 1:
| Driver pin | Goes to this motor wire |
|---|---|
| 2B (coil 2) | black, its name is A or A+ |
| 2A (coil 2) | green, its name is C, A- or A with a bar |
| 1A (coil 1) | red, its name is B or B+ |
| 1B (coil 1) | blue, its name is D, B- or B with a bar |

The colors in the table and in this picture belong to our motor. Another maker may choose other ones, so the first place to look is the datasheet of your motor. The motor lines of the wiring diagrams are no help here, because purple, pink, yellow and brown were chosen for the drawing only. If you have no datasheet, unplug the motor and do a small test:
- With a multimeter (resistance range): hold the probes on two motor wires. Some ohms on the display mean that you have both ends of one coil. No value means two different coils.
- Without a multimeter: short two of the wires (metal on metal) and feel the shaft. If it has become stiff compared with before, you have shorted a coil, and these two are its ends.
Inside a coil you are free: exchange its two wires, and the panel just moves the other way, against the sun. Between the coils you are not: with a wire of coil 1 in the place of a wire of coil 2, the motor only trembles and hums.
※ NOTE THAT:
First the wires, then the 12V. And when the 12V is there, keep your hands off the motor plug. A coil answers every loose contact with a voltage spike, and such a spike can be the last thing the A4988 sees.
Wiring with the Module Alone
Here the A4988 sits without its carrier, and each wire goes straight to a pin of the module:

This image is created using Fritzing. Click to enlarge image
For a fixed build, the same module connects to the screw terminals like this:

This image is created using Fritzing. Click to enlarge image
| A4988 Module | 12V Side / Motor / Arduino Nano 33 IoT |
|---|---|
| VMOT | DC power jack, plus screw |
| GND below VMOT | DC power jack, minus screw |
| 2B, 2A | coil 2 (A, C) |
| 1A, 1B | coil 1 (B, D) |
| VDD | 3V3, never 5V |
| GND below VDD | GND (the two drawings use different GND pins, both are right) |
| STEP | D4 |
| DIR | D3 |
| RST + SLP | a short wire of their own (orange) |
| EN and the three MS pins | nothing |
The ground of the board and the ground of the adapter meet inside the module, so no extra wire is needed between them.
※ NOTE THAT:
The carrier board is gone, and with it two parts that you have to replace:
- Its track from RST to SLP. A short wire does it, look for the orange line. A floating RST means a panel that does not go anywhere.
- Its capacitor: 100uF, best rated for 35V or higher. It belongs right beside the module, the + leg to VMOT and the - leg to the ground pin below. You do not see it in the drawing, but do not skip it.
How To Program For A4988 Stepper Motor Driver
For the first sketch, digitalWrite() and delayMicroseconds() do the whole work.
- The first step is to define what never changes, that is the two pins, the step size and the two directions:
- In setup(), both pins become outputs, and STEP waits at LOW:
- Before a turn, the direction goes to DIR, followed by a tiny break:
- A single step looks like this. The two waits set the pace, and longer waits give a slower shaft:
- A full turn is this pulse, STEPS_PER_TURN times in a row.
In the second sketch, the panel has to start and stop softly, so the pause between two pulses changes all the time. The AccelStepper library works that out:
- Include the library, and create a stepper object of the DRIVER type (one STEP pin, one DIR pin):
- Specify in setup() how long STEP stays HIGH, how fast the panel may go and how quickly it may change its speed:
- To send the panel somewhere, name the target in steps, counted from the place at power-on (the east):
- MoveTo() only notes the target. The moving is done by run(), and every call of it makes one step or none. So it stands at the top of loop(), and no delay() may stop the loop:
- DistanceToGo() tells how many steps are left. 0 means that the panel has arrived:
Arduino Nano 33 IoT Code for A4988 Stepper Motor Driver
Here is a short test, still without sun and panel. The shaft goes round once with DIR at HIGH (we call it west), takes a break of 1.8 seconds, goes round once with DIR at LOW (east) and takes a break again. With 250 pulses in a second, it needs 0.8 seconds for the 200 steps. That would be 75 turns in a minute, and the motor can jump to this speed without a ramp. Later, with smaller steps, a turn simply takes longer, because the pulse keeps its length.
Detailed Instructions
Are you using the Arduino Nano 33 IoT for the first time? The Getting Started with Arduino Nano 33 IoT tutorial prepares the Arduino IDE for it.
- Wire the components as shown in the diagram. The 12V adapter lies beside the socket for now.
- Connect the Arduino Nano 33 IoT board to your computer using a USB cable.
- Adjust VREF now, while the motor has no power.
- Open Arduino IDE on your computer.
- Select the Arduino Nano 33 IoT board and its COM port.
- Copy the code above, paste it into the Arduino IDE and click the Upload button.
- After the upload, give the motor its 12V.
- Set the Serial Monitor to 9600 baud, and watch the text and the cardboard arrow together:
Each line starts together with a turn and gets its end when the turn is complete. At the end of any line, the arrow has to be where it was at the beginning. The step number is only what the board has sent: it counts on even if the motor has no 12V.
Arduino Nano 33 IoT Code for a Solar Panel That Goes with the Sun
This sketch is the one-minute day. It has three phases:
- Day: every 5 seconds one hour is over, and the panel makes a small move of 8 steps to the west. Twelve hours take 60 seconds.
- Return: 5 seconds after the last move, the panel goes back to the east, 96 steps in one go.
- Night: the panel waits 7 seconds in the east. Then a new day starts.
The speed limit is only 120 steps per second, because a panel is wide and heavy at its edges. It must not be thrown around.
Detailed Instructions
- No new wiring is needed, but pull the 12V adapter out again.
- Click the Library Manager icon on the left side of the Arduino IDE.
- Type AccelStepper into the search box. The entry you need is the one by Mike McCauley.
- Click its Install button.
- Search for AccelStepper created by Mike McCauley
and click the Install button.
- Put the second code into a new sketch and upload it.
- Turn the cardboard by hand until its arrow looks to the side you want as east. The shaft is free while the 12V is missing.
- Give the motor its 12V again, and press the small reset button of the Nano 33 IoT once. The sketch starts from the beginning, and this time the motor has power at sunrise.
- Open the Serial Monitor. On this board, opening it does not restart the sketch, so if you are late, you see the rest of the day:
Compare the two kinds of moves. A small one is over in a third of a second, and it never gets near the top speed. The way home has time for all three parts. Calculated, it gets faster for 24 steps, stays at 120 steps per second for 48 steps and gets slower for the last 24. All this takes about 1.2 seconds. Now set ACCELERATION to 100 and watch it again: the start and the stop become much softer.
Every target is counted from the east, not from the last place. So the angles do not drift, and after the return the arrow is where the day began.
Troubleshooting
Look at the motor while it has power, but pull the adapter out of the wall before you touch a wire:
- Does nothing move, and can you turn the shaft easily? The driver is off. Check the 3V3 wire on V (or VDD) and the 12V. On a bare module, also check that RST and SLP are linked.
- Does the shaft feel locked, but the panel stays where it is? The driver is on and gets no pulses. Check D4, D3 and the GND wire between the board and the driver.
- Does the motor hum or shake? Look at the coil pairs first. After that, try a higher VREF. Too much TOP_SPEED or ACCELERATION sounds the same.
- Does the panel go from west to east? Exchange red and blue (coil 1 on our motor) and nothing else.
- Does the driver get very hot? Lower VREF, use the heat sink, and leave some air around the module. When it overheats, it switches itself off for a while.
- Is every move too small or too big? The number behind MICROSTEPS does not fit the step size on the driver. For example, a driver at 1/2 and a sketch that says 1 give 7.2 degrees per hour, half of what you want.
- Is the panel in the wrong place in the morning? Something blocked it and steps got lost. Or the board started when the panel was not looking east.
Additional Knowledge
A4988 vs DRV8825
In the same two sockets you can also put a DRV8825. For the sketch, nothing changes: STEP is STEP and DIR is DIR. The differences are in the numbers:
| A4988 | DRV8825 | |
|---|---|---|
| Wires from the Nano 33 IoT | four (one of them is 3V3) | three |
| Amps per coil without cooling | about 1 | about 1.5 |
| Amps per coil with good cooling | 2 | 2.2 |
| Microsteps go down to | 1/16 | 1/32 |
| Motor supply | 8 to 35 volts | 8.2 to 45 volts |
It is evident that a big panel is in better hands with a DRV8825. For a panel as light as ours, both are equally good. The wiring and the code of the other one are in the Arduino Nano 33 IoT - DRV8825 Stepper Motor Driver tutorial, and Arduino Nano 33 IoT - Stepper Motor explains position and speed in more detail.
Why Real Trackers Look Different
Our model shows the movement, but it does not save energy: the motor takes more power than a mini panel can make. Big solar trackers put a gear between the motor and the panel. The gear holds the panel, so the motor can be off between two moves. If you build such a gear, multiply STEPS_PER_HOUR by the gear ratio. With 5 motor turns for one panel turn, 8 steps become 40 steps. The EN pin can switch the motor off when you connect it to one more output, say D5: HIGH between the moves, LOW shortly before the next one.
Project Ideas
- A real day: set HOUR_TIME to 3600000, and one hour takes one hour. Let the Arduino Nano 33 IoT fetch the time of the sunrise over Wi-Fi, as in the Arduino Nano 33 IoT - HTTP Request tutorial.
- Follow the light, not the clock: one light sensor on the left edge and one on the right edge. The panel takes a step to the brighter side until both see the same.
- Find the east alone: after power-on, turn slowly until a limit switch clicks, and let this click be step 0.
- Prove that it helps: log the voltage of the panel with the Arduino Nano 33 IoT - Measure Voltage tutorial, once with a fixed panel and once with a moving one.