How to Build a Smart Automatic Feeder for Your Dog Using a Raspberry Pi
Ever stare at your dog waiting for breakfast while you’re stuck in a Zoom call? That tug‑of‑war between work and pet care is real, and a DIY smart feeder can end the drama. I built one for Max last winter, and the whole process was as satisfying as watching him gobble his first bowl on schedule. Below is a step‑by‑step guide that anyone with a bit of curiosity can follow.
What You’ll Need
Before you dive in, gather these parts. Most of them are cheap and easy to find online or at a local electronics store.
- Raspberry Pi (any model with GPIO pins; I used a Pi 4)
- Micro‑SD card (8 GB or larger, pre‑loaded with Raspberry Pi OS)
- 5 V DC motor with a small gear box (enough torque to push a kibble cup)
- Motor driver board (L298N works well)
- Breadboard and jumper wires
- Power supply for the Pi (5 V / 3 A)
- Food container (a simple plastic tub works)
- Servo or stepper motor (optional, for a rotating cup design)
- Miniature LCD screen (optional, for on‑board status)
- Screwdriver, zip ties, and a bit of hot glue
If you’re missing a tool, improvise. I used an old coffee can as the food hopper and a cheap hobby servo for the dispensing arm.
Setting Up the Raspberry Pi
Install the OS
- Download Raspberry Pi OS Lite from the official site.
- Flash it onto the micro‑SD card using a tool like Balena Etcher.
- Insert the card, plug in the power, and let the Pi boot.
Enable SSH and GPIO
Open a terminal on the Pi (or connect via SSH from your laptop) and run:
sudo raspi-config
- Navigate to Interface Options → SSH and enable it.
- Go to Interface Options → GPIO and turn it on.
- Finish and reboot.
Now you can control the Pi’s pins from any computer on the same network.
Wiring the Motor
Understanding GPIO
GPIO stands for General‑Purpose Input/Output. Think of them as tiny switches that let the Pi talk to the outside world. We’ll use a few pins to tell the motor when to turn.
Connect the Motor Driver
- Plug the L298N board into the breadboard.
- Connect the motor’s two wires to the driver’s OUT1 and OUT2 terminals.
- Wire the driver’s IN1 and IN2 pins to two GPIO pins on the Pi (e.g., GPIO 17 and GPIO 27).
- Connect the driver’s GND to the Pi’s ground and the +5 V to the motor’s power source.
- Add a small capacitor (100 µF) across the motor’s power leads to smooth out spikes.
Test the Motor
Run a quick Python script to spin the motor forward for two seconds, then reverse:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
IN1 = 17
IN2 = 27
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
def forward():
GPIO.output(IN1, GPIO.HIGH)
GPIO.output(IN2, GPIO.LOW)
def reverse():
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.HIGH)
forward()
time.sleep(2)
reverse()
time.sleep(2)
GPIO.cleanup()
If the motor whirs as expected, you’re good to go.
Programming the Scheduler
Why Not Use Cron?
You could schedule feeds with Linux’s cron, but a small Python script gives more flexibility—like adjusting portions based on the day of the week.
The Feeding Script
Create a file called feeder.py:
import RPi.GPIO as GPIO
import time
import datetime
GPIO.setmode(GPIO.BCM)
IN1 = 17
IN2 = 27
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
def dispense():
# Spin motor forward for 0.8 seconds (adjust for your cup size)
GPIO.output(IN1, GPIO.HIGH)
GPIO.output(IN2, GPIO.LOW)
time.sleep(0.8)
GPIO.output(IN1, GPIO.LOW)
GPIO.output(IN2, GPIO.LOW)
# Define feeding times (24‑hour format)
schedule = {
"07:00": "morning",
"12:00": "noon",
"18:00": "evening"
}
try:
while True:
now = datetime.datetime.now().strftime("%H:%M")
if now in schedule:
print(f"Feeding {schedule[now]} at {now}")
dispense()
# Wait a minute so we don’t feed twice in the same minute
time.sleep(60)
time.sleep(10)
except KeyboardInterrupt:
GPIO.cleanup()
Run it with python3 feeder.py. The script checks the clock every ten seconds and triggers the motor at the times you set. Adjust the schedule dictionary to match your dog’s routine.
Running on Boot
To make the feeder start automatically after a power loss, add a line to /etc/rc.local before exit 0:
python3 /home/pi/feeder.py &
Now the Pi will launch the feeder script each time it boots.
Testing and Tweaking
Dry Run
Fill the hopper with a few kibble pieces and watch the motor dispense. If the portion is too big, shorten the time.sleep(0.8) in the dispense() function. Too small? Lengthen it a bit.
Real‑World Test
Leave the feeder running for a day while you’re at work. Check the leftover kibble in the morning—if it’s consistent, you’ve nailed the timing. If Max seems hungry, add a second dispense call for that meal.
Adding a LCD
If you want a visual cue, hook a 16×2 LCD to the Pi’s I2C pins (GPIO 2 and GPIO 3). A quick library like lcd lets you print “Next feed: 12:00” on the screen. It’s a nice touch for the tech‑curious pet parent.
Safety Tips
- Secure the wiring. Loose wires can short out and damage the Pi.
- Use a fuse on the motor’s power line to protect against overload.
- Keep the hopper sealed when you’re not feeding; pests love dry kibble.
- Never leave the Pi unattended if you’re testing new code. A stray command could spin the motor forever.
Wrap‑Up
Building a smart feeder with a Raspberry Pi is a rewarding weekend project that saves you from juggling bowls and meetings. The core idea is simple: a tiny computer, a motor, and a bit of code. From there, you can add Wi‑Fi alerts, voice control, or even a camera to watch Max’s happy face as he eats.
I hope this guide gets you feeding on autopilot. When you see your dog wag his tail at the exact moment the motor clicks, you’ll know the effort was worth it.
- → How to Build a Voice‑Controlled Smart Light Switch with Raspberry Pi for Under $30 @techdiyhub
- → How to Build a Raspberry Pi-Powered Smart Home Hub from Scratch @techcraftinsights
- → How to Build a Smart Home Hub with a Raspberry Pi for Under $50 @techandtinker
- → Step-by-Step Guide: Build a Raspberry Pi Smart Light Switch for Under $30 @techandtinker
- → How to Create an Interactive Web‑Controlled LED Matrix Using Node.js and Raspberry Pi @craftcodeacademy