Using the Raspberry Pi to keep the plants alive
I was looking for a good excuse for a Raspberry Pi project when we started talking about driving back to Wisconsin rather than flying. I’ve never done the 34 hour drive before and wasn’t planning on doing it soon, but Covid changed that. Soon enough it became a reality and I found my perfect pi project: keeping the plants alive.
After writing a decent amount of assembly in the wonderful Nand to Tetris course and my own foray into reversing x86 binaries, it was a joy to get back to Python. I’ve never used Flask before, and it has been years since I did anything web related.
Hardware
- Raspberry Pi 4 4GB (CanaKit) – Amazon
- Soil Moisture Sensor (Capacitive)
- Pump x5 (12V Peristaltic) – Amazon
- Analog to Digital board (ADS1115) – Amazon
- 12V Power Supply – Amazon
- Extra Tubing – Amazon
- Assorted jumper wires – Amazon
Total cost was around $230. Definitely not the cheapest option, but cheaper than replacing all the plants. And more fun.
You could also get by with one pump providing water for all the plants. I went with one pump per plant, since they all have different watering needs. Plus if one pump dies, only one plant dies. I considered using an extra pump for our favorite plant (don’t tell the rest), but didn’t. All the pumps worked for the month we were gone.
Software
As much as I was excited seeing plaintext sensor values being served by the rpi, I had to find something a little more exciting. This was around the peak of my girlfriends Animal Crossing addiction (cue the Animal Crossing will steal yo gurl meme), so I asked her to take some screenshots.
Yes, my character is the one with the full head of gray hair. The character that I surrendered after sensing I was encroaching on her territory. Since then she has updated my tent to a house and accelerated my graying hair.
Github: https://github.com/colinkarpfinger/PlantServer
Functionality
- Check RPi temperature and memory usage
- Check each plant’s soil moisture
- View a graph of soil moisture over time
- Water a plant at it’s normal value, or 20% less/more.
- View a live stream of the webcam (helpful for making sure things are actually working)
Architecture
Database Schema
The plant_config table just holds configuration data; which plant is hooked up to which pump (gpio_number) and which soil moisture sensor (adc_channel). This makes it easier to decide how to wire them up later and easily switch channels around if needed.
The duration_pref_seconds is the amount of time it takes the pump to move the amount of water we typically use to water the plant. I just timed how long it took to pump 1 cup of water, and then scaled that accordingly. Some of our larger plants take 2 cups, and the smaller ones take less than that.
The interval_pref_hours was intended to be how often you should water the plant. I was thinking of building in something to automatically water the plants should the internet go down, but ended up skipping this. I figured manually watering them was better than finding a bug where they all got over-watered and flooded the apartment 🙂
It worked!
With any project like this, I figured there was a non-zero chance of forgetting something stupid and killing all the plants. I did have fun trying to plan for everything. Ultimately, it all worked! The plants survived for over a month while we were gone. There was definitely a joy to watering our plants while we were in the middle of nowhere on I-80.
However, I noticed the soil moisture sensor on our plant “Fred” wasn’t changing when watered. I started to wonder if one of the cables came undone, or the pump failed. I tried opening the webcam to see if you could notice the tubing shaking when water was pumping, to no avail. So one day when I had some spare time I was able to write up a Python script to record audio from the webcam. I ran the script, watered the plant, and I heard hear the sound of the pump turning on! Success.
The water in the bucket lasted almost exactly a month. My girlfriend’s calculations were spot on. After studying for the GRE, she has been fed up with any math story-problem, and since I’m a math-loving engineer, I do my best to ambush her with math whenever possible. We expected a little evaporation, and there wasn’t any more than expected. It tends to be fairly humid here, so you might want to put a cover on your water reservoir if you live in a dry area.