Project Description




During quarantine, I bought a Raspberry Pi and some sensors from Amazon to learn about IoT programming. After some tinkering, I thought an interesting project to learn would be to build a self-watering garden. Then, I bought some seeds in an attempt to make this useful for more than my own learning to try to actually grow some herbs.

Obviously what I've done here is not the easiest, cheapest, or most effective way to grow herbs. I really just built it to use any and all sensors I could connect to the Raspberry Pi. I don't even know if the herbs will grow well here, but it was a fun project (and I've got some seedlings coming in)!

I also wanted to work on my web development skills, so I built an API to which the Pi can post the sensor readings and a front-end which will render some cool graphics. Since I built the rest of the project in Python and it is my preferred programming language, I chose Flask to build the web app. Flask is incredibly intuitive and simple to work with. I hosted the app on Heroku, since it is so simple to use and has a free "hobby" tier and used PostgreSQL for the database which will store the readings.

The code for the app which manages the garden can be found here on GitHub.

The code for this web app can be found here on GitHub.

System Layout

I'd like to make a better circuit diagram at some point, but this should do for now:

Some more views:


Closeup of environment sensors
Closeup of Raspberry Pi
Closeup of water level sensor and water pump
Closeup of soil moisture sensor

How it Works

I wrote a python script which runs on the Pi, and takes readings from all sensors every 5 minutes (the timing can be changed, obviously). After taking a reading, if the reading is above a certain threshold (indicating dry soil), the pump will turn on for 1 second. I determined this threshold experimentally through trial and error, and I expect to need to modify it over time. I am also very worried about over-watering, so I only allow the pump to run once in a 24 hour period using the automated script. If I press the Touch Sensor the pump will run for 0.5 seconds. Once the readings have been collected and pump run if necessary, the script will post to the web app's API to store the data in Postgres in the cloud.

The full details can be found here on GitHub.

The web app is really simple. There is an endpoint at which the Raspberry Pi can post the latest readings, and some logic to render a set of latest readings in a pretty simple array of charts using matplotlib and mpld3. The code for the web app can be found here on GitHub.

The dashboard by default shows the last 6 hours of readings.

From the dashboard, we can see some really interesting things in the data:

Since this is an mpld3 rendering, you can use the home/zoom/pan icons at the bottom left of the screen to explore the data in more detail.





Questions? Feel free to reach out over email.