For the last two summers, Jess and I have experimented with growing a container garden on our balcony. Plants need water, and a lot of plants need a lot of water. Furthermore, different plants consume water at different rates, and many are sensitive to overwatering. I don't like repetitive work, and I certainly don't want to poke soil every day to check if its moist. We have computers for that.
My goals were to reduce how often I needed to haul water to the balcony, and to eliminate the need to manually probe soil moisture.
Pumping water from a large jug is fairly straightforward, and it turns out that tech-savvy farmers have long been employing electronic moisture sensors for the probing aspect. Many hours were subsequently spent researching different ways to measure moisture in soil, and weighing the tradeoffs.
The most simple method of electronically sensing moisture is resistive. That is, measuring the resistance between two pins inserted into the soil. The resistance will vary with the moisture content: moisture improves conductivity, and resistance falls. Preliminary tests were promising, but this method showed its flaws mere hours later.
As electrons flow from one pin to the other, electrolysis occurs. This results in corrosion, which substantially affects the measured resistance. The effect was substantial enough to entirely void any long-term measurements taken with this method. Clever self-calibration might alleviate this problem, but I felt that was needlessly complex.
Another common method of moisture measurement - one that doesn't necessitate corrosion of the probes - is capacitive. When two metal plates are side-by-side in some medium (even air), the surrounding space forms a capacitor. By measuring the capacitance, we can detect the dielectric permittivity of the surrounding medium. This conveniently correlates with moisture content, just like resistance.
Sadly, my attempts at making a conductive moisture sensor failed. I have some suspicions as to why, and might give it another shot when time permits.
Not Doing It Yourself🔗
I preferred to have this system working now rather than perfect later. Spending $37 on a third party sensor seemed an acceptable tradeoff. I found the Vegetronix VH400 to be reliable, and accurate in its measurements.
Deciding When to Water🔗
Now that I had a way of measuring soil moisture, I wanted to automate acting on that information. Time to write a program and load it on a microcontroller! For this I chose an Arduino. After spending a while playing with Arduino shields to give this thing network capabilities, I decided on a slightly more complex approach. The Arduino would be equipped with a Bluetooth 4 (also known as Bluetooth Low Energy) shield, allowing it to communicate with other devices without wires. No ethernet cables on the balcony!
Most example code for the BLE Shield assumed a mobile app. I felt that was overkill, and I wanted to connect to this over the internet anyway.
I used a Raspberry Pi with a Bluetooth LE dongle to create a Bluetooth- to-Internet bridge for my electronic gardener. The Pi connects to a remote database-driven PHP script.
The PHP script has a web interface for me to monitor moisture levels and set irrigation thresholds. These thresholds are passed back to the Arduino, which decides when to pump water.
The Arduino keeps a watchful eye on soil moisture levels. When it detects that a pot is too dry (as defined by my settings for that particular plant), it checks to ensure that it is daytime (watering plants at night can cause diseases and rotting). If it is an acceptable time to water the plants, the Arduino triggers a pump submerged in a large bucket. The pump is connected to a flow meter to monitor water consumption, which leads to a network of potted mini-sprinklers.