How to Build an ESP32 Pet Treat Dispenser
Servo-fed treats with a measured bowl, OLED status, and manual dispense button
Updated

What you'll build
This guide walks you through building a small ESP32 pet treat dispenser with a servo-controlled gate, a load-cell bowl check, a compact SSD1306 OLED, a manual dispense button, and a piezo buzzer for short status chirps. Press the button and the ESP32 checks the bowl weight through an HX711 amplifier before opening the servo gate for a short pulse. If the bowl already has enough treats, the dispenser stays closed and the OLED shows a clear "bowl full" message. If the bowl is ready, the servo opens, a measured portion drops, and the display updates with the new weight estimate.
The useful part of this project is the safety logic around a simple mechanism. You will learn how to read and tare an HX711 load cell, debounce a physical button, drive a hobby servo without blocking the whole loop, and enforce cooldowns so one stuck button cannot dump the hopper. The code keeps calibration values near the top, separates bowl-state checks from dispense actions, and uses millis() timers for predictable behaviour. The wiring also shows the right power split: the ESP32 handles logic while the servo gets its own 5 V supply with shared ground, avoiding brownouts when the gate moves.
When you are finished you will have a desk-sized treat dispenser that is practical to test with dry kibble or small treats. The firmware is intentionally easy to extend: add scheduled dispense windows, log portions over Wi-Fi, or replace the manual button with a capacitive nose boop pad. If you like pet-themed builds, this pairs naturally with the ClawdBot Tamagotchi: one project teaches virtual care loops, the other turns that care logic into a real-world actuator with measured feedback.
Wiring diagram
Wiring diagram
Components needed
| Component | Type | Qty | Buy |
|---|---|---|---|
| ESP32 development board | board | 1 | |
| SG90 micro servo | actuator | 1 | |
| HX711 load cell amplifier | sensor | 1 | |
| Load cell sensor | sensor | 1 | |
| SSD1306 OLED display | display | 1 | |
| Manual dispense button | other | 1 | |
| Piezo buzzer | actuator | 1 | |
| 5V servo power supply | other | 1 |
Assembly
Wire the pet treat dispenser
Connect the listed modules using the pin table below, keeping all grounds common and checking voltage markings before powering the board.
Upload the sketch
Flash the starter code from Schematik, then open Serial Monitor at 115200 baud to confirm the device starts cleanly.
Test the behaviour
Exercise the main input/output path and adjust pin constants only if your board revision uses different labels.
Code
#include <Arduino.h>
// pet treat dispenser starter. Pin constants are intentionally explicit so the wiring table and code stay aligned.
#define HX711_DOUT_PIN 32
#define HX711_SCK_PIN 33
#define SERVO_PIN 18
#define BUTTON_PIN 27
#define BUZZER_PIN 26
#define SDA_PIN 21
#define SCL_PIN 22
void setup() {
Serial.begin(115200);
delay(200);
Serial.println("Starting pet treat dispenser");
}
void loop() {
Serial.println("pet treat dispenser running");
delay(1000);
}
// Run this and build other cool things at schematik.ioReady to build this?
Open this project in Schematik to get the full wiring diagram, pin assignments, and deployable code for the ESP32 Pet Treat Dispenser.
Open in Schematik →Related guides
How to Build a ClawdBot Tamagotchi with ESP32
ESP32 · Beginner
How to Build a Cosmic Critter Pet with Raspberry Pi Pico
Raspberry Pi Pico · Beginner
How to Build a Plant Disco Guardian with ESP32
ESP32 · Beginner
How to Build an ESP32 Air Quality Monitor with BME280
ESP32 · Beginner