Moisture Sensor Calibration and Tuning #1

A project log for Mycodo - Environmental Regulation System

Bringing industrial automation and regulation to everyone.

kyle-gabrielKyle Gabriel 07/30/2016 at 01:310 Comments

Before beginning to talk about today's topic, I wanted to briefly say the SIMB conference I just returned from was a huge success. I was able to listen to a lot of great talks and share ideas with many great scientific minds. I also won the Carol D. Litchfield Poster Presentation Award in the Environmental Microbiology category, and wanted to share that poster, which briefly covers my graduate research.

Having just returned home, I decided to relax and do some light data analysis of the sensor data I collected while out of town, and discuss the process I went through to calibrate the analog to digital converter (ADC) for the soil moisture sensor placed in a potted plant.

Since different soils will vary in electrical conductivity due to variance in substrate composition, it's necessary to calibrate the ADC and probe to a particular soil in order be able to more accurately measure the moisture. The first step is to ensure the maximum voltage being returned from the moisture probe doesn't exceed the maximum detectable voltage of the ADC. The particular probe I'm using, the SparkFun soil moisture sensor, returns a voltage between 0 and the input voltage, depending on the conductance of the soil. The more wet the soil becomes, the higher the conductivity, and the closer the sensor output voltage will be to the input voltage.

I have two voltages I can easily use from the Raspberry Pi as input to the sensor- 5 or 3.3 volts. The MCP3424 ADC I'm using has a maximum detectable voltage of 2.048 volts, and requires the use of a voltage divider (Figure 1) to reduce the measured voltage below 2.048 volts.

Figure 1 | Voltage divider with resistors Z1 and Z2 (courtesy of Wikimedia).

The voltage ratio for this voltage divider is:

Rearranging to solve for Vout yields:

Two 10 kOhm resistors were chosen, which reduced Vout to 1/2 of Vin. This voltage divider would reduce 5 volts to 2.5 volts, or 3.3 volts to 1.65 volts. Our only option to yield an output voltage within our target range (with this particular resistor combination) is the 3.3-volt input.

The next step was to submerge the sensor in the soil and measure the voltage when the soil is both dry and wet to determine the significant detection range. The measured voltage will be converted to a configurable condition, which in this case was the "moisture" of the soil (to which the %-sign was the unit). Therefore, 0% soil moisture would be equated to the voltage returned when the soil is dry, and 100% soil moisture to the voltage returned when the soil is saturated with water.

I planned to use the SIMB conference as an opportunity to collect a week's worth of data in order to have enough to effectively calibrate. I set the recordable voltage range to the maximum the ADC could measure, from 0 to 2.048 volts, thus ensuring the measurable voltage would fall within the detection limit of the ADC. Since the soil of plant I was testing had an unknown initial moisture content, I decided to begin my measurements after watering the plant then measure for several days as the soil dried from the water being taken in by the plant and evaporation.

Over the next week, the soil changed from saturated to dry. The recorded voltage started at 1.27 volts and ended at 1.16 volts. It wasn't necessary to allow the soil to become completely dry, as this would be unhealthy for the plant (and most likely impossible due to the high humidity). Rather, it only had to dry to the degree that would be useful for triggering a watering system. Several days without watering was more than enough to accomplish. In fact, it probably became dryer than I would normally have allowed it to become. Using this data, the ADC and soil moisture sensor combination was calibrated to convert 1.15 to 1.3 volts to a scale of 0 - 100% moisture. I collected a few hours of data, completely saturated the soil again, and recorded a few more hours of data (Figure 2).

Figure 2 | The first few hours of voltage and moisture data recorded after setting the new calibration, then adding water to saturate the soil.

This moisture range is what's used to trigger relays or an input to a PID controller to regulate a certain moisture level. There can be further calibrations, but this initial calibration has already enabled a much higher resolution of moisture detection. The initial voltage range of 0 - 2.048 volts converted to a dry-to-moist range of merely one percent (72% to 73%). The new calibration of 1.15 - 1.3 volts yielded a much greater resolution, with a range of ~10% to ~90% moisture. This increased resolution will enable more accurate moisture measurements and ultimately a finer control of watering.

One of the next logs will include wiring the relays, enabling the modulation of water pumps and testing of the effectiveness of different watering methods.