DEV Community

Cover image for Story of automated fish feeder with RaspberryPi
Pavel Kutáč
Pavel Kutáč

Posted on

Story of automated fish feeder with RaspberryPi

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.

Detail of feeder with bowls and stepper motor

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.

Schema of electrical circuit

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.

Descriptions of parts on the board

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.

Top comments (3)

Collapse
 
martensp profile image
martensp

This is a very interesting solution to the problem. I started thinking about an automatic fish feeder last year when I realized that summer was coming and vacation trips with it. The aquarium in our house appeared only six months ago, and I used to feed the fish myself. And if a two-day cleanse the fish, I think, would have no problem, then our absence for two or three weeks could be fatal for them. In fact, there were two problems: in addition to feeding, we had to solve the problem by turning on and off the light. It turned out that the problem of lighting can be solved easily with a timer. It is inexpensive and easy to use.

Collapse
 
arxeiss profile image
Pavel Kutáč

I totally agree. Basically, we are feeding them from Monday to Friday. No food during weekends. We practice this for 2 years and that's fine. But yes, 2 weeks might be fatal.

And for light, we use also timer. Something like this https://cdn.alza.cz/ImgW.ashx?fd=f4&cd=SD030c&i=1.jpg
But if there is a power strike, timer is not synchronised then. So it happen to us, that there was a light during night and no light during the day. So maybe we will change it to Raspberry too. Because it has always correct time after internet connection is back.

Collapse
 
solbypan4 profile image
Solbypan4

Thanks for sharing