Soil moisture sensors are popular among hobbyists who e.g. want to monitor or automatically irrigate their plants.
There are a number of cheap sensors available in the various ‘Chinese webshops’ but those come with a caveat. I will discuss a few and come with ‘solutions’ to some of the biggest problems.
The above sensor is very popular, but in short: it is shit. It is a resistive soil moisture sensor and those come with a big problem: electrolysis. The fact that there is a constant current flowing through the sensor when it is in contact with wet soil will lead to electrolytic breakdown of the very thin layer on the sensor’s PCB, or in other words: after a relatively short period the metal will no longer be on your sensor, but in your soil.
Another issue with this module is that people use the entire module even when that is not necessary. Let me explain with help of a picture:
The image shows the circuit used in the module. It is basically a comparator that when the soil moisture (and thus the resistance) reaches a value that is set with the variable resistor, the output of the comparator (DO) toggles. So far so good. The analog output (AO) on the other hand is directly connected to the sensor. That means that if you only use the Analog Output, you do not need the module at all, just connecting the sensor to an analog input and use an internal or external pullup will suffice.
I suggest you do not use this sensor at all.
The above sensor is more of the same. It is also a resistive sensor and thus has the same problems as the one above. It does not have a digital output, just an analog. Also, because of the exposed electronics on it, it is not really suitable for outside use. I suggest you do not buy this one.
The above sensor supposedly is made from a non-electrolytic sensitive material. It is suggested it is made of carbon. My experience with it is not long enough to say if that is true, but it seems to be fake in that aspect. However, it is definitely useable in combination with some solutions i will suggest later.
The above sensor is a capacitive sensor. That means it does not measure the resistance of the soil but the capacitance of the soil. That means that there is no need to have any bare metal sticking in the soil and therefore electrolysis is not a problem. It has some other issues though: The coating that is used to cover the plates of the ‘capacitor’ sadly does not cover the sides of the PCB. Therefore moisture will eventually leak in and basically turn the capacitor into a resistor that will rot away. Also because of the exposed electronics at the top it is not really suitable to use outside. If you want to use this sensor it would be a good idea to dip or spray it completely into/with PlastiDipR.
Sadly there are some issues with this sensor:
- Some sensors do not use a TLC555 but an NE555. The latter is not working properly with 3v3 which means you have to remove the voltage regulator.
- The 1Mohm resistor (called R4 on the pcb) is not connected to ground on some boards, leading to very slow readings. As this seems to be a problem in the boards design it is easiest solved by soldering a 1Mohm resistor over the Aout and Ground pins.
Realise that capacitive sensors measure other values than resistive soil sensors. A capacitive sensor measures true water content of the soil whereas a resistive sensor in fact measures ion/salt content in the soil, so adding say fertilizer to your soil will change the reading of your resistive sensor but not your capacitive sensor. As such capacitive sensors are better than resistive sensors, but it can be a pain to make sure they are completely watertight. In my experience the often used nailpolish will dissolve over time as does laquer. The before mentioned PlastiDipis a good solution, but adds to the cost of the sensor. The resistive sensor is just much easier.
So what can we do to protect the resistive sensor against electrolysis?
You will read various ‘solutions’ for this:
“You have to feed it with AC”
Yeah, right.Let alone that most of the circuits to do that do not provide AC but just a DC Sinewave or some other form of pulsed DC which does not help at all
“You have to reverse the voltage”
Okay….. apart from the fact that this requires an extra pin, it also takes a lot of time sensitive programming.
There are better solutions:
Use decent galvanized bolts/nails of say 6mm thick and don’t give a fuck. After the growing season take them out, give them a scrub and use again. They will last pretty long.
Only apply a voltage and thus a current to your sensor when you need it.
You really do not need to know the moisture content of your soil every second of the day. Suppose you measure only 4-6 times a day and every measurement takes say 1 mSec. Then you only need to apply a voltage for 4-6mSec a day. That is a lot less electrolysis.
You can do this by feeding the voltage divider that makes up your sensor and pull up resistor simply from an extra pin of your microcontroller and set up a timer to drive that pin HIGH, read the value and drive the pin LOW once every 4-6 hrs. If you do not cherish the idea to use an I/O pin to feed a sensor, the circuits below will do the same. Obviously one should not set an internal pull up resistor when using this option.
There are purists that say you would still need to reverse the voltage for those 4-6 msecs as well, but come on.
The easiest though is to do away with metal alltogether and to use graphite rods. These are current conducting and not subjected to electrolysis or regular corrosis.
It is of course not possible to solder wires to graphite but wires can easily be attached with some heat shrink. The rods as shown here have a combined resistance of approx 10k.