Arduino UNO Q - Stepper Motor A4988 Driver
The cat wants breakfast at 7:15. You want to sleep. An automatic feeder keeps both of you happy: a screw (also called an auger) lies at the bottom of a food tank, and one full turn of it drops one portion of dry food into the bowl. The turn must be the same every day, and a plain DC motor cannot promise that. A stepper motor can, because it moves in equal small steps that your program counts. On this page, the Arduino UNO Q turns such a screw with a NEMA 17 stepper motor and an A4988 driver. The STM32 MCU makes the steps. The Linux side knows the meal times, counts the portions and answers on your phone.
From the first wire to the first meal, you will:
- Meet the A4988 module: its pins, its limits, and the idea behind STEP and DIR
- Find out why VDD belongs on the 3V3 pin of the Arduino UNO Q, not on 5V
- Set the motor current with a tiny trimmer, and choose a step size
- Wire the driver in two ways: on an expansion board, or as a module alone
- Turn the screw out and back with a short sketch that needs no library
- Let Python on Linux serve meals at set times over Bridge, with soft starts and stops
- Feed the cat by Telegram, with a daily limit and an automatic refill alert
- Use OpenClaw on Arduino UNO Q with the A4988

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 build this project without the expansion board. In that case, add a 100uF capacitor (rated 35V or more is best) and one short wire between two pins of the module. Both ways are shown below. The 12V adapter is only for the motor. Your Arduino UNO Q stays on its USB-C cable.
Overview of the A4988 Stepper Driver
Moving a stepper motor means switching its coils in a strict order. The A4988 chip already knows that order (the part that knows it is called the translator), so your sketch never touches a coil. It sends only two signals. STEP says "one step now", and DIR says which way. Each time STEP goes from LOW to HIGH, the shaft moves by one step.
Then there is the current. A 3V motor on a 12V adapter sounds like smoke. But the A4988 measures what flows through each coil and keeps cutting the power off and on, very fast, so the coil stays just below your limit. Engineers say the driver chops the current.
The DIYables version comes ready to plug in: 16 soldered pins on a red board, 20 mm long and 15 mm wide, more or less. A little heat sink with a sticky side is packed with it.
| Property | A4988 module |
|---|---|
| Motor | one bipolar stepper with 4 wires (a 6-wire motor works too, used as a 4-wire one) |
| VMOT, motor power | 8V to 35V DC |
| VDD, logic power | 3V to 5.5V, it must be wired |
| Current per coil | 1A or so without heat sink, 2A at most with heat sink and good cooling |
| Step sizes | full, 1/2, 1/4, 1/8, 1/16 |
| STEP pulse | 1 us HIGH and 1 us LOW are enough (us = a millionth of a second) |
| Protects itself from | overheating, a supply that is too low, crossover current |
| Fault pin | none |

| Pin | Job | In this project |
|---|---|---|
| EN | motor outputs on (LOW or free) or off (HIGH, the shaft is loose then) | free |
| MS1, MS2, MS3 | pick the step size, free = LOW | free (full step) |
| RST | resets the chip when LOW. It floats, nothing pulls it up | joined to SLP |
| SLP | LOW puts the chip to sleep. The module itself keeps it HIGH | joined to RST |
| STEP | one pulse = one step | Arduino UNO Q D4 |
| DIR | turning direction | Arduino UNO Q D3 |
| VMOT | plus of the motor power | 12V adapter (+) |
| GND next to VMOT | minus of the motor power | 12V adapter (-) |
| 2B, 2A | coil 2 of the motor | motor wires A and C |
| 1A, 1B | coil 1 of the motor | motor wires B and D |
| VDD | logic power | Arduino UNO Q 3V3 |
| GND next to VDD | logic ground | Arduino UNO Q GND |
Both GND pins end in the same copper. And if the top of your board reads B2, A2, A1, B1, all is fine: turn it over, and the underside says 2B, 2A, 1A, 1B.
Why VDD Goes to 3V3
Many driver modules make their own logic voltage. The A4988 does not. It takes it from VDD, and VDD also decides what counts as a HIGH signal: everything above 0.7 x VDD. The MCU pins of the Arduino UNO Q give 3.3V, so look at the two choices:
| VDD wired to | A HIGH must be above | What a 3.3V pin does |
|---|---|---|
| 5V | 3.5V | not safe, steps can get lost or nothing moves |
| 3V3 | about 2.3V | safe, every step arrives |
So the rule for the Arduino UNO Q is short: VDD = 3V3, never 5V.
The Motor: 200 Steps, Two Coils
A NEMA 17 of this kind is a bipolar stepper: two coils, four wires, no brushes. One full step is 1.8 degrees, and 200 of them make one turn. In our feeder one turn is one portion, so 200 steps = one portion.
Two wires belong to each coil, and they must stay together on the driver. One coil takes 2B and 2A, the other coil takes 1A and 1B.

