Skip to content
Wish Lists Cart
0 items

DIY Cat & Dog Feeder Using Raspberry Pi

18 Jan 2024
DIY Cat & Dog Feeder Using Raspberry Pi

Greetings, animal lovers, today we are going to make an automatic pet feeder using the Raspberry Pi kit PicoBricks. We have shared the necessary 3D printing files and Python codes in the article. Let's get started then.

Our pets, especially cats and dogs, get hungry very often. You may sometimes feel too lazy to refill their food. This is quite normal. I too often feel lazy to keep refilling my beloved cat Oslo's food bowl :).

That's why I decided to prepare a very useful project both for myself and for you: raspberry pi cat feeder.

If I were to list the features of our amazing robot:

  1. Thanks to its automatic timer feature, it automatically refills the food compartment at the intervals you set.
  2. The robot detects when the food is finished thanks to HC-SR04 (LDR), and a warning appears on the OLED screen and the robot makes a beep sound.
  3. Your pet can develop a placebo effect as it makes a beep sound while dispensing food.

Great features, aren't they? Let's then learn step by step how to make a DIY automatic cat and dog feeder.

Wiring Diagram


Step 1: Let's Print with a 3D Printer

One of the best aspects of this project is the opportunity for 3D printing. This way, you can create your own pet feeder at home for free. 

Don't worry, I have shared the necessary STL files below:

Download 3D STL Files

Let's Load the Codes onto Our Raspberry Pi

You can easily load the codes I will share below from BricksIDE or any application that supports Raspberry Pi. If you don't know how to do it, you can read our article:

How to Use PicoBricks with Micropython?

Here are the codes:


import time
from machine import Pin
from machine import I2C
from picobricks import SSD1306_I2C
from machine import PWM
from math import fabs
import utime

i2c = I2C(0, scl=Pin(5), sda=Pin(4), freq=200000)
oled = SSD1306_I2C(128, 64, i2c, addr=0x3c)
pwm_1 = PWM(Pin(21))
buzzer = PWM(Pin(20))
trigger = Pin(15, Pin.OUT)
echo = Pin(14, Pin.IN)
def getDistance():
   while echo.value() == 0:
      signaloff = utime.ticks_us()
   while echo.value() == 1:
      signalon = utime.ticks_us()
   timepassed = signalon - signaloff
   distance = (timepassed * 0.0343) / 2
   print("The distance from object is ",distance,"cm")
   return distance

def CalculateAngle(angle):
   angle = fabs((angle * (6000 / 180)) + 2000)
   angle = round(angle)
   return angle

# Configure the hardware timer
timer = machine.Timer()

# Define a global variable to store the elapsed time
elapsed_time = 0
# Function to be called by the timer interrupt
def timer_callback(timer):
    global elapsed_time
    elapsed_time += 1

# Configure the timer to call the callback function every second
timer.init(freq=1, mode=machine.Timer.PERIODIC, callback=timer_callback)

# Main loop
while True:
    # Print the elapsed time every 5 seconds
    oled.text("It'll give food",0,0)
    oled.text("in every",0,10)
    oled.text("12 hours?",0,20)
    distance = getDistance()

    if distance < (5):
        oled.text("FEEDING TIME",10,30)

        oled.text("{}".format("Mama Bitti"), 0, 0)
    if elapsed_time % 10 == 0:

    # Sleep for a short duration to reduce CPU usage

And... that's it. Now you can fill the food bowl and give your happy cat a belly rub.

If you have any questions, don't hesitate to ask. Take care :)

Prev Post
Next Post

Thanks for subscribing!

This email has been registered!

Shop the look
Choose Options

Edit Option

Have Questions?

Back In Stock Notification


Product SKURatingDescription Collection Availability Product Type Other Details
this is just a warning
Shopping Cart
0 items
Same Day Shipping No Extra Costs
Easy Returns Guarantee Return with Ease
Secure Checkout Secure Payment