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:

NEMA 17 stepper motor turned step by step by Arduino UNO Q and A4988 driver

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×Stepper Motor Nema 17
1×A4988 Stepper Motor Driver
1×Expansion Board for A4988
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
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
A4988 module pinout with EN, MS1, MS2, MS3, RST, SLP, STEP, DIR, VMOT, 2B, 2A, 1A, 1B, VDD and GND
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.

Stepper motor coils with the wire names A, C, B, D and their colors
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
  1. Find the current rating in the datasheet of your motor. Start well below it.
  2. Leave the 12V adapter unplugged. USB-C is enough, because VDD gets its 3.3V from the Arduino UNO Q.
  3. Meter on DC volts, red probe on the metal head of the trimmer, black probe on a GND pin.
  4. 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.

The wiring diagram between Arduino UNO Q A4988 stepper motor driver

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:

The wiring diagram between Arduino UNO Q A4988 stepper motor driver Screw Shield

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.

The wiring diagram between Arduino UNO Q with a bare A4988 module, NEMA 17 motor and 12V adapter

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:

The wiring diagram between Arduino UNO Q A4988 module Screw Shield

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

  1. Name the two pins and count the steps of one turn:
#define STEP_PIN 4 // D4 -> STEP #define DIR_PIN 3 // D3 -> DIR #define MICROSTEPS 1 #define STEPS_PER_TURN (200 * MICROSTEPS)
  1. In setup(), turn both pins into outputs:
pinMode(STEP_PIN, OUTPUT); pinMode(DIR_PIN, OUTPUT);
  1. Choose a direction, then give DIR a few microseconds:
digitalWrite(DIR_PIN, HIGH); delayMicroseconds(5);
  1. 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:
for (int i = 0; i < STEPS_PER_TURN; i++) { digitalWrite(STEP_PIN, HIGH); delayMicroseconds(2000); digitalWrite(STEP_PIN, LOW); delayMicroseconds(2000); }

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.

  1. Create the stepper. DRIVER means a chip with a STEP pin and a DIR pin:
#include <AccelStepper.h> AccelStepper stepper(AccelStepper::DRIVER, 4, 3); // STEP, DIR
  1. 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):
stepper.setMinPulseWidth(3); stepper.setMaxSpeed(400); stepper.setAcceleration(400);
  1. Set a target. This line moves nothing yet:
stepper.moveTo(stepper.targetPosition() + 200); // one more portion
  1. 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:
stepper.run();
  1. Ask if the motor is still moving, or end the move early with a soft stop:
bool moving = stepper.isRunning(); stepper.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.
/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-stepper-motor-a4988-driver */ // Arduino UNO Q - A4988 stepper motor driver: the feeder screw turns once out, once back (no library) // The STM32 MCU of the Arduino UNO Q makes every STEP pulse. The Linux side is not used here. // Wiring (expansion board): STEP -> D4, DIR -> D3, V -> 3V3, G -> GND // The motor power comes from a 12V adapter on VIN / GND, never from the Arduino UNO Q. #define STEP_PIN 4 // Arduino UNO Q D4 -> A4988 STEP, one pulse = one step #define DIR_PIN 3 // Arduino UNO Q D3 -> A4988 DIR, which way the shaft turns #define MICROSTEPS 1 // 1 = full step (all DIP switches OFF), or 2, 4, 8, 16 #define STEPS_PER_TURN (200 * MICROSTEPS) // a 1.8 degree motor has 200 full steps per turn #define STEP_DELAY 2000 // microseconds HIGH, then the same LOW (250 pulses per second) #define REST_TIME 1500 // milliseconds of rest after each turn #define PUSH_OUT HIGH // DIR level that moves the food to the bowl #define PULL_BACK LOW // DIR level that moves the food back // Send 'steps' pulses to the driver, all in one direction void turn_screw(int steps, int direction) { digitalWrite(DIR_PIN, direction); delayMicroseconds(5); // let DIR settle before the first pulse for (int i = 0; i < steps; i++) { digitalWrite(STEP_PIN, HIGH); // this LOW -> HIGH edge is the step delayMicroseconds(STEP_DELAY); digitalWrite(STEP_PIN, LOW); delayMicroseconds(STEP_DELAY); } } void setup() { Serial.begin(115200); delay(1500); pinMode(STEP_PIN, OUTPUT); pinMode(DIR_PIN, OUTPUT); digitalWrite(STEP_PIN, LOW); Serial.println("A4988 on UNO Q: one turn = " + String(STEPS_PER_TURN) + " steps"); } void loop() { // 1. One full turn that pushes food out Serial.println("Push out: 1 turn (DIR HIGH)"); turn_screw(STEPS_PER_TURN, PUSH_OUT); delay(REST_TIME); // 2. One full turn the other way Serial.println("Pull back: 1 turn (DIR LOW)"); turn_screw(STEPS_PER_TURN, PULL_BACK); delay(REST_TIME); }

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.
Make a new App for the A4988 sketch in Arduino App Lab
  • Name it CatFeederTest and press Create.