| Module pin | Wire of the motor | Often marked | Color here |
|---|---|---|---|
| 2B | A | A+ | black |
| 2A | C | A- (A with a bar on top) | green |
| 1A | B | B+ | red |
| 1B | D | B- (B with a bar on top) | blue |
The last column is only our example motor. Yours may look different, and its datasheet has the final word. You can also hunt for the pairs: between two wires of one coil, a multimeter shows a few ohms. No meter at hand? Let two wires touch, then try to rotate the motor. If the shaft has become stiff, both wires come from one coil.
Step Size and DIP Switch
The pins MS1, MS2 and MS3 can cut one full step into smaller ones. The motor then runs smoother and quieter, but it needs more pulses for the same turn.
| MS1 | MS2 | MS3 | Step size | Pulses per turn |
|---|---|---|---|---|
| LOW | LOW | LOW | full | 200 |
| HIGH | LOW | LOW | 1/2 | 400 |
| LOW | HIGH | LOW | 1/4 | 800 |
| HIGH | HIGH | LOW | 1/8 | 1600 |
| HIGH | HIGH | HIGH | 1/16 | 3200 |
On the expansion board these pins sit on a small DIP switch, where ON means HIGH. The order runs backwards: switch 1 is MS3, switch 2 is MS2, switch 3 is MS1. Leave all three OFF for now. If you move them later, tell the sketch too: MICROSTEPS is 1 for full, 4 for 1/4, 16 for 1/16. A feeder next to the bedroom is a good reason for 1/4 steps.
Set the Motor Current First
A round screw on the module, the trimmer, decides how much current a coil may get. Turning it changes a small voltage named VREF, and this is the number you read on the multimeter. The formula is limit = VREF / (8 x Rs). Our module carries two R100 resistors, so Rs = 0.1 ohm, and VREF comes out as 0.8 x current:
| Current per coil | VREF to set |
|---|---|
| 0.5A | 0.40V |
| 0.7A | 0.56V |
| 1A | 0.80V |
- Find the current rating in the datasheet of your motor. Start well below it.
- Leave the 12V adapter unplugged. USB-C is enough, because VDD gets its 3.3V from the Arduino UNO Q.
- Meter on DC volts, red probe on the metal head of the trimmer, black probe on a GND pin.
- Nudge the trimmer with a small screwdriver and read VREF after every nudge. The tip must not slip onto other parts.
A module from another maker may carry R050 resistors. Then VREF is 0.4 x current. Keep one more thing in mind for a feeder: a motor at rest still gets its holding current. It stays warm between the meals, and so does the driver.
Would a DRV8825 do the job? Yes. It also obeys STEP and DIR, and it drops into the same sockets. It accepts 8.2V to 45V, gives about 1.5A (2.2A cooled), offers steps as small as 1/32, and saves you the VDD wire. For a feeder screw, the smaller A4988 is plenty. For motors without steps, see Arduino UNO Q - DRV8833 DC Motor Driver and Arduino UNO Q - BTS7960 Motor Driver.
Wiring Diagram
With the Expansion Board
Plug the A4988 into the two sockets, and only four jumper wires are left between the board and the Arduino UNO Q.

