Arduino MicroPython Stepper Motor A4988 Driver
Boiler rooms, old cars and railway stations have something that no LCD can copy: a big round dial with a pointer. You can read it from the other side of the room. To build one yourself, you need a motor that goes to an exact angle and then stays there without moving. A stepper motor does just that. On this page, the pointer sits on the shaft of a NEMA 17 motor, the DIYables A4988 Stepper Motor Driver Module feeds the motor, and an Arduino Giga R1 WiFi with MicroPython gives the orders on only two pins. This is the way we go:
- Meet the 16 pins of the A4988 module, and find out which motor wires belong together.
- Wire it twice: first on an expansion board, then with the bare module. STEP is on D4, DIR is on D3, and VDD is on 3.3V.
- Pick a step size with MS1, MS2 and MS3, and set the motor current with a small screwdriver.
- Move the shaft with plain machine.Pin code, then add a speed ramp, so a long pointer starts and stops softly.

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 .
You can leave out the expansion board. It saves a few wires and brings its own capacitor, but the last wiring drawing on this page does the same job without it. For the gauge itself, a strip of cardboard makes a fine pointer, and a paper plate makes a fine dial.
Overview of A4988 Stepper Motor Driver and Pinout
The module is a red board of about 20 x 15 mm with two rows of eight pins, already soldered, and a little stick-on heat sink in the bag. It looks after one bipolar stepper motor, and nothing else.
What does it do for you? A stepper motor only turns when its coils get power in the right order, again and again. You could type that order in Python, but the A4988 has it inside already, in a part called the translator. So the script never touches a coil. It sends a pulse on STEP to say "go one step", and it sets the level on DIR to say "this way" or "that way". The chip has a second job: it measures the current in both coils and cuts the power on and off, very fast, so that the current never passes the limit you set. This trick is named chopping, and thanks to it a motor with 3V on its label can live with a 12V adapter.

| Data | DIYables A4988 Stepper Motor Driver Module |
|---|---|
| Motor it can drive | 1 bipolar stepper motor, 4 wires (or 6 wires with 4 of them used) |
| Motor supply (VMOT) | 8V to 35V DC, 12V on this page |
| Logic supply (VDD) | 3V to 5.5V, from a wire of its own |
| Current for each coil | about 1A as it is, up to 2A with the heat sink and good cooling |
| Step sizes | full, 1/2, 1/4, 1/8, 1/16 |
| STEP pulse | HIGH for 1 µs or longer, LOW for 1 µs or longer |
| Protection | over-temperature shutdown, under-voltage lockout, crossover-current protection |
| Fault pin | not available |
The pins, sorted by their job in this project:
- STEP: the pulse input. The moment it goes from LOW to HIGH, the motor makes one step (or one microstep). Wire it to D4.
- DIR: decides which way the next steps go. Wire it to D3.
- VDD: power for the logic part of the chip. The module cannot make this voltage itself, so the wire is a must. Wire it to 3.3V of the Giga.
- GND, in the corner beside VDD: the logic ground. Wire it to any GND pin of the Giga.
- VMOT: power for the motor. It gets the + of the 12V adapter.
- GND beside VMOT: the motor ground. It gets the - of the 12V adapter. A track on the module joins the two GND pins.
- 2B and 2A: the two ends of one motor coil.
- 1A and 1B: the two ends of the other motor coil.
- MS1, MS2, MS3: the step size. A pin with no wire counts as LOW, and three LOW pins mean full steps.
- EN: turns the motor outputs on (LOW) or off (HIGH). The module holds it LOW, so no wire is needed. With HIGH, your fingers could turn the shaft freely.
- SLP: puts the chip to sleep when LOW. The module holds it HIGH.
- RST: resets the chip when LOW. No part on the module holds this pin, so on its own it floats between HIGH and LOW. Join it to SLP, and it stays HIGH too.
Do not worry if your board shows other names at the motor pins. The top side prints B2, A2, A1, B1, and the underside prints 2B, 2A, 1A, 1B. They are the same four pins.
Why VDD Goes to 3.3V and Not to 5V
Every logic chip has a border above which a voltage counts as HIGH. For the A4988, the border is 0.7 x VDD. A Giga pin gives 3.3V when it is HIGH, so compare:
| VDD on | HIGH begins at | The Giga sends | What happens |
|---|---|---|---|
| 5V | 3.5V | 3.3V | below the border, steps can get lost |
| 3.3V | 2.31V | 3.3V | well above the border, every pulse counts |
On the power header of the Giga, the 5V hole is the direct neighbour of the 3.3V hole. Read the label once more before you push the wire in.
Four Motor Wires, Two Coils
Inside a bipolar motor there are two separate coils, and both ends of each coil come out as a wire. Two coils, four wires. Our NEMA 17 turns 1.8° per full step, so 200 full steps bring the pointer back to where it began, and 50 full steps are a quarter of the dial.

