Raspberry Pi controller – Part 1

This is the beginning of my project for a water system for the farm. My Raspberry Pi 3 B+ arrived yesterday. I’m beginning the prototyping for monitoring soil moisture in each of the 12 watering zones of the garden (1/2 acre), control sprinklers in those zones, monitor weather and record total water usage.


Parts so far:



Raspbian is fairly barebones, I used the Stretch Lite install without a desktop. No need for it in this case but I did have to install all the other software components and associated libraries. To access the MCP3008 I’m using the Pi’s SPI interface and a python library from Adafruit.

To get the total number of I/O ports I need I’ll ultimately end up using I2C and SPI. I’ll need 12 ports for moisture sensors, 12 ports for sprinkler control and one for water meter connected to the main line. Which totals 25 ports. I’d like to add weather station features too so there will likely be 2+ Pi’s in the garden, I’ll put one in the green house eventually as well.

A basic test shows the sensor working. You can see below that port 0, where the moisture sensor  is attached, is fluctuating as I put a wet sponge on it. It’ll still need to be calibrated to determine the proper range for dry vs wet. I chose a capacitive sensor over a resistive one. The resistive sensors are fairly crude with two exposed metal prongs you insert into the soil. They’re more likely to corrode and since they measure moisture based on resistance, each sensor will have a different response based on it’s distance from the controller. The wiring itself has a certain resistance to it based on it’s lenght which would add to the resistance of the sensor itself. While each sensor could be calibrated individually I’d rather not have that headache. The capacitive sensors are timing based, they measure the amount of time it takes an on board capacitor to recharge, the recharge time is affected by the amount of moisture in contact with the soil so it’s much more predictable and the way the sensor is constructed it’s less susceptible to corrosion. Although the top portion will need to be encased in resin before putting them outdoors for actual use.


I’m building a Drupal module for all this so it’ll have a nice web interface that can be accessed locally on the farm wifi,  from our house, our phone or an LCD attached to the Pi itself in the garden. If it turns out well enough I’ll make the module freely available.

There are lots of tutorials out there on hooking up a MCP3008 to a Pi so I’ll skip that part as far as the basics go. I’ll post my progress as I go, hopefully I’ll have something working in a couple of weeks.