This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
- Look twice before you push the module in. The pins EN to DIR belong on the G V S side, and VMOT belongs at the small VIN arrow. A module that sits backwards can die at the first power-on.
- The V wire is a must here. It carries 3.3V to VDD. A DRV8825 runs without it, an A4988 does not.
- One G and one V are enough. The three G pins are joined, and so are the three V pins. The drawing uses the EN row, but any row works.
- Leave EN and the DIP switch alone. EN free = driver on, all switches OFF = full step. RST and SLP are joined on the board already.
- 12V stays on the green VIN / GND terminal. Never bring it to a pin of the Arduino UNO Q. Only the grounds meet, and they do so on the expansion board.
| Expansion board | Wire goes to |
|---|---|
| STEP row, pin S | Arduino UNO Q D4 |
| DIR row, pin S | Arduino UNO Q D3 |
| V (one of three) | Arduino UNO Q 3V3 (power header) |
| G (one of three) | Arduino UNO Q GND (next to pin 13, or any other GND) |
| EN row, pin S | nothing |
| VIN | 12V adapter plus, the (+) screw of the DC power jack |
| GND beside VIN | 12V adapter minus, the (-) screw of the DC power jack |
| Motor plug, pins 2B + 2A | one coil, wires A and C |
| Motor plug, pins 1A + 1B | the other coil, wires B and D |
The brown, yellow, pink and purple motor wires are only colors of the drawing. Go by the coil table above.
A feeder has to work for months, and one wire that slips out means a hungry cat. With a Screw Shield V2 or a Proto Screw Terminal Block Shield on the Arduino UNO Q, you clamp D3, D4, 3V3 and GND under screws. The pin names do not change:

This image is created using Fritzing. Click to enlarge image
Without the Expansion Board
The module can also stand alone. Then the jobs of the expansion board become yours: one joint, one capacitor, and more wires.

This image is created using Fritzing. Click to enlarge image
※ NOTE THAT:
- RST to SLP, always. In the drawing, the orange jumper does it. Nothing pulls RST up, and a chip that sits in reset ignores every pulse.
- One capacitor: 100uF, 35V or more is best. It goes between VMOT and the GND beside it, as near to the module as you can, plus leg on VMOT. The drawing leaves it out. Your build should not.
- Hands off the motor wires while the 12V is on. Plugging or unplugging a coil under power sends a spike into the A4988, and that can be its end.
| A4988 pin | Wire goes to |
|---|---|
| STEP | Arduino UNO Q D4 |
| DIR | Arduino UNO Q D3 |
| VDD | Arduino UNO Q 3V3 |
| GND next to VDD | Arduino UNO Q GND |
| VMOT | (+) screw of the DC power jack, 12V |
| GND next to VMOT | (-) screw of the DC power jack |
| 2B, 2A | one coil, wires A and C |
| 1A, 1B | the other coil, wires B and D |
| RST, SLP | each other |
| EN, MS1, MS2, MS3 | nothing |
The bare module works with a screw shield as well:

This image is created using Fritzing. Click to enlarge image
Last look before the 12V comes on:
- Is every wire in place? The adapter is always the last thing you plug in.
- Are the module GND, the adapter minus and the Arduino UNO Q GND connected to each other?
- Is the motor plugged in? From now on do not plug or unplug it, with the expansion board or without.
- Does the heat sink sit flat, without touching a pin?
- Is the tank empty for the first test? Later, cover the screw, so no paw and no finger can reach it.
How To Program For A4988
There are two ways. Plain pulses need no library and are perfect for a first test. The AccelStepper library adds soft starts and stops, and the Bridge sketch further down is built on it.
Plain Pulses
- Name the two pins and count the steps of one turn:
- In setup(), turn both pins into outputs:
- Choose a direction, then give DIR a few microseconds:
- Send one pulse for each step. At 2000 us HIGH plus 2000 us LOW, the motor makes 250 steps in a second (75 RPM in full step). This is slow enough for a start from zero, with no speeding up:
AccelStepper
A heavy screw full of food cannot jump to high speed. If you ask for that, the motor only buzzes and loses steps. AccelStepper shortens the time between the pulses little by little, and makes it longer again before the stop.
- Create the stepper. DRIVER means a chip with a STEP pin and a DIR pin:
- In setup(), set three numbers: how long a pulse lasts (us), how fast the motor may go (steps per second), and how quickly it may get there (steps per second, gained every second):
- Set a target. This line moves nothing yet:
- In loop(), call run() again and again. Each call checks the time and makes a step if one is due. A delay() here would break the motion:
- Ask if the motor is still moving, or end the move early with a soft stop:
Arduino UNO Q Code
Before any cat gets fed, check your wires with a small sketch. It runs on one half of the board only:
- The STM32 MCU owns D3 and D4 and makes the pulses. Their timing is counted in microseconds, so this is MCU work.
- The Qualcomm MPU with Debian Linux has a day off. It gets its job in the Bridge section.
- The screw goes out by one turn, pauses for 1.5 seconds, comes back by one turn, pauses again, and so on.
Detailed Instructions
Is this your first App on the board? Getting Started with Arduino UNO Q shows how to set up Arduino App Lab.
- Wire the logic side: STEP to D4, DIR to D3, V (or VDD) to 3V3, G (or GND) to GND.
- Set VREF: Connect the USB-C cable and adjust the trimmer as described above. Then unplug the USB-C cable.
- Wire the power side: Screw in the DC power jack, plug in the motor, and keep the 12V adapter away from the wall socket for now.
- Plug in USB-C again, start Arduino App Lab, and wait for your UNO Q to show up.
- Make an App: Click Create New App.

