We like to use reservoir-style planters on the back porch to grow cherry tomatoes and basil. They work great as long as you never forget to re-fill them with water … so this project is designed to monitor the soil moisture and send me an email if it gets too dry — future projects might add a valve and a water connection but hey, lets get this part working first.
And some female jumper wires …
You’ll need to solder some GPIO pins onto your Pi Zero — and if I’ve lost you already … be warned. This is not “Instructables” — this post is for folks who know what a RPi is and are looking for some tips on how I hacked this thing together — based on several different sources. For software/operating system, my was project is built using the desktop version of Raspbian Stretch, because it has the python libraries and the python IDLE (Python’s Integrated Development and Learning Environment) built in. I did all the prototyping on a Raspberry Pi 3 because it has all the USB connections for keyboard, mouse, etc — and was just easier. Once complete, I the moved the SD card over the Pi Zero and … Bob’s your uncle as they say in Old Blighty.
Standing on the shoulders of …
This page, https://www.modmypi.com/blog/raspberry-pi-plant-pot-moisture-sensor-with-email-notification-tutorial, created in 2015, gives a very good step-by-step process and also provided the code I used for my starting point.
I just wanted to know when to water the plants — if you wanted percentages and the ability to plot line graphs of your moisture levels (see how this shit escalates? ) then this post is for you https://computers.tutsplus.com/tutorials/build-a-raspberry-pi-moisture-sensor-to-monitor-your-plants–mac-52875
Solving the gmail challenge …
The script featured in the modmypi article attempts to use the python smtplib library for the email function … well I tried to use that with a fresh gmail account that I set up, (yes I set the security to allow less secure apps to send email) … and I could not get it to work.
YAGMAIL to the rescue
I tweaked the moisture.py script to leverage the awesome YAGMAIL project (Yet Another Gmail client). You’ll need to install yagmail using the python package manager … or however you can. I used the python3 version.
pip3 install yagmail[all]
use And it WORKS!
I added this line
python3 /home/pi/Moisture-Sensor/moisture.py &
before “exit 0” in my /etc/rc.local file so the script would run at bootup.
I also used cron to run another little script that uses yagmail to send me a “i’m alive” email once a day …
next up is the valve … inspired by this project http://www.instructables.com/id/Raspberry-Pi-Controlled-Irrigation-System/
Videos that helped me figure this out…
(I used a blob of bluetac to hold my board steady for soldering … not the fancy rig t-shirt boy used)
This video helps you see how the thing must be wired — but I wanted to get emails not just see the light come on!