DIY Raspberry Pi automatic dog or cat feeder: Full tutorial | Viam
DIY Raspberry Pi Automatic Dog or Cat Feeder: Full Tutorial
Build your own pet feeder, from hardware setup to programming with a Raspberry Pi and Viam.
Introduction
If your pet is as insatiable as mine, you are familiar with waking up to the sound of gentle whining and begging paws—two hours before the alarm.
Summary
By following this tutorial, you'll:
- Build your own automatic pet feeder using Raspberry Pi.
- Train a custom machine learning (ML) model with Viam’s Data Manager to recognize your pet.
- Implement Viam’s Machine Learning and Vision Services to run the model on your robot.
- Integrate a stepper motor and 3D-printed dispenser to release treats when your pet is identified.
Requirements
Hardware
You will need the following hardware components:
- A computer running macOS or Linux
- Raspberry Pi with microSD card (and microSD card reader)
- Raspberry Pi power supply
- Stepper motor and motor driver
- 12V power supply adaptor for motor driver
- Simple USB powered webcam
- Assorted jumper wires
- Four 16mm or 20mm M3 screws
Tools and Other Materials
You will also need the following tools and materials:
- Wide mouth Mason Jar or blender cup (if you want to avoid using glass!)
- Small pet treats or dry kibble
- Tools for assembly such as screwdrivers and allen keys
- 3D printer (or somewhere you can order 3D printed parts from)
- 3D printed STL models
Software
You will need the following software:
- Python 3
- pip
viam-serverinstalled to your board.
1. Assemble Your DIY Dog or Cat Feeder
Prepare your 3D prints. The front of the main body of your print is the side with the dog bone.
Mount your Raspberry Pi to the side of the main body of your pet feeder.
Connect your power source to the Pi.
Mount your webcam to the front of your pet feeder.
Insert the 3D printed stepper motor wheel into your pet feeder.
Place your stepper motor into the motor holder part.
Connect your stepper motor to the motor driver according to the wiring diagram:
2. Configure and Test Your Automatic Pet Feeder
After setting up your robot, proceed to configure and test it.
- Set up the Raspberry Pi.
- Configure components in the Viam app.
- Test your DIY smart pet feeder’s motor.
Test Your Smart Pet Feeder’s Camera
Next, test the camera. Ensure you can see your pet.
3. Use ML to Recognize Your Cat or Dog
Make your pet feeder smart by capturing data using ML models.
Configure Data Management
- Under the CONFIGURE tab, add the Data Management service to sync data with the Viam app.
- Ensure Data Capture and Cloud Sync are enabled.
Capture Images of Your Pet
Collect images of your pet using the feeder.
Create a Dataset and Tag Images
- Select images to tag with your pet's name.
- Add each image to a dataset.
4. Control Your DIY Smart Pet Feeder Programmatically
Use the Viam SDK in Python.
Set Up Your Python Environment
- SSH into your Pi.
- Install Python Package Manager:
sudo apt install python3-pip
Add the Logic
- Implement logic to control the motor based on ML classifications of the camera feed.
async def main():
# Initialize components
...
while True:
# Check camera stream for pet
classifications = await puppyclassifier.get_classifications_from_camera(camera_name)
if found:
# Dispense treat
await stepper.go_for(rpm=80, revolutions=2)
else:
await stepper.stop()
Upgrade Your DIY Cat or Dog Feeder
Consider adding features like sound alerts or multi-pet recognition.
Full Code
The entire code for the project in Python:
import asyncio
...
# Add your full code here
Viam is the fastest way to build a robot. Register for Viam 101 by July 31 for an opportunity to win a UFACTORY Lite 6 arm.