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:

Requirements

Hardware

You will need the following hardware components:

  1. A computer running macOS or Linux
  2. Raspberry Pi with microSD card (and microSD card reader)
  3. Raspberry Pi power supply
  4. Stepper motor and motor driver
  5. 12V power supply adaptor for motor driver
  6. Simple USB powered webcam
  7. Assorted jumper wires
  8. Four 16mm or 20mm M3 screws

Tools and Other Materials

You will also need the following tools and materials:

  1. Wide mouth Mason Jar or blender cup (if you want to avoid using glass!)
  2. Small pet treats or dry kibble
  3. Tools for assembly such as screwdrivers and allen keys
  4. 3D printer (or somewhere you can order 3D printed parts from)
  5. 3D printed STL models

Software

You will need the following software:

1. Assemble Your DIY Dog or Cat Feeder

  1. Prepare your 3D prints. The front of the main body of your print is the side with the dog bone.

  2. Mount your Raspberry Pi to the side of the main body of your pet feeder.

  3. Connect your power source to the Pi.

  4. Mount your webcam to the front of your pet feeder.

  5. Insert the 3D printed stepper motor wheel into your pet feeder.

  6. Place your stepper motor into the motor holder part.

  7. 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.

  1. Set up the Raspberry Pi.
  2. Configure components in the Viam app.
  3. 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

  1. Under the CONFIGURE tab, add the Data Management service to sync data with the Viam app.
  2. 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

  1. Select images to tag with your pet's name.
  2. 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

  1. SSH into your Pi.
  2. Install Python Package Manager:
    sudo apt install python3-pip
    

Add the Logic

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.