- Name it CatFeederTest and press Create.

- Copy the sketch: Delete the lines in sketch/sketch.ino and paste the code from above. Nothing else in the App changes.
- Start it: Press the Run button and wait until the console shows the first lines. The motor has no 12V yet, so it does not move.

- Add the 12V: Before you plug the adapter in, fix a paper fish to the shaft. Its nose shows where a turn begins and ends.
App Lab Console Output
Follow the nose of the paper fish. After each turn it must point exactly to its starting place, even in the fiftieth round. If it drifts, steps are lost. One turn lasts about 0.8 seconds (200 steps x 4 ms). Then push the fish gently during a pause: the shaft holds firm, because the coils keep their current.
When the Motor Does Not Behave
| What you see | Why | What helps |
|---|---|---|
| No movement at all | RST is not joined to SLP, or V / VDD gets no 3.3V | the short jumper (module alone), or the wire from 3V3 |
| Humming, shaking, no turn | the pairs are mixed up, two coils share a pair of pins | look for the pairs again, one coil belongs on 2B + 2A |
| Steps get lost when the tank is full | too little current, or too much speed | a bit more VREF, a longer STEP_DELAY, a smaller RAMP |
| Food travels back into the tank | the coil is wired in reverse | exchange 1A and 1B, with the 12V off |
| The driver gets far too hot | VREF is too high | turn it down, and use the heat sink |
| The fish makes only a part of a turn | the DIP switch asks for small steps, MICROSTEPS still says 1 | all switches OFF, or change MICROSTEPS |
Bridge: Linux + MCU
Time for real meals. Linux has a clock, so Python keeps the meal plan and says "two portions, please". The MCU does the steps, now with the AccelStepper library. The wiring stays as it is.
- The MCU alone drives D3 and D4. Linux never sees a single pulse.
- Functions that Python can call:
- feed: give 1 to 6 portions. It only moves the target and returns at once
- stop_feed: end the move early, with a soft stop
- get_state: read-only, answers feeding or idle
- get_portions: read-only, the number of whole turns since the sketch started
- feed and stop_feed change what the pins do, so they use Bridge.provide_safe(). For the two read-only functions, Bridge.provide() is enough.
- ⚠️ /dev/ttyHS1 on the Linux side and Serial1 on the MCU side are RESERVED for the Arduino router. Never open them in your own code.
How can the motor keep turning while Linux talks? The safe functions run between two rounds of loop(). In each round, our loop() waits for the right moment, makes one step and ends. So every call from Linux slips in between two steps, and the screw does not stutter. The Bridge library needs about 1 ms between two rounds. That is why this sketch should stay below 800 steps per second.
Is Bridge new to you? Read Arduino UNO Q - Communication Between Linux and MCU first.
MCU Code (Bridge)
With these numbers the screw needs one turn to reach its top speed of 400 steps per second, and one turn to slow down again. One portion takes about 1.3 seconds, two portions about 1.9 seconds. If you choose smaller steps, the same TOP_SPEED turns the screw more slowly: at 1/4 step, 400 steps per second are only half a turn per second.
Python Code (Bridge)
The script looks at the clock once per second. When a meal is due, it calls feed, waits until the screw rests, and reads how many portions really came out.
Detailed Instructions
- New App: Create one more App in Arduino App Lab and name it CatFeeder.
- MCU side: Paste the MCU code into sketch/sketch.ino. This sketch needs two libraries:
- Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.

