Search This Blog

Sunday, February 23, 2020

"Tomato Pi" & "Scarecrow Pi"-- Raspberry Pi in our urban garden

Last summer my fiance and I got really excited about gardening and raising vegetables on our back patio. We have a really nice sized garden bed that my dad built for us and over the course of a couple of months, we were getting some really nice growth out of the tomato bush and peppers that we had planted. Unfortunately, we noticed that one of our tomato plants wasn't growing as well as we hoped and we discovered the local urban wildlife was enjoying the fruits of our labor before we ever had a chance to. So I decided to get making and see how we could use the Raspberry Pi to help us with our urban gardening challenges.

**The programs that I used for the "Tomato Pi" and the "Scarecrow Pi" are embedded below at the end of this post.

Project #1: "Tomato Pi" soil sensor

capacitive sensor
Our first task was to make watering our tomato plant more efficient and accurate for a better fruit outcome. Inspired by the Raspberry Pi agricultural work of Chris Regini and Melanie Shimano, I jumped online and purchased some inexpensive moisture sensors and got to playing.

While shopping, I discovered that there are two types of moisture sensors you might use with your Raspberry Pi or Arduino-- a double-pronged resistive sensor that outputs both digital and analog data, or the capacitive sensor that outputs only analog data. I'd read numerous blog posts stating that the resistive sensor was prone to corrosion when left in soil over time, so I purchased a couple of capacitive sensors, which sounded as if they would hold up better if left in the soil for an extended period of time.

However, if using a capacitive sensor you will also need to use some type of analog to digital converter, as the Raspberry Pi does not include an analog pin. You can purchase an MCP3008 analog to digital converter pretty cheaply for the project (great instructions on how to do this on Maker.Pro website), which I did, before also realizing that my Explorer HAT Pro also has an analog to digital converter pin. Using the Explorer HAT Pro and accompanying python module made it SO easy to set up the moisture sensor!

email notification from Tomato Pi
The final step was testing the sensor to determine what values meant good soil moisture, too little moisture or too much moisture. We also programmed the Pi to send an email every 6 hours with a soil moisture update so that we knew whether we needed to go out and water or leave the plant alone.

While I still have to up my "packaging game" (I know this set up isn't the fanciest or prettiest) we were pretty happy with the results and reliability of the sensor.


Project #2: "Scarecrow Pi" motion-activated wildlife camera & scarecrow

One of the major annoyances of having an urban garden is discovering that the local birds and squirrels are getting into our vegetables before we are! So I decided to play with some automated solutions to our garden pest problem.

Building off the idea of wildlife cameras, I first put together a motion-activated camera to capture the culprits in action. (Really I wanted to use a distance sensor so that the camera would only go off if an animal got within a certain distance of our planter box, but I haven't yet got one to work so...)

I also wanted to incorporate some type of scare tactic to keep animals out of our plants (without hurting them!), so I decided on the servo motor. And while the scarecrow itself doesn't yet look like a scarecrow (I'm thinking I'll hire a student to build me a better looking scarer), shiny materials are said to keep birds away so as far as we can tell, having the motor shake shiny paper in front of the birds when they set off the sensor seems to be working just as well.

In order to run our "scarecrow" headless I also programmed the Pi to autostart the program on boot, and I programmed a "shut down" button so that I can shut down properly when I need to. As for power, I'm currently running the Pi on a solar powered battery pack-- although I'm thinking about just running an extension cord to the garden box as the battery, even though solar powered, doesn't tend to last more than a day. I still need to track down some of these batteries that I've seen others use more successfully for multiple days.

I still need to adjust the sensitivity of the motion sensor, and my next steps will be to update the camera to take video and stream online, but in the meantime, this is definitely doing the trick!


Tomato Pi code:


Scarecrow Pi code:


Learning resources:

Soil moisture sensor

https://maker.pro/raspberry-pi/tutorial/interfacing-soil-moisture-sensor-with-raspberry-pi
https://www.element14.com/community/community/raspberry-pi/raspberrypi_projects/blog/2017/08/23/iot-garden
https://gpiozero.readthedocs.io/en/stable/api_spi.html#spi-keyword-args
https://cdn-learn.adafruit.com/downloads/pdf/reading-a-analog-in-and-controlling-audio-volume-with-the-raspberry-pi.pdf
https://learn.sparkfun.com/tutorials/soil-moisture-sensor-hookup-guide/all

With ExplorerHAT Pro

https://github.com/pimoroni/explorer-hat/blob/master/tutorial/welcome-analog.py

Shutdown button

https://core-electronics.com.au/tutorials/how-to-make-a-safe-shutdown-button-for-raspberry-pi.html

Servo motor (for moving scarecrow)

https://gpiozero.readthedocs.io/en/stable/api_output.html
https://projects.raspberrypi.org/en/projects/grandpa-scarer/3