| A4988 pin | Motor wire | Other names | Our sample motor |
|---|---|---|---|
| 2B | A | A+ or A | black |
| 2A | C | A- or A with a bar | green |
| 1A | B | B+ or B | red |
| 1B | D | B- or B with a bar | blue |
Makers do not agree on colours, so trust the datasheet of your own motor more than this table. You have no datasheet? Either of these tests finds the pairs:
- Take a multimeter and measure between two wires. A few ohms: one coil. No connection: two different coils.
- Hold two bare wire ends together and turn the shaft by hand. If it suddenly feels heavier, those two wires are one coil.
Once the pairs are right, not much can go wrong. Swap the two wires inside one pair, and the pointer simply runs the other way. But put one wire of each coil into the same pair of pins, and the motor only hums and trembles.
Step Size for a Calm Pointer
The A4988 can cut a full step into smaller pieces. The pointer then glides instead of ticking, and the motor gets quieter. The price is more pulses for the same angle:
| MS1 | MS2 | MS3 | Step size | Pulses for one turn | Pointer moves per pulse |
|---|---|---|---|---|---|
| LOW | LOW | LOW | full | 200 | 1.8° |
| HIGH | LOW | LOW | 1/2 | 400 | 0.9° |
| LOW | HIGH | LOW | 1/4 | 800 | 0.45° |
| HIGH | HIGH | LOW | 1/8 | 1600 | 0.225° |
| HIGH | HIGH | HIGH | 1/16 | 3200 | 0.1125° |
On the expansion board, the three small DIP switches set these pins, and ON means HIGH. The numbers run backwards: switch 3 is MS1, switch 2 is MS2, and switch 1 is MS3. For 1/8 steps, put 3 and 2 to ON and leave 1 OFF. With the module alone, a wire from an MS pin to 3.3V makes it HIGH. Both scripts start with a constant named MICROSTEPS. It must always hold the same number as the driver: 1, 2, 4, 8 or 16.
Set the Current Limit (VREF)
The tiny round trimmer next to the chip sets how much current a coil may take. You read the setting as a voltage called VREF. The limit is VREF / (8 x Rs), and Rs on the DIYables module is 0.1Ω (two of the small resistors carry the mark R100). Turned around, it becomes easy: VREF = 0.8 x current.
| Current you want | VREF to set | Good for |
|---|---|---|
| 0.4A | 0.32V | a light cardboard pointer, the first try |
| 0.7A | 0.56V | a heavier pointer |
| 1A | 0.80V | the most without a heat sink |
How to do it:
- Connect VDD and GND, and plug the Giga into USB. VDD has power now, and the 12V adapter can stay unplugged.
- Set the multimeter to DC volts. Put the black probe on GND and the red probe on the metal top of the trimmer.
- Turn the trimmer just a little with a small screwdriver, and measure again. Keep the tip off the parts around it.
- Begin low. Go up only if the pointer misses steps, and never above the rated current of your motor.
The formula changes with the resistors. A board of another brand with R050 parts needs VREF = 0.4 x current.
Do not be surprised by heat. A pointer that stands on its mark still needs current to hold its place, so the motor and the driver warm up even when nothing moves.
Wiring Diagram
The scripts are the same for both circuits below. Choose the one that fits your parts, and leave the adapter for the very end.
With the Expansion Board
Push the A4988 into the two sockets of the 42 x 42 mm board. The motor has its own 4-pin plug there, the adapter wires go under two screws, and only four jumper wires lead to the Giga.

This image is created using Fritzing. Click to enlarge image
| Arduino Giga R1 WiFi | Expansion board (G V S header) |
|---|---|
| D4 | S pin of the STEP row |
| D3 | S pin of the DIR row |
| 3V3 | V pin (the drawing uses the EN row) |
| GND | G pin (the drawing uses the EN row) |
| nothing | S pin of the EN row stays free, the driver is on |
The three V pins are joined on the board, and so are the three G pins. That is why one red wire and one black wire are enough. The V wire feeds VDD of the A4988, so it cannot be left out. In the drawing it starts at the 3V3 pin of the small inner header near the USB ports. The 3.3V pin of the power header is just as good.
| 12V side | Where it goes |
|---|---|
| DC power jack + | VIN screw terminal |
| DC power jack - | GND screw terminal |
| 2B, 2A, 1A, 1B of the 4-pin plug | motor wires A, C, B, D, as in the coil table above |
The brown, yellow, pink and purple wires only exist in the drawing. Your motor has its own colours, so go by the coils. RST and SLP are already joined on this board, a 100uF / 35V capacitor sits next to the screw terminal, and the print "12-24V" tells you which adapters it is made for.
※ NOTE THAT:
- Check the module twice before you press it in: the EN to DIR row belongs to the socket beside the G V S header, and VMOT sits at the little "VIN" arrow. Turned around, the module can be destroyed at power-up.
- The 12V belongs to the VIN screw only. It must never meet a pin of the Giga.
- Never pull out or push in the motor plug while the driver has power. The voltage spike can kill the A4988.
With the A4988 Module Alone
Without the expansion board, you take over two of its jobs: the link between RST and SLP, and the capacitor. The pins of the module are male, so you need jumper wires with a female end on this side.

