I was inspired by Peter Weissbrod's post: how to keep hungry tigers busy in the early morning to build my kitten Lillie an automatic feeder.
I hoped to build this on a Sunday morning, so it was imperative to keep the design as minimal as possible.
- Raspberry Pi (any generation) $5-30
- USB Wifi Adapter & SD Card ~ $2
- Micro USB Cable and Power Adapter ~ $2
- Micro Servo (TowerPro SG90) ~ $4
- Cable ties
- 1 Gallon Milk Bottle (Preferably empty)
- Double Edge Razor Blade.
Compile the required parts.
My first issue was the servo's connector was a three pin connector
[ SIG | V+ | GND ]. If you are using a Raspberry Pi Zero, I recommend cutting and soldering to pins
[ 7 | 4 | 6]. If you have a different model or prefer not to solder, then you need someway to connect the servo to the raspberry pi pin headers; this is where the razor blade comes in. I took the razor blade and with great care cut spliced the SIG pin (orange cable), separating it into two parts.
Then using the soldering iron, I melted a small slit in the side of the milk cap and secured the control horn into the milk bottle cap with a screw (that came with servo).
I then carefully positioned the servo next to the opening of the milk bottle, and using two small cable ties I attached it to the neck of the milk bottle, using the existing blue milk bottle ring.
I then cut open the bottom (now top) of the milk bottle, to be able to refill with cat food.
Using cable ties, I then attached the raspberry pi to the side of the milk bottle. And using a shoe lave and screw attached it to the wall.
Plugged the servo directly into the raspberry pi:
[SIG Orange] -> [GPIO 4] (pin 7) [V+ Red] -> [5v] (pin 4) [GND Brown] -> [GND] (pin 6)
- Setting up the SD card.
There is an awesome bit of software called PiBakery that lets you setup, config, and flash Raspberry Pi SD's cards. I highly recommend it as an easy way to setup up a headless Raspberry Pi.
Although a JS programmer at heart, I thought that python was a better hammer for this nail.
- I first made a basic program that would open and close the servo:
import RPi.GPIO as IO import time pinOut = 4 IO.setwarnings(False) IO.setmode (IO.BCM) IO.setup(pinOut,IO.OUT) p = IO.PWM(pinOut,50) def openFeeder(): print('open feeder') p.start(2.5) p.ChangeDutyCycle(7.5) time.sleep(0.75) p.ChangeDutyCycle(2.5) time.sleep(0.5)
- After verifying that this was successfully opening and closing the servo, I then whipped up a minuscule Python Flask server so that I could remote trigger the Feeder: Pet Feeder Gist
The server is now running on the raspberry pi (port 5000), and I can trigger it by opening a browser (making a get request):
or a custom amount of time, if you have a super hungry cat:
- Adding the server as a service
I wasn't certain the best way to ensure that the server would start on boot, and after some research, I decided that the best way was to set it up as a service.
a) Create and save a file:
[Unit] Description=Feeder After=multi-user.target [Service] Type=simple ExecStart=/usr/bin/python /home/pi/feeder_server.py Restart=on-abort [Install] WantedBy=multi-user.target
b) then run:
sudo systemctl enable cat_feeder.service #enable the service
sudo systemctl daemon-reload #refresh service list
sudo systemctl status cat_feeder.service #check if service is running
then you can start and stop your services:
sudo systemctl start cat_feeder.service
sudo systemctl stop cat_feeder.service
The service (server) will now run on boot (& on reboot)
- I setup a static ip address in my router for my raspberry pi's MAC address.
- Setup port forward for port 5000
If you need a little help with this go to: static ip's and port forwarding.
One of the main benefits of having an automatic cat feeder, was being able to remove trigger, and schedule feeding. To schedule feeding, I opted to integrate with IFTTT. Using the maker channel, I was able to then use any IFTTT triggers to activate the feeder.
I have setup two IFTTT applets so far:
- Feed Lillie 8am every morning
- Button to feed Lillie (this shows in my today view widget on iOS)
(this is super convenient when I am late getting home)
You could then come up with some crazy IFTTT recipes / applets.
e.g. Feed my cat when I post a photo to Instagram.
The feeder has been running 2 or more times each day for the past 2 weeks and has run flawlessly. I was pretty surprised It's a super fun project, and extremely convenient.
The only issue that has turned up isn't so much related to the feeder, but more to the fact that Lillie moves her bowel around. This means sometimes we end up with food on the floor... next project: un-moveable cat bowl?
Look forward to part 2
As an extension to this product, I have purchased an Amazon Dash IOT button, that we will attempt to train Lillie to be able to feed at will.