Resistive Soil Sensors

10/18/18

Categories: Electronics Tags: Modules

~/contents

Rambling notes on resistive sensors. I picked up a handful of “Flying Fish” resistive soil sensors to experiment with, they average around 50c on Aliexpress. This model is a 4-pin soil moisture hygrometer that detects soil humidity. It has analog and digital out, the analog value varies depending on the operating voltage, which is 3.3 to 5v. Digital out would be for wet/not wet, most indications will want to use analog readings. These inexpensive resisitive sensors are infamous for having probes that corrode quickly compared to the more expensive capacitative sensors on the market, and this is a common problem for resisitive soil moisture sensors in general.

Sensor Corrosion From Electrolysis

A major issue with these cheap sensors is the corrosion of the electrodes they are sold with, which skews the readings. Corrosion can occur quite rapidly. These sensors use a DC drive configuration and each time the sensor powers on the coppor atoms on the positive electrode prong are being ionised and transported to the negative electrode by the moisture in the soil. There they are deposited and become copper atoms again. As a result, the positive electrode steadily corrodes.

One way to slow corrosion is to only power the sensor when taking a reading. This is a good practical measure for any type of sensor setup. Indoor plants probably only need to be checked every half-hour or so. Outdoor plants, especially in very hot climates, will need to be checked more often. This isn’t a fix, however; the shipped electrodes will still corrode and have to be replaced.

Corrosion-Resistant Electrodes

It’s a good idea to replace the shipped electrodes with a different material. In their post Aeroponic All-year Greenhouse on a Budget, hyperkante suggests using graphite, specifically by harvesting lead from pencils. I tried this to see how doable it really was, and unfortunately had little success. I was also concerned the lead in a #2 pencil was too thin and would too easily break, and I wasn’t sure of the quality of graphite in cheap pencils. You can usually purchase woodless graphite pencils for around $1 each and you can read about the blackness/hardness scale here, essentially hardness correlates to clay content and blackness to graphite content. In Pencil drawing of a sensor actually is a sensor researchers experimented with different levels of graphite hardness in graphite piezoresistive sensors.

Another option is using gypsum, or plaster of paris, to encase the prongs. Vander Lee Vinyeard discusses this in Gypsum Sensor Casting, as does Cheap Vegetable Gardener in Best DIY Cheap Soil Moisture Sensor. Gypsum will eventually break down, and I have read complaints that the sensor readings are less accurate because of moisture retention by the plaster.

Alternately, you can just use a long pair of nails or screws. They’ll still corrode, but they’re cheaper and easier to replace as you probably have a box of them lying around somewhere.

Use Alternating Current

An AC-driven sensor will allow you to bypass electrolysis somewhat, but requires an additional digital pin. The probe is in series with a resistor, forming a voltage divider, and the center of the divider is connected to an analog input. The voltage divider is connected between the two digital outputs. Andrew Frueh provides a basic example in the post, The Soil Moisture Sensor and associated code. They recommend pairing this with a Soil Temperature Sensor and kindly provide the deets.

Use a Capacitative Sensor

This is the only way to avoid the corrosion issue. The capacitative sensors are hermetically sealed, so there is no exposed metal to corrode. They tend to average about $1.50 - $2 on Aliexpress. They still need to be weatherproofed for outdoor use. Looking at the schematics and PCBs online, it looks like the majority of the Chinese-manufactured sensors are 555 circuits. These sensors are built with a PCB designed to be used as a probe. Zero Characters Left has an interesting post, PCB as a Capacitive Soil Moisture Sensor, that explains how this works. In Remote flower watering and monitoring Guido Socher also discusses the use of insulated PCB or sheets of metal as capacitative sensors (and incidentally, doesn’t seem to think much of graphite).

There are a variety of these sensors available, including the wireless open-source Chirp, and these range all the way to sensors run by ESP8266 that also measure temperature and humidity. Another benefit of these sensors is they can be connected via I2c, so you can have a lot of sensors controlled by one device without having to expand IO pins.

Other Circuit Ideas

Biotanicalls NPN sensor costs about 10 cents in common components and is easy to construct. Another approach is the use of a 555 timer, and you can find many schematics online. EME Systems provides some very detailed information on this in Conductivity with the BS2/OWL2 and notes the issue of galvanic currents affecting sensors in proximity and speeding their corrosion (in the case of DC circuits).

Weatherproofing

Outdoor use of these sensors require waterproofing the circuitry, including a conformal coating on the circuitboard, soldered joints, etc., as well as heatshrink or other protective tubing on wires, and just being generally smart about device placement relative to the elements. Ideally one would use a silicone conformal coating, but you could also try polyester or epoxy resin or something like PlastiDip.

Calibration

These sensors must be calibrated. Readings will vary between sensors based on the electrode material, the type of sensor circuit, and the soil itself, as well as how far apart the probes are, so if you make your own sensors you need to make sure the probe distance is fixed. Temperature will change the readings, so if you need very precise readings you will need to pair with a soil temperature sensor. Probe corrosion will change the readings, some probe materials will react to moisture differently (for instance, I found the graphite does appear to retain a little moisture when I conducted dry air vs. water submersion tests).

If outputting a 10-bit signal the range will be 0 to 1023. I found all the flying fish sensors returned higher values when dry and lower values when wet. Attempting to calibrate with the potentiometer doesn’t have much effect (values change by 20 to 50 at best).

To calibrate all these different sensors for testing relative to the soil I’m using, I took a basic air / submerged reading, then I measured a baseline dry value when the sensors are in a pot of bone-dry soil, and a baseline wet value when the sensors are in a pot of water-saturated soil. Arduino C map function does the heavy lifting and allows us to get all these different sensors on the same page, so to speak.

map(value, fromLow, fromHigh, toLow, toHigh)

map(currentValue, dryValue, wetValue, calibratedDryValue, calibratedWetValue)

A pythonic equivallent would be

def arduino_map(x, in_min, in_max, out_min, out_max):
    return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min

Most of my sensors settle down once they’re in soil, but if there’s a lot of variance in analog readings Chris Ruppel suggests input smoothing.

Corrosion Experiments

I decided to drive a series of sensors hard (reading about every 10 seconds) to see how quickly they will corrode. For the first group, I used one Flying Fish as a control, one with graphite electrodes and one with screw electrodes. This was to compare the speed of corrosion across different materials. My second group included an AC sensor with Flying Fish electrodes and an NPN sensor with Flying Fish electrodes, to compare the speed of corrision with different types of circuits.

SENSOR | AIR | WATER | DRY SOIL | WET SOIL
Flying Fish Control | 989 | 370 - 400 | 300 | 180 ~
Flying Fish / Screw Electrodes | 989 | 530-630 | 600 | 390
Flying Fish / Graphite Electrodes | 895 / 795 | 190 / 220 | 300 | 101
AC Circuit / FF Electrodes | 615 / 630 | 1022 | 775 | 1022
NPN DC Circuit / FF Electrodes | 120-130 | 750 - 780 | 415 | 755~

Preliminary testing found the graphite was highly variable until I put it in soil, then it settled down. I noticed for my wet readings the control sensor’s value would steadily climb about one point per second from the initial value of 220. Since my dry soil reading was only 300, this was worrisome, but I noticed that when I stopped the test and waited a few seconds, then restarted, the value had dropped again. My frequent 1 second readings, which were useful for debugging the setup, were affecting the sensor readings.

Observations

The flying fish electrodes corroded quite quickly. The NPN corroded the most quickly, but both the AC and Control began to show signs of corrosion within the first day and by the fourth day all had some rust. The screws and lead exhibit no corrosion yet.

My readings are kind of all over the place, and temperatures recently dropped and that appears to be affecting them as well. But the control continues to steadily climb, whereas the graphite and screw electrodes, which are driven by the same type of module, stayed within an expected range.

Additional resources: