Wi-Fi pet feeder with portion control
Build it step by step
0 of 7 donePrint the auger and hopper
Test with dry food.
Mount the stepper
Shaft aligned with the auger.
Test one turn
Check the direction.
Weigh a portion
Set TURNS_PER_PORTION.
Add the web page
With your own password.
Set the feeding times
In the code.
Watch it for a few days
Before leaving it.
How do you build a wi-Fi pet feeder with portion control?
A stepper turns an auger to drop measured portions of dry food at set times, and you can feed from your phone too. You need ESP32 DevKit V1, 28BYJ-48 Stepper Motor, ULN2003 driver board, 5 V 2 A USB adapter and 3D printer PLA filament 1.75 mm (1 kg). It takes 7 steps and about 240 minutes.
- Level
- Intermediate
- Time
- About 240 min
- Parts
- 5
Wiring
| From | To | Why |
|---|---|---|
| ULN2003 IN1, IN2, IN3, IN4 | ESP32 GPIO19, GPIO18, GPIO5, GPIO17 | Stepper coils |
| ULN2003 plus and minus | 5 V adapter, ground joined to the ESP32 GND | Motor power |
| Stepper plug | ULN2003 socket | 28BYJ-48 motor |
| ESP32 | Same 5 V adapter on VIN, or USB | Power |
Code
The 28BYJ-48 is a geared stepper, so it turns slowly with a lot of force, which is right for an auger that pushes dry food along a tube. The sketch counts turns, not time, so each portion is the same: weigh the food from one portion on a kitchen scale and change TURNS_PER_PORTION until it matches the amount your vet suggests. Two safeguards matter for a pet: a hard daily limit of portions, which the web page cannot get past, and the coils are switched off after each feed so the motor does not heat. The web page uses a password, so only you can feed from it; use it on your home network and do not open it to the internet. Print the auger and hopper in PLA, but be aware that printed layers can hold bacteria, so line the parts that touch the food with a food-safe liner or use food-safe containers, and wash them regularly. A jam can stall the motor, so look at the feeder a few times a day at first and do not rely on it as the only source of food or water for a pet that is left alone for days. Keep the cable and the motor out of the pet's reach. Arduino IDE with the ESP32 boards package 2.0.x, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Pet feeder: feeds a set number of auger turns at two times a day and from a password-protected web page.
// Libraries: Stepper (built in), WebServer (built in with the ESP32 package). Board: ESP32. Fill in the placeholders.
#include <WiFi.h>
#include <WebServer.h>
#include <Stepper.h>
#include <time.h>
const char* WIFI_NAME = "YOUR_WIFI_NAME";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
const char* PAGE_PASSWORD = "CHOOSE_A_PASSWORD";
const int FEED_HOURS[] = { 7, 18 }; // feeding times, 24 hour clock
const int TURNS_PER_PORTION = 3; // calibrate: weigh the food from one portion
const int MAX_PORTIONS_PER_DAY = 4; // a hard limit so a bug or a hacker cannot overfeed
Stepper motor(2048, 19, 5, 18, 17); // 28BYJ-48: coil order IN1, IN3, IN2, IN4
WebServer server(80);
int portionsToday = 0, lastDay = -1, lastFedMinute = -1;
void releaseCoils() { for (int p : {19, 18, 5, 17}) digitalWrite(p, LOW); }
bool feed() {
if (portionsToday >= MAX_PORTIONS_PER_DAY) return false;
motor.step(2048 * TURNS_PER_PORTION);
releaseCoils();
portionsToday++;
return true;
}
void handleRoot() {
if (!server.authenticate("admin", PAGE_PASSWORD)) return server.requestAuthentication();
String s = "<h1>Feeder</h1><p>Portions today: " + String(portionsToday) + " of " + String(MAX_PORTIONS_PER_DAY) + "</p>";
s += "<form method='post' action='/feed'><button>Feed now</button></form>";
server.send(200, "text/html", s);
}
void handleFeed() {
if (!server.authenticate("admin", PAGE_PASSWORD)) return server.requestAuthentication();
feed();
server.sendHeader("Location", "/"); server.send(303);
}
void setup() {
Serial.begin(115200);
motor.setSpeed(8); // rpm, slow and strong
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) delay(500);
configTime(19800, 0, "pool.ntp.org"); // India time, change for yours
server.on("/", handleRoot);
server.on("/feed", HTTP_POST, handleFeed);
server.begin();
}
void loop() {
server.handleClient();
struct tm t;
if (getLocalTime(&t)) {
if (t.tm_mday != lastDay) { lastDay = t.tm_mday; portionsToday = 0; } // new day, new allowance
int minuteKey = t.tm_hour * 60 + t.tm_min;
for (int h : FEED_HOURS) {
if (t.tm_hour == h && t.tm_min == 0 && minuteKey != lastFedMinute) { lastFedMinute = minuteKey; feed(); }
}
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Tap Feed now | Auger turns and food drops |
| Weigh one portion | Matches the amount you set |
| At the set time | Feeds once |
| Fifth feed in a day | Refused |
If it does not work
Motor buzzes
Check the coil order 19, 5, 18, 17.
Food jams
Use a larger auger gap and dry, even food.
Times are wrong
Check the time zone offset in configTime.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the wi-Fi pet feeder with portion control?
ESP32 DevKit V1, 28BYJ-48 Stepper Motor, ULN2003 driver board, 5 V 2 A USB adapter and 3D printer PLA filament 1.75 mm (1 kg).
How long does the wi-Fi pet feeder with portion control take to build?
About 240 minutes for a intermediate maker, in 7 steps.
How do I know the wi-Fi pet feeder with portion control works?
Tap Feed now: Auger turns and food drops. Weigh one portion: Matches the amount you set. At the set time: Feeds once.
Motor buzzes: what should I check?
Check the coil order 19, 5, 18, 17.
Food jams: what should I check?
Use a larger auger gap and dry, even food.
Times are wrong: what should I check?
Check the time zone offset in configTime.
