A lot of hobby suppliers sell soil moisture sensors with a printed circuit probe and some electronics. Soil resistance varies with moisture - more water = less resistance. It also varies with temperature, but that's a subject for another day. The probe consist of two electrodes in the ground, and a circuit to gauge the resistance between them. The picture shows my probe and my wife's geranium (I think it's a geranium!). Normally the probe would be stuck into the soil, with just the wires emerging. This one I bought without electronics, because I know about The Problem!
The Problem is that the cheap sensors use DC. But metal (electrodes) plus DC = electrolysis = corroded electrodes. So a better solution is to use AC, which at least reduces electrolysis.
When I started this little project I needed to get the order of magnitude of the probe resistance, so I used a multimeter (DC!) thinking it would do for rough and ready. But what happened was that I was getting reading all over the place, in the 100K to many megohm range. Then I got a negative reading. So I switched to DC volts measurement and got up to 200mV. I wonder how many germaniums I'd need to power my house?
Anyhow, here's my circuit.
The 100K potentiometer and the resistance of the probes form a voltage divider. The Arduino generates a square wave at 100Hz which is AC coupled to that voltage divider by C1. Hence there is no net DC across the probe electrodes. Meanwhile, the analogue input of the Arduino is held at 2.5V DC by the 100K voltage divider. The AC across the probes is AC coupled into the analogue input by C2. Hence the voltage at the analogue input will be switching plus and minus from 2.5V. The analogue input can measure voltages between 0V and 5V with 10 bit (1024 steps) resolution.
The program measures the analogue voltage just after each output change, at about the point marked X and Y on the little waveform in the middle of the schematic. Then it calculates the difference, yielding in effect the peak to peak voltage. The lower the probe resistance, the smaller that difference will be. Possible values are 0 to 1023. The potentiometer is adjusted for about 500 with soil of the target moisture. The program also contains some low pass filtering to remove any random fluctuations (noise) in the readings.
The program is built on a simple "superloop" multitasking framework, so more tasks can easily be added.
. And here is the program ...