Engineering at Home: Scientific Cat Feeding with Raspberry Pi & Lego

Meet Zoey and Jake, whose daily job is to eat, meow, have fun and sleep

As a multi-people household with multiple cats, we as human-beings all love our cats, all trying to keep the cats fed regularly two times a day. We found ourselves constantly asking each other: Have you fed the cats? Sometimes we unknowingly feed the cats separately so that the cats would become bigger and bigger. To keep our kitties healthy, we decided to solve this problem.

What we needed was simple: a timer next to the cat bowls showing us when the cats were fed last time. But more than a timer, we want this thing to be more friendly to our specific use case, maybe with a big button for people to push every time the cats get fed, so that the timer can be reset to keep other people informed. At first it sounded like we just need a $10 timer from Amazon, but why don’t we have fun and make something ourselves?

So this is the plan we came up with, only requiring a basic level of software development and some creativity.

Turned out some fun work could be more useful than we thought.

this Raspberry Pi was a birthday gift few years ago, and finally there’s a use to it

Both my wife and I were big lego fans, so we decided to capsulate the Rpi into a standing device that looks like one of those smart home assistances. We bought a touch screen, a bunch of lego bricks and some Rpi accessories with some wires, buttons and sensors.

The Rpi accessary package contained quite some stuff, from minimum things like cables, light bulbs to motors and motion sensors. For now we just gonna need some basic cables and a button. But who knows? we may even automate the feeding part some day.

It took some patience to connect the capacitor and cables correctly. we were able to refer to those Rpi manuals mostly for high schooler robotic competitions.

Now is the casing part. lego is just awesome enough to make anything you want. Soon we were able to make it stand on itself like a Google Home.

The physical button at the front is obvious enough to see and large enough for people to push easily after feeding the cats.

Now is the coding part. we quickly designed a UI specifically for the screen size. To keep a log of all the button pushes, I setup the SQLite as a minimal database, with data stored on SD card. A mini API layer was developed to handle the button events and the inquiries from the client. Every time someone pushes the button, the event will be written into the DB as a new record. This is for analysis later to see if there are any interesting patterns of how we use the device.

Woohoo! It was almost done. We put a few things together (the web based UI, backend API and button push listener) for some integration test. The Ubuntu OS on Rpi made the whole thing very straightforward.

And it’s all done! It looked like a very simple device, but it solved a big problem for us. Bear with us for the cables left outside.

how about some fireworks?

5 Months Later…

I was surprised by how this little device helped us keeping the kitties healthy. We used it every time we fed the cats, so there have been some logs that we can look at. So I took the SD card out, extracted the data from SQLite DB, and did a simple data analysis with Jupyter notebook.

all the button pushes were logged as timestamps in the meow_events table

Here’s a plot of the counts of feeds everyday since 2020–8–27. From the chart we can clearly see that we fed the cats 2–3 times on average per day. There was more fluctuation on the first few days, mostly because we were playing with the device a lot.

Here’s a histogram of the time (hour of day) when we fed the cats. obviously, in the morning we tended to feed from 8am to 9am, and from 9am to 10am, while in the evening the timing was pretty random. Guess it was because usually the first thing we do after getting up, but it was kind of random because we have lots of other activities in the evening.

This is obviously a very basic device with some basic functionalities, but it was fun applying some engineering techniques to our daily needs. The next step is to further automate the timer reset, by using motion sensor / weight to detect kitties’ behaviors. Hope this inspires you too, and have fun building!

AI/ML engineer in Silicon Valley, Christian, passionate about software and creativity.