Files of a new App in Arduino App Lab, with the sketch folder
  • 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.
Run button that uploads the A4988 sketch in Arduino App Lab
  • 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

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-11-20 06:48:31] A4988 on UNO Q: one turn = 200 steps [2026-11-20 06:48:31] Push out: 1 turn (DIR HIGH) [2026-11-20 06:48:33] Pull back: 1 turn (DIR LOW) [2026-11-20 06:48:36] Push out: 1 turn (DIR HIGH) [2026-11-20 06:48:38] Pull back: 1 turn (DIR LOW) [2026-11-20 06:48:40] Push out: 1 turn (DIR HIGH)

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)

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-stepper-motor-a4988-driver */ // Arduino UNO Q - A4988 stepper motor driver: the screw of a cat feeder, run from Linux via Bridge // Wiring (expansion board): STEP -> D4, DIR -> D3, V -> 3V3, G -> GND // A Bridge function only changes the target. loop() makes the steps, with a smooth start and stop. // Library: "AccelStepper" by Mike McCauley #include "Arduino_RouterBridge.h" #include <AccelStepper.h> #define STEP_PIN 4 // D4 -> A4988 STEP #define DIR_PIN 3 // D3 -> A4988 DIR #define MICROSTEPS 1 // must match the DIP switches (all OFF = 1) #define STEPS_PER_PORTION (200L * MICROSTEPS) // one turn of the screw = one portion #define MAX_PORTIONS 6 // one command never gives more than this #define TOP_SPEED 400.0 // steps per second (2 turns per second in full step), keep it below 800 #define RAMP 400.0 // steps per second, won every second while speeding up AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN); bool was_turning = false; // Give N portions. Only the target moves here, so this function returns at once. void feed(int portions) { portions = constrain(portions, 1, MAX_PORTIONS); stepper.moveTo(stepper.targetPosition() + portions * STEPS_PER_PORTION); Monitor.println("Feed " + String(portions) + ", new target step " + String(stepper.targetPosition())); } // Stop early. stop() picks a target close by, so the screw slows down and does not jerk. void stop_feed() { stepper.stop(); Monitor.println("Stop asked, slowing down"); } // Read-only: "feeding" or "idle" String get_state() { return stepper.isRunning() ? "feeding" : "idle"; } // Read-only: how many whole turns the screw has made since the sketch started int get_portions() { return stepper.currentPosition() / STEPS_PER_PORTION; } void setup() { Bridge.begin(); Monitor.begin(); stepper.enableOutputs(); // STEP and DIR become outputs stepper.setMinPulseWidth(3); // each STEP pulse stays HIGH for about 3 microseconds stepper.setMaxSpeed(TOP_SPEED); stepper.setAcceleration(RAMP); // These two change what the pins do, so they are registered with provide_safe Bridge.provide_safe("feed", feed); Bridge.provide_safe("stop_feed", stop_feed); // Read-only values, so plain provide() is enough Bridge.provide("get_state", get_state); Bridge.provide("get_portions", get_portions); Monitor.println("A4988 Bridge ready - screw at rest"); } void loop() { // Wait for the right moment, make ONE step, then leave loop(). // The safe Bridge functions run between two rounds of loop(), so between two steps. long before = stepper.currentPosition(); while (stepper.run() && stepper.currentPosition() == before) { } // Tell the console once when the screw has come to rest bool turning = stepper.isRunning(); if (was_turning && !turning) { Monitor.println("Screw at rest, " + String(get_portions()) + " portions since start"); } was_turning = turning; }

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.