This image is created using Fritzing. Click to enlarge image
| A4988 module | Connect to |
|---|---|
| STEP | D4 of the Giga |
| DIR | D3 of the Giga |
| VDD | 3.3V of the Giga |
| GND beside VDD | GND of the Giga |
| RST and SLP | each other, with a short wire (orange in the drawing) |
| VMOT | + of the 12V adapter |
| GND beside VMOT | - of the 12V adapter |
| 2B, 2A | motor wires A and C (first coil) |
| 1A, 1B | motor wires B and D (second coil) |
| EN, MS1, MS2, MS3 | nothing (driver on, full steps) |
※ NOTE THAT:
- Forget the RST-SLP wire, and the shaft will not move at all.
- Add a 100uF capacitor, best with a 35V rating or more, right at the module: + leg to VMOT, - leg to GND. It takes up voltage peaks on the 12V line. The drawing does not show it.
- The minus of the adapter, the GND of the module and the GND of the Giga must be one common ground.
How To Program A4988 With MicroPython
There is no library to copy to the board. Two output pins and some waiting time do everything.
- Create the two outputs. On the Giga, the pin name is a text such as 'D4':
- Set the direction, and give the A4988 a moment to notice it:
- Send one pulse, which is one step. Two times 2000 µs make 4 ms per step, or 250 steps per second:
- An angle in degrees becomes a number of pulses with one line. With full steps, 90 degrees give 50 pulses:
- A gauge thinks in values, not in degrees. If 150 is the last number on the scale and the scale covers 270 degrees, this line finds the place of any value:
Please keep one thing in mind: the A4988 cannot tell the script where the pointer really is. The script only counts its own pulses. If somebody pushes the pointer, or if a step gets lost, the count is wrong until you set the pointer to 0 again.
Arduino MicroPython Code - Stepper Motor A4988 Driver
The first script checks the wiring. The shaft goes once around the dial, rests for two seconds, comes back the same way, and rests again. One turn takes 0.8 seconds (75 RPM), which is slow enough for a motor to start from zero without help.
Detailed Instructions
To try it on the Arduino Giga with Thonny IDE:
- Thonny IDE must be on your computer, and the MicroPython firmware must be on the Giga.
- Both are new to you? Work through Getting Started with Arduino and MicroPython first, then come back.
- Build one of the two circuits, with the DIP switches all OFF (or MS1 to MS3 free). Keep the 12V adapter unplugged.
- Fold a piece of tape around the motor shaft, like a small flag, so you can see it turn.
- Connect the Giga and the computer with the USB Type-C cable.
- Open Tools Options in Thonny IDE.
- Go to the Interpreter tab and select MicroPython (generic).
- Select the COM port that belongs to the Giga (e.g., COM33 on Windows or /dev/ttyACM0 on Linux).
- Copy the script into the editor of Thonny.
- Put it on the board:
- Press Ctrl+S, or click Save.
- Select MicroPython device and enter main.py as the file name.
- Plug the 12V adapter into the DC power jack. The shaft locks now.
- Click the green Run button (or press F5), and look at the Shell.
Watch the flag, not only the Shell. It has to stop at the same place after every lap, even after ten of them. If the flag stops at another place, steps were lost, and the table under "When the Pointer Does Not Obey" can help.
After a click on Stop, the Shell is quiet, but the shaft is still hard to turn. That is normal: the EN pin is free, so the driver keeps holding the motor. Unplug the 12V adapter to let it go.
Arduino MicroPython Code - Gauge Pointer With Soft Start and Stop
Glue a 12 cm pointer to the shaft, run the first script again, and you see a problem. The motor jumps from standstill to 250 steps per second, the pointer bends, and at the end it swings back and forth. The second script takes care of this with a speed ramp. Each move begins slowly, gets a little faster with every pulse, and slows down in the same way before it stops.
The script also knows the dial: a scale from 0 to 150 over three quarters of a circle (270°). With full steps, each unit of the scale is exactly one pulse. Like the dashboard of an old sports car, the gauge first sweeps to the last mark and back, then it visits 40, 115 and 75.
show_value() is the only function you need to call. It turns the value into a target, counts the pulses from the present position, and asks speed_at() for the speed of each pulse. Values below 0 or above 150 are cut off, so the pointer never leaves the scale.
Detailed Instructions
- Draw a dial with the numbers 0 to 150 over 270°, and fix the motor behind it. The middle of the dial is the motor shaft.
- Paste the second script into Thonny, stop the old one, and save the new one as main.py on the MicroPython device.
- Is the 12V adapter plugged in? Good, the shaft is locked. Push the pointer on the shaft so that it stands on 0.
- Click Run (F5) and let the gauge play its list once.
- To end the show, click into the Shell and press Ctrl+C. The pointer drives back to 0 before the script ends.
Here is the ramp of the long sweep from 0 to 150, as the script calculates it:
| Pulse number | Speed | Time for this pulse |
|---|---|---|
| 1 | 60 pulses per second | 16.7 ms |
| 26 | 180 pulses per second | 5.6 ms |
| 51 to 100 | 300 pulses per second | 3.3 ms |
| 125 | 180 pulses per second | 5.6 ms |
| 150 | 60 pulses per second | 16.7 ms |
The sweep takes about 0.85 seconds. At the slow starting speed all the way, it would take 2.5 seconds. Now look at the short move from 0 to 40: it has no room for the full ramp, so it only climbs to about 150 pulses per second and then slows down. You do not need any extra code for this, because speed_at() always looks at the nearer end of the move.
Three numbers to play with:
- TOP_SPEED: lower it for a heavy or long pointer.
- RAMP_PULSES: a bigger number means a longer, softer start and stop.
- MICROSTEPS: change it to 8 and set the DIP switches to 1/8 steps. The same list then needs eight times as many pulses, and the pointer moves over the dial very smoothly.
※ NOTE THAT:
The file name main.py makes the Giga run the script by itself at power-up. A pulse without 12V moves nothing, but the script counts it all the same. For a gauge on the wall, put time.sleep(5) at the top of the script, so you have time to plug in the adapter and turn the pointer to 0.
When the Pointer Does Not Obey
| What you see | Reason and cure |
|---|---|
| The shaft does not move, the Shell prints as usual | The 12V is missing, or VDD (V on the expansion board) has no 3.3V wire. On the bare module, check the RST-SLP wire too |
| The motor hums or shakes on the spot | The coil pairs are mixed up, or VREF is too low, or the speed is too high. Test the pairs, raise VREF a little, then lower TOP_SPEED |
| Bigger values move the pointer to the left | One coil is reversed. Unplug the 12V, then swap the two wires of one coil, for example 1A and 1B |
| The pointer stops at half or a quarter of the angle | MICROSTEPS in the script and the MS pins (DIP switches) say different things. Remember that switch 3 is MS1 |
| The pointer misses its marks after some minutes | Steps get lost. Use a lighter pointer, a longer ramp, or a little more current |
| The driver is too hot to touch, or the motor stops now and then | The chip protects itself from heat. Lower VREF and stick the heat sink on the chip |
A4988 or DRV8825?
Shops often list these two modules side by side. Both take the same STEP and DIR signals, and both fit the sockets of the expansion board, so the scripts of this page do not care which one is plugged in. The real differences:
| A4988 | DRV8825 | |
|---|---|---|
| Motor supply | 8V to 35V | 8.2V to 45V |
| Current without and with cooling | about 1A, then 2A | about 1.5A, then 2.2A |
| Finest step | 1/16 | 1/32 |
| Logic supply wire | needed, 3.3V on the Giga | not needed |
For a pointer, the A4988 is more than strong enough. Choose the DRV8825 if your motor needs more current, or a supply above 35V. The table of MS1 to MS3 above belongs to the A4988, so look up the step sizes again if you change the module.
And if the thing you want to turn has no fixed positions at all, such as a fan or a wheel, a plain DC motor is the better choice. See Arduino MicroPython BTS7960 Motor Driver.
Project Ideas for Your Gauge
Replace the MARKS list with a real measurement, and give it to show_value() as a whole number (use round()):
- Room thermometer: write 0 to 50 on the dial, set MAX_VALUE to 50, and read the probe from Arduino MicroPython NTC Thermistor Temperature Sensor.
- Fresh-air dial: green, yellow and red fields, with the number from the SCD40 CO2 sensor.
- Hand-driven gauge: let a potentiometer choose the value, and watch the pointer follow your hand.
- A gauge that finds its own zero: fit a limit switch at the 0 mark. At start, step back slowly until it closes, then set position to 0.