How to Build an ESP32 Pet Treat Dispenser

Servo-fed treats with a measured bowl, OLED status, and manual dispense button

ESP32PetsIntermediate55 minutes8 components

Updated

How to Build an ESP32 Pet Treat Dispenser
For illustrative purposes only
On this page

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

Interactive wiring diagram

Components needed

ComponentTypeQtyBuy
ESP32 development boardboard1
SG90 micro servoactuator1
HX711 load cell amplifiersensor1
Load cell sensorsensor1
SSD1306 OLED displaydisplay1
Manual dispense buttonother1
Piezo buzzeractuator1
5V servo power supplyother1

Assembly

1

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.

2

Upload the sketch

Flash the starter code from Schematik, then open Serial Monitor at 115200 baud to confirm the device starts cleanly.

3

Test the behaviour

Exercise the main input/output path and adjust pin constants only if your board revision uses different labels.

Code

Arduino C++
#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.io
Libraries: HX711, Servo, Adafruit SSD1306