""" This Arduino UNO Q script was developed by newbiely.com This Arduino UNO Q script is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-stepper-motor-a4988-driver """ from arduino.app_utils import * from datetime import datetime, timedelta import time # Linux side: the meal plan of the cat feeder. # The MCU makes every step. Python only decides when to feed and how many portions. MEALS = {"07:15": 2, "12:30": 1, "18:45": 2} # "HH:MM" -> portions CLOCK_SHIFT = 0 # hours to add when the printed clock is not your local time today = "" given = set() # the meals that were already given today served_today = 0 # portions given today def now(): return datetime.now() + timedelta(hours=CLOCK_SHIFT) def serve(portions): # Start the screw, wait until it rests, return how many portions came out before = int(Bridge.call("get_portions")) Bridge.call("feed", portions) while str(Bridge.call("get_state")) == "feeding": time.sleep(0.2) return int(Bridge.call("get_portions")) - before def loop(): global today, served_today clock = now() date = clock.strftime("%Y-%m-%d") meal = clock.strftime("%H:%M") if date != today: # first run, or midnight: start a new day today = date given.clear() served_today = 0 print(f"New day {date}, the feeder clock says {meal}") if meal in MEALS and meal not in given: given.add(meal) portions = serve(MEALS[meal]) served_today += portions print(f"Meal {meal}: portions {portions}, today {served_today}") time.sleep(1) App.run(user_loop=loop)

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.
Add sketch library in Arduino App Lab on Arduino UNO Q
  • Search for AccelStepper created by Mike McCauley and click the Install button.
My Apps / DIYables Apps
Run
Bricks
No bricks added...
Sketch Libraries
No sketch libra...
Files
python
sketch
.gitignore
README.md
app.yaml
sketch.ino
Add sketch library
AccelStepper Mike McCauley

Provides an object-oriented interface for 2, 3 or 4 pin stepper motors and motor drivers.

1.64
Install
More Info
  • Search for Arduino_RouterBridge created by Arduino and click the Install button.
My Apps / DIYables Apps
Run
Bricks
No bricks added...
Sketch Libraries
No sketch libra...
Files
python
sketch
.gitignore
README.md
app.yaml
sketch.ino
Add sketch library
Arduino_RouterBridge Arduino

This library provides a simple RPC bridge for Arduino UNO Q boards, allowing communication between the board and other devices using MsgPack serialization.

0.4.1
Install
More Info
  • 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

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-11-20 07:02:24] A4988 Bridge ready - screw at rest [2026-11-20 07:15:00] Feed 2, new target step 400 [2026-11-20 07:15:02] Screw at rest, 2 portions since start [2026-11-20 12:30:00] Feed 1, new target step 600 [2026-11-20 12:30:01] Screw at rest, 3 portions since start [2026-11-20 18:45:00] Feed 2, new target step 1000 [2026-11-20 18:45:02] Screw at rest, 5 portions since start
DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-11-20 07:02:27] New day 2026-11-20, the feeder clock says 07:02 [2026-11-20 07:15:02] Meal 07:15: portions 2, today 2 [2026-11-20 12:30:02] Meal 12:30: portions 1, today 3 [2026-11-20 18:45:02] Meal 18:45: portions 2, today 5 [2026-11-21 00:00:00] New day 2026-11-21, the feeder clock says 00:00

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)

""" This Arduino UNO Q script was developed by newbiely.com This Arduino UNO Q script is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-stepper-motor-a4988-driver """ from arduino.app_utils import * import requests import time # Linux side: a Telegram bot for the cat feeder. # Keep the MCU sketch from the Bridge section. It offers feed, stop_feed, # get_state and get_portions. BOT_TOKEN = "YOUR_BOT_TOKEN" API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}" MAX_PER_FEED = 6 # the MCU sketch gives no more than this in one command DAILY_LIMIT = 10 # portions per day, the bot refuses more TANK_SIZE = 40 # portions in a full food tank REFILL_AT = 8 # send the refill alert at this many portions or fewer last_update_id = 0 chat = None # the last chat that wrote, it gets the automatic messages day = "" fed_today = 0 tank = TANK_SIZE # portions still in the tank seen = None # the MCU portion counter at the last look turning = False refill_sent = False HELP_TEXT = ( "Cat feeder commands:\n" "/feed N - give N portions\n" "/stop - stop the screw early\n" "/status - screw, portions today, tank\n" "/refill - the tank is full again" ) def send_message(chat_id, text): try: requests.post(f"{API_URL}/sendMessage", json={"chat_id": chat_id, "text": text}, timeout=10) except Exception as e: print(f"Error sending message: {e}") def get_updates(wait): try: resp = requests.get(f"{API_URL}/getUpdates", params={"offset": last_update_id + 1, "timeout": wait}, timeout=wait + 5) return resp.json().get("result", []) except Exception as e: print(f"Error getting updates: {e}") return [] def book_portions(): # Read the MCU counter and book the portions made since the last look global seen, fed_today, tank total = int(Bridge.call("get_portions")) new = max(total - seen, 0) seen = total fed_today += new tank = max(tank - new, 0) return new def feed(parts, chat_id): global turning if len(parts) != 2 or not parts[1].isdigit() or not 1 <= int(parts[1]) <= MAX_PER_FEED: send_message(chat_id, f"Usage: /feed 1-{MAX_PER_FEED} (example: /feed 2)") return count = int(parts[1]) left = max(DAILY_LIMIT - fed_today, 0) if turning: send_message(chat_id, "The screw is still turning. Try again in a few seconds.") elif count > left: print(f"Refused: {fed_today} of {DAILY_LIMIT} portions used today") send_message(chat_id, f"Refused. {fed_today} of {DAILY_LIMIT} portions are used today, {left} left.") else: Bridge.call("feed", count) turning = True send_message(chat_id, f"Feeding, portions asked: {count}.") def handle(text, chat_id): global tank, refill_sent parts = text.split() command = parts[0] if parts else "" if command == "/feed": feed(parts, chat_id) elif command == "/stop": if turning: Bridge.call("stop_feed") send_message(chat_id, "Stopping. The screw slows down first.") else: send_message(chat_id, "The screw is not turning.") elif command == "/status": state = str(Bridge.call("get_state")) send_message(chat_id, f"Screw: {state}. Today: {fed_today} of {DAILY_LIMIT}. Tank: {tank} of {TANK_SIZE}.") elif command == "/refill": tank = TANK_SIZE refill_sent = False send_message(chat_id, f"Thank you! The tank counts {TANK_SIZE} portions again.") else: send_message(chat_id, HELP_TEXT) def loop(): global last_update_id, chat, day, fed_today, seen, turning, refill_sent if seen is None: # first run: begin with what the MCU has already counted seen = int(Bridge.call("get_portions")) if time.strftime("%Y-%m-%d") != day: # first run, or midnight: the daily counter starts again day = time.strftime("%Y-%m-%d") fed_today = 0 for update in get_updates(1 if turning else 5): last_update_id = update["update_id"] msg = update.get("message", {}) chat_id = msg.get("chat", {}).get("id") text = msg.get("text", "").strip() if not chat_id: continue print(f"Telegram: {text}") chat = chat_id handle(text, chat_id) # The screw came to rest: count what really came out if turning and str(Bridge.call("get_state")) == "idle": turning = False new = book_portions() print(f"Done: portions {new}, today {fed_today}, tank {tank}") send_message(chat, f"Done. Portions in the bowl: {new}. Today: {fed_today} of {DAILY_LIMIT}.") # Automatic alert: the tank is nearly empty if tank <= REFILL_AT and not refill_sent: refill_sent = True print(f"Alert: time to refill, {tank} portions left") send_message(chat, f"Time to refill! Only {tank} portions are left in the tank.") time.sleep(0.2) App.run(user_loop=loop)

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

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-11-20 19:02:10] Telegram: /feed 2 [2026-11-20 19:02:12] Done: portions 2, today 2, tank 10 [2026-11-20 19:03:40] Telegram: /feed 6 [2026-11-20 19:03:42] Telegram: /stop [2026-11-20 19:03:44] Done: portions 4, today 6, tank 6 [2026-11-20 19:03:44] Alert: time to refill, 6 portions left [2026-11-20 19:05:01] Telegram: /feed 6 [2026-11-20 19:05:01] Refused: 6 of 10 portions used today [2026-11-20 19:06:30] Telegram: /refill [2026-11-20 19:06:52] Telegram: /status
Telegram
Telegram 12:45
Welcome to Telegram!
ArduinoBot 10:19
Chatting with Arduino...
telegram-botfather
BotFather Yesterday
Your bot has been created.

ArduinoBot

bot
Today
/feed 2
10:15 AM ✓✓
Feeding, portions asked: 2.
10:16 AM
Done. Portions in the bowl: 2. Today: 2 of 10.
10:17 AM
/feed 6
10:18 AM ✓✓
Feeding, portions asked: 6.
10:19 AM
/stop
10:20 AM ✓✓
Stopping. The screw slows down first.
10:21 AM
Done. Portions in the bowl: 4. Today: 6 of 10.
10:22 AM
Time to refill! Only 6 portions are left in the tank.
10:23 AM
/feed 6
10:24 AM ✓✓
Refused. 6 of 10 portions are used today, 4 left.
10:25 AM
/refill
10:26 AM ✓✓
Thank you! The tank counts 12 portions again.
10:27 AM
/status
10:28 AM ✓✓
Screw: idle. Today: 6 of 10. Tank: 12 of 12.
10:29 AM

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.

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!