- Search for AccelStepper created by Mike McCauley
and click the Install button.
- Search for Arduino_RouterBridge created by Arduino and click the Install button.
- Linux side: The Python code goes into the Python file of this App.
- Choose a test meal: Change one time in MEALS to three minutes from now, so you do not have to wait until morning.
- Run: Start the App, and give the motor its 12V as soon as the first console line is there.
- Compare the clock: The first Python line shows the time of the board. If it is not your local time (the board clock may be on UTC), write the difference in hours into CLOCK_SHIFT and run again.
App Lab Console Output
Look at the target steps: 400, 600, 1000. The target only grows, because each meal adds its own 200 steps per portion. At midnight, Python sets its daily counter back to zero, while the MCU counts on.
Telegram
You are late at work and the bowl is empty? Send a message. This bot gives portions on request, and it looks after two things by itself:
- Daily limit: after 10 portions in one day the bot refuses more, even if the whole family sends /feed. The count starts again at midnight of the board clock. Change DAILY_LIMIT for your cat.
- Refill alert: the bot counts what leaves the tank. When only 8 portions are left, it writes to you without being asked.
| Command | What the feeder does |
|---|---|
| /feed N | gives N portions, 1 to 6 in one go |
| /stop | ends the move early, with a soft stop |
| /status | tells the screw state, the portions of today and the tank level |
| /refill | you filled the tank, so its counter starts again |
You need a bot and its token. Both come from How to Create a Telegram Bot.
The MCU keeps its sketch. The bot calls the same four Bridge functions.
Python Code (Telegram)
Detailed Instructions
- Swap the Python code: In the CatFeeder App, replace the meal plan script with the bot script. The sketch and the libraries stay.
- Paste the token that @BotFather gave you into BOT_TOKEN.
- Small tank for the test: Set TANK_SIZE to 12, so the refill alert comes soon.
- Run, plug in the 12V adapter, and send /feed 2 to your bot.
- Try the stop: Send /feed 6, and /stop right after it. The screw slows down within about one turn.
- Try the limit: Keep feeding until the bot says no.
App Lab Console Output
ArduinoBot
Six portions were asked, but only four fell into the bowl. The bot reads the counter of the MCU after each move, so it books what the screw really did. Both counters live in memory only: they start again when you restart the App.
OpenClaw
You can adapt the OpenClaw to this tutorial by refering the instruction on Arduino Uno Q - OpenClaw Tutorial
Project Ideas
Exact turns and a Linux computer on one board. Some things you can build with that:
- Feeder With a Scale: Put a force sensor under the bowl. Python skips a meal if the last one is still there.
- Tank Level Meter: An ultrasonic sensor in the lid measures how deep the food is, so you no longer need /refill.
- Two Cats, Two Screws: A second A4988 needs only two more pins of the MCU. Each cat gets its own plan in Python.
- Fish Food Drum: Set 1/16 step and turn a small drum by a few degrees per meal.
- Bird Table With Opening Hours: Use a light sensor, and let the feeder start only after sunrise.
Challenge Yourself
Pick the one that fits your level:
- Easy: Set the DIP switch to 1/4 step (only switch 2 ON) and change MICROSTEPS in the first sketch. Then find the STEP_DELAY that brings a turn back to 0.8 seconds.
- Medium: Let the motor cool down between meals. Wire EN to D5, set D5 HIGH when the screw rests (the shaft is free then), and LOW again 5 ms before the next move.
- Advanced: Join the two Python scripts. Meals run from the plan, /plan shows it in Telegram, and the portion counters are saved in a file, so a restart does not lose them.