Story of automated fish feeder with RaspberryPi
Pavel Kutáč
Posted on February 1, 2022
All started 2 years ago, when a colleague got a Beta fish and brought it to the office. By that day all of us started to learn how to care about aquarium. But our office building is closed every Christmas for almost 2 weeks. That might be too much for the fish without food.
🇨🇿 V češtině si lze článek přečíst na kutac.cz
Before Christmas 2020 we used our smaller tank and moved the fish to a colleague's flat. But during 2021 that tank became an Aquarium PC. So there was no spare tank to move the fish again. Automated fish feeder is must have. But the existing ones are either expensive or not compatible with our aquarium.
For more about side projects in our company, visit profiq.com/blog
3D printed solution
On ThingiVerse.com we have found ideal solution. First, we had to do a small modification to properly attach stepper motor. The first prototype actually worked! But in the tank, we have also snail, not just fish. And the snail’s food was bigger than the bowl in the feeder. So we needed to do the next iteration and print the inner part again with bigger bowls.
Android Things vs RaspberryPi
I got an Android Things kit during Google Developer Days back in 2017 in Krakow, Poland. And I thought I could use it for feeder. However, Google stopped this project meanwhile. I thought it means, that only new features are not coming. But they removed also all images required to make the kit alive. I spent the whole weekend trying to find another solution to make it work, but unsuccessfully. So with colleagues, we decided to use the RaspberryPi which was unused in our office.
After we prepared RaspberryPi and we were able to control LED, we realized what will be the next challenge. The stepper motor driver needs input voltage in the range 8.2 - 45V and a logic voltage between 2.5V and 5.25V. But RaspberryPi needs 5V and has 3.3V GPIO pins. And we had an old laptop power adapter that produce 19.5V. The decision was made. We will use only 1 power supply and the feeder will contain also DC/DC step-down module to power Raspberry.
CRON with Python script and monitoring
RaspberryOS comes with some nice integration into Python, so controlling GPIO (General-purpose Inputs Outputs) is super easy. In some situations, I could call myself a control freak. I wanted to be sure, it will be working flawlessly. So besides some basic logging into the local file, I set up also monitoring with service Healthchecks.io. I was writing about it earlier.And for the worst case, we assigned a static IP address and set up port-forwarding to have access with SSH into the Raspberry.
The python script itself was executed regularly every hour by Linux Cron. And the last feeding time was controlled programmatically. So even during power strike, fish and snail would be fed after that. You can find the full script in our public Gitlab repository.
Visual feedback with non-stop stream to YouTube
Access with SSH, logging, and monitoring might check the software behavior. But as the feeder is a piece of hardware, it is much harder to monitor. So we decided to do a stream with a web camera on YouTube. We have used ffmpeg tool and the prepared script can be found again in our public Gitlab repository.
Everyones know, the developers are lazy. It is not a big surprise we kept everything to the last days. So we weren’t able to optimize streaming enough. The stream was in resolution 640x480px and 15 FPS and it still uses almost 95% of CPU time. So for safety reasons, we used another RapsberryPi just for streaming. If it would not survive, it wouldn’t affect our feeder.
Oh yes, we succeeded. But what about next year's improvements?
This article would be most likely private if the fish or the snail would die. And because you are reading it, they survived. Yaay! And we also have some baby snails. Yaay again! But there is still space for some improvements for Christmas 2022.
Food for the snail is a little bit bigger and sometimes it is stuck with fish food. So nothing or just a small portion fell into the water. It would be helpful to also control the direction of moving and do some shaking when food should fall down. And for sure we need to find a better streaming setting that would allow us to watch the stream in better quality.
Posted on February 1, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.