catfeeder

Software and tutorial for building your own automatic web-controlled catfeeder built with the RaspberryPi.

What is this and why?

Some cat owners (mostly with flat-only cats) know the problem: You are one or two days not at home. Your cat has enough water, enough toilets with sand filled, etc., but when your cat sees food it will eat it immediately. In many countries you just get a programmable catfeeder with day and time setting, but you get no chance to connect it anywhere and build your own interface.

This is a tutorial, with provided software (as it is and without any guaranty), on how to build your own automatic catfeeder controlled via a web interface. It is build with simple materials you can easily get. You will need a little understand in electronic circuits, Raspberry Pi and manual work. It will first give you a suggestion on how to build a box where you place your catfeeder and then the installing instructions on how to set the software up.

How does it work?

This catfeeder is located in a self-made wood-box and in it is a meat chopper without blades, that holds dry food for cats. The meat chopper is plugged in a wireless socket which gets controlled by a Raspberry Pi. The Pi sets the wireless socket on and off in a time that you can control via the web interface, so that you can portioning it. In the box there is a hole where the food drops out. If you install the light-barrier there is another hole where the cat can put something in, e.g. a textile mouse, to get food reward.

See it in action

feed gif

light-barrier gif

The web interface

There is a secured web interface where you have to login to control the catfeeder:

login

Then ther is a page where you can feed immediately and power on/off the training hole controlled by the light-barrier:

feed

There is also a control center where you can configure your wireless socket and the time settings for the portions of one feed unit:

settings

And of course this web-app is responsive:

responsive

How to build

Electronics

What do you need?

For the light-barrier

The total amount is about 100€ (in Germany) including the wood box, depending on your country's prices.

Wiring diagram

wiring-diagram

Legend

The 433MHz transmitter (in the left) is symbolic as text on the breadboard. You should connect it directly to the Pi via jumper cables.

If you just want the feed function without light-barrier, you only have to connect the 433MHz transmitter. For using the light-barrier function connect also the stuff on the right side of the breadboard as shown in the wiring plan.

After you checked that everything works fine, enlarge the two IR diodes with jumper cables to place it later in the wood box.

Wood box

This is an example of how to build a wooden box, that keeps the meet chopper, Pi, wireless socket, etc. in it. The wood box is a little bit larger than the meet chopper - the dimensions are attached to the one I bought and should only give you a hint and feelings for the ratio. As you can see in the pictures, I have put a raised floor into the box - this is not a must. Initially I wanted to bring the meet chopper a little bit up to place a slide outwards on the box. But I rejected this idea because it works also nice without a slide. Now it's used to put the cable stuff and Pi under it. You don't need to build this raised floor for construction reasons (then you can build the box a little less higher) - do as you want. If you don't want to use the light-barrier / training hole you can also build the box smaller - just adjust it to your meat chopper.

What do you need?

The steps to build are the following:

box1

As you can see my box is a square in the width and a rectangle in the height.

box2

box3

box4

box5

box6

box7

box12

box13

box14

box9

box10

box8

Congrats, you are finished with building the box!

How to Install

Dependencies

First install these packages to your raspbian:

Clone Repository

Clone this repository to /var/www/html/. You can achieve this by directing to this folder and execute git clone https://github.com/DavidKoenig/catfeeder.git

Create database

Create a database, mydatabasename . Please create a new user for this, that has only access to this database (security reasons), mydatabaseuser!

You will be later asked about the name and credentials when executing the deploy script. Type your mydatabasename and mydatabaseuser with mypassword that you created at this step.

Every information for doing this can be found here: https://wiki.debian.org/PostgreSql

Install project dependencies

Run composer install from the root directory of the project

Set permissions

Bash script

Because of the usage of the Raspberry Pi Remote library the python scripts in this project need sudo rights. But don't be afraid, it's all wrapped in a single bash script on which www-data has access and the command for executing this script is hardcoded. But we need to make it accessible for www-data.

To do so add the following at the end of /etc/sudoers:

www-data ALL=NOPASSWD:/var/www/html/cat-feeder/app/Resources/pi/catfeeder-sudo-script.sh

Python scripts

Please make sure, that the scripts in the folder app/Resources/pi/ are all executable and belong to the user pi and the www-data group To do so run the following:

sudo chmod +x feed.py light-barrier.py send catfeeder-sudo-script.sh

for executable right and

sudo chown pi:www-data feed.py light-barrier.py send catfeeder-sudo-script.sh

Further you have to add the user pi to www-data with

sudo usermod -a -G www-data pi

Troubleshooting

If there goes something wrong with cache cleaning when running composer install (it will be mentioned when the error occurs) set the permissions for cache, logs and sessions folder as following (first go to the var folder of the project):

Deploy

You have to do the following steps to deploy the:

    Alias /catfeeder "/var/www/html/catfeeder/web/"
    <Directory "var/www/html/cat-feeder/web">
        Options +FollowSymLinks
        AllowOverride All
    </Directory>

Launch the deploy script

Execute the deploy script with

bash /var/www/html/catfeeder/delpoy.sh prod

You will be asked about several configurations:

After finishing the deploy script, you have to change your password.

That's it you are finished installing the application!

What else to do?

If you want to use the catfeeder outside you local network (from the internet), you have to

These are just hints, I will not provide a tutorial for this, there are enough to find with the search engine of your choice ;-)