Previous Posts:
Epidode 1: Forget Me Not: Application
Episode 2: Forget Me Not: The Best Laid Plans ...
Episode 3: Forget Me Not: Setup EnOcean with openHAB
Episode 4: Forget Me Not: Medication System
Episode 5A: Forget Me Not: Using Notify My Android with OpenHab
Episode 6: Forget Me Not: Plant Watering System Design
Episode 7: Forget Me Not: Medication System Demo
Episode 8: Forget Me Not: Using Twitter
Episode 9: Forget Me Not: Sunshine, Lollipops, and Rainbows
Episode 10: Forget Me Not: It's so hot!
Forget Me Not: Episode 11A: Watering System Construction
Introduction
So, I've had it with DX.com and I decided I would design my own soil moisture sensor. I used most of my budget from the challenge to stock my "lab" so that I would have the parts and tools necessary to build most circuits I might design. I'm still waiting for some parts, but that's just how it goes. Having said all that, this blog post will be about designing a soil moisture sensor.
Initial Thoughts
To measure the soil moisture, we would actually be measuring the conductance or resistance of the soil. It will be most conductive when the soil is completely saturated with water and least conductive when void of any moisture.
Simplest First
The easiest way to make this measurement is with a voltage divider where one of the resistors is the soil resistance. Figure 1 shows a simple divider where S1 is the measured voltage. The two probes placed in the soil would be S1 and GND.
Figure 1: Soil moisture sensor based on a voltage divider.
So, the obvious question here is, "How do I select R1?", and it's a really good question. We need more information, particularly about the soil and distance between our probes (S1 and GND). I chose to use a distance of 15 mm, which means when I construct my sensor the probes must be 15 mm apart. I measured the resistance of my dry soil over a distance of 15 mm and it was about 200 kΩ. I then measured a cup of water's resistance over a distance of 15 mm and it was about 50 kΩ. I need to optimize R1 for those boundary conditions, but before we get too much further into that optimization problem let's explore the expected response of such a sensor. We can derive the relation for the probe voltage:
where Vs is the voltage across the sensor probes,
Rs is the soil resistance,
and R1 is our fixed resistance.
Notice anything non-desirable in the sensor response from this equation? If it's not clear yet, let's choose a value of 100 kΩ for R1 and plot the expected response. Figure 2 shows such a response.
Figure 2: Voltage divider response for soil moisture sensor.
How about now? It's not linear! If I wanted to use this sensor I would have to use a look up table, or a function to linearize the response. This isn't completely out-of-the-norm, and for my original purpose of a high and low threshold triggered system, this would serve the purpose. Since receiving the RPiSoC I wanted to eventually implement the ADC functionality to get a soil moisture percentage, so I would like a linear response. Oh, by-the-way if you indeed wanted to use the divider of Figure 1, you could either treat it as an optimization problem or simply use a spreadsheet to determine the best possible value. This is a common problem, and I've also seen a derivation showing that the optimum value is the square root of the minimum value multiplied by the maximum value. This would be (200k*5k)^(1/2) = 100 k and results in a dynamic range of 2.2/1.1 or 2. It's fairly poor, but if you consider the number of components and ease of setup this may be the result for you. (For a proof of the equation look here: arduino - How would I get a full range voltage reading from a pressure sensor? - Electrical Engineering Stack Exchange)
Let's examine another popular circuit for soil moisture measurement that involves an active device. Figure 3 shows a soil moisture sensor circuit that is quite popular. It's everywhere on the internet, and this is the same circuit that was on the Funduino sensor I "purchased" from DX. There is a good DIY on this type of sensor here: Botanicalls Twitter DIY.
Figure 3: Soil moisture sensor implemented using a BJT.
This sensor places the probe resistance into the base resistance, thereby changing the base current as the soil resistance changes. This base current is, obviously, translated into an emitter current and produces an output voltage indicating the soil resistance or moisture level (typical values for a probe separation of 30 mm are R2 = 10kΩ, and R1 = 100Ω). I simulated this sensor for a probe resistance varying between 100kΩ and 400kΩ (probe distance was twice that of my measurements from earlier). Figure 4 shows the results.
Figure 4: Sensor response from the circuit of Figure 3.
This graph is more appealing because it much more linear than the graph of Figure 2, but I'm bothered by the numbers on the vertical axis. From completely dry to soaked soil there is only a voltage swing of just over 300 mV! I'm not convinced either of the two sensors discussed so far are suitable for an accurate moisture level reading.
So, where shall we go from here? I think we should be able to easily get a dynamic range of 4 since the ratio of dry to wet soil resistance is 4. To do this we need to drive a constant current through our "load", where the load is our soil resistance, and measure the corresponding voltage. It's time to crack open the textbooks (Google) and find a nice current source circuit. Here's one: BJT Current Source. Figure 5 shows the current source modified such that the collector resistor is the soil resistance.
Figure 5: Current source soil moisture sensor using a BJT. Output is measured between S1 and S2.
I've set R2 to 10 kΩ and done my analysis to get an appropriate output voltage (S1 to S2) range by using R1 = 40kΩ. There are sites where this same type of analysis has been done, for example: resistors - Choose the resistence with voltage divider sensor - Electrical Engineering Stack Exchange. I've simulated the circuit and the results are shown in Figure 6.
Figure 6: Current source combined with the soil resistance produces a linear output with a dynamic range of 4.
So, there it is; a nice linear output with a dynamic range of 4 (2.5/.625). This is the best I could do in the short time I had; I don't have any diodes yet , so I will likely have to build the second sensor and "deal with it". Hope this helps anyone designing a soil moisture sensor.