How to Monitor Soil pH and Moisture Level
Contributed By DigiKey's North American Editors
2018-03-29
Maintaining proper soil moisture and pH is a fundamental requirement for plant health, whether applied in large scale agriculture or simple home gardens. To measure these soil characteristics, however, developers need to design cost-effective precision analog signal chains able to convert raw data to useful information required for specific soil measurement applications.
One approach to achieving these goals of precision is to use a reference design with appropriately flexible software. A good example of such a solution is the EVAL-CN0398-ARDZ board and software package from Analog Devices.
This article discusses the applications and requirements associated with monitoring soil moisture and pH before introducing the Analog Devices CN0398 board and reference design. The article explains how the major components used in the CN0398 design address key design requirements and examines their role in the overall application. The article finishes by showing how developers can use the CN0398 board and associated software package to rapidly evaluate and customize soil monitoring applications.
The need for accurate soil measurement
The need to maintain proper soil water content and pH level is a fundamental requirement for plant growers at any scale of production. Soil water deficiencies directly translate into reduced photosynthesis for any plant, as well as a decline in other biological processes such as nitrogen fixation in important legume crops such as soybeans.
Similarly, changes in soil from fertilization or natural phenomena can dramatically impact soil pH, leading to a reduction in essential microbes and soil nutrients. In some crops, improper soil pH in early growth stages leads to lower growth rates and final yield.
Without suitable soil monitoring systems, soil moisture and pH can shift to unfavorable values, resulting in eventual deterioration of plant health. Together, the Analog Devices EVAL-CN0398-ARDZ board and software package provide a complete soil monitoring design that developers can employ directly or modify to meet their unique requirements.
Analog Device’s CN0398 board and reference design were created specifically for use with external moisture, pH, and temperature sensors in soil measurement applications. Its on-board circuitry comprises a complete multi-sensor design required to produce moisture and pH output data accessible through its serial interface. Even with its extensive functionality, the design consumes a maximum of only 1.95 milliamps (mA) and provides power saving features, including the use of pulse-width modulation (PWM) for powering external sensors.
Developers can use the CN0398 to jumpstart custom hardware designs or use the board with the Analog Devices EVAL-ADICUP360 Arduino-compatible baseboard. Designed as an Arduino shield, the CN0398 plugs directly into the baseboard providing a platform for rapid application development.
To speed software development, engineers can take advantage of Analog Device’s ADuCM360_demo_cn0398 open-source software package designed for use with the CN0398 sensor board, ADICUP360 baseboard and Analog Device’s CrossCore Embedded Studio. Along with basic drivers and system support utilities, the software package includes complete C++ source and header files, including a complete soil measurement software application.
The combination of the Analog Devices board set and software package provides developers with a complete hardware design and software application ready for immediate use in soil measurement applications. Just as important, the CN0398 hardware reference design and sample software provides the blueprint for rapid development of custom soil measurement systems able to meet the unique requirements of these applications.
Sensor signal processing
The CN0398 hardware design includes three separate subcircuits for external moisture, pH and temperature sensors. Each subcircuit provides all the circuitry required to interface with each type of sensor. As a result, developers need only plug each sensor into its corresponding connector on the CN0398 board and provide power to begin sensor operations. This functionality is built around the Analog Devices AD7124-8, which combines an extensive signal conditioning front end with a 24-bit sigma-delta (Σ-Δ) analog-to-digital converter (ADC) (Figure 1).
Figure 1: With its integrated signal chain and ADC, the Analog Devices AD7124-8 simplifies design of multi-sensor systems required for soil measurement. (Image source: Analog Devices)
The AD7124-8’s signal multiplexer can route eight differential or 15 single-ended inputs through its integrated programmable signal chain to the on-chip Σ-Δ ADC and digital filter for conversion and conditioning. Developers use the AD7124-8’s serial interface to connect the device to an MCU host for device control and data conversion.
Because of its extensive functionality, developers can meet a wide range of design requirements with few additional components beyond the sensor circuits and a stable voltage source. For the CN0398 reference design, Analog Devices uses its ADR3433 voltage reference as the analog supply (AVDD) and voltage reference (REFIN1) (Figure 2). As described below, designs for each of three sensor circuits requires only a few additional components.
Figure 2: Using the Analog Devices AD7124-8, developers can implement sensor designs with few additional components beyond specific sensor input circuits and a precision voltage reference such as the Analog Devices ADR3433. (Image source: Analog Devices)
Moisture measurement
Soil moisture systems typically determine water content by taking advantage of the difference in the dielectric constant of water (80) versus air (1). For these systems, developers drive a simple 3-wire sensor such as a TE Connectivity Measurement Specialties HPP809A033 sensor with an excitation voltage to generate an output voltage proportional to soil water content.
In the CN0398 design, the soil moisture front end uses an Analog Devices ADP7118-2.5 low dropout (LDO) linear regulator to provide a stable excitation voltage (Vsensor) for the sensor (Figure 3). To supply the LDO, developers can draw power from the ADICUP360 baseboard or from their custom designs.
Figure 3: The Analog Devices CN0398 design uses the company’s ADP7118-2.5 low dropout (LDO) regulator to provide a stable Vsensor voltage source for a capacitive moisture sensor. (Image source: Analog Devices)
Although the ADP7118 can provide a continuous sensor voltage level, power consumption concerns and the specific requirements of some moisture sensors dictate the use of a pulsed source for driving the sensor. To address these requirements, developers can supply the sensor with voltage pulses by driving the LDO’s enable (EN) port with an MCU PWM output.
Using its integrated signal conditioning circuit and ADC, the AD7124-8 can reliably sample and convert the voltage output of a moisture sensor. For soil measurement applications, however, the relationship between the converted sensor data and soil moisture can be complex.
In assessing soil moisture, soil health experts typically compare soil moisture levels in terms of soil volumetric water content (VWC), which is the ratio of water volume to total soil volume. Moisture sensor manufacturers typically provide equations for converting the output of their sensors to VWC. Still, soil conditions or the nature of the application itself can require the use of a conversion equation more suited to their own unique situation.
Analog Devices demonstrates the use of either approach in its sample software package. By enabling the USE_MANUFACTURER_MOISTURE_EQ to
define in the CN0398.h
header file, developers can elect to use the manufacturer’s recommended piece-wise conversion formulas or a standard conversion equation provided in the software. Here, the sample read_moisture()
routine generates a moisture output depending on the sensor output voltage range if USE_MANUFACTURER_MOISTURE_EQ
is defined (Listing 1). If the define is commented out in the CN0398.h
header, the routine can convert the voltage to moisture using the provided mathematical expression.
float CN0398::read_moisture()
{
float moisture = 0;
#ifdef MOISTURE_SENSOR_PRESENT
DioSet(ADP7118_PORT, ADP7118_PIN);
set_digital_output(P3, true);
timer.sleep(SENSOR_SETTLING_TIME);
int32_t data = adcValue[MOISTURE_CHANNEL]= read_channel(MOISTURE_CHANNEL);
DioClr(ADP7118_PORT, ADP7118_PIN);
float volt = voltage[MOISTURE_CHANNEL - 1] = data_to_voltage_bipolar(data, 1, 3.3);
#ifdef USE_MANUFACTURER_MOISTURE_EQ
if(volt <= 1.1) {
moisture = 10 * volt - 1;
} else if(volt > 1.1 && volt <= 1.3) {
moisture = 25 * volt - 17.5;
} else if(volt > 1.3 && volt <= 1.82) {
moisture = 48.08 * volt - 47.5;
} else if(volt > 1.82) {
moisture = 26.32 * volt - 7.89;
}
#else
moisture = -1.18467 + 21.5371 * volt - 110.996 * (pow(volt, 2)) + 397.025 * (pow(volt, 3)) - 666.986 * (pow(volt, 4)) + 569.236 * (pow(volt, 5)) - 246.005 * (pow(volt, 6)) + 49.4867 * (pow(volt, 7)) - 3.37077 * (pow(volt, 8));
#endif
if(moisture > 100) moisture = 100;
if(moisture < 0 ) moisture = 0;
#endif
set_digital_output(P3, false);
return moisture;
}
Listing 1: The Analog Devices CN0398 software package provides a sample moisture routine that demonstrates how developers can use manufacturer conversion formulas or equations to convert moisture sensor voltage to useful moisture data. (Code source: Analog Devices)
pH measurement
A typical pH sensor such as that in the SparkFun Electronics SEN-10972 pH kit exhibits an equivalent circuit characterized by a high impedance voltage source. Even using an ADC with an integrated signal conditioning front end, experienced developers typically add a buffer between the sensor output and ADC input in these situations.
Accordingly, the pH sensor circuit in the CN0398 design includes an Analog Devices ADA4661-2 op amp (Figure 4). Well-suited to low-power applications such as sensor circuits, the ADA4661-2 is a precision op amp that features single-supply operation, low power consumption, and low offset voltage across its full operating voltage range.
Figure 4: In the Analog Devices CN0398 design, an Analog Devices ADA4661-2 op amp provides a buffer between a typical high impedance pH sensor and the Analog Devices AD7124-8 analog input. (Image source: Analog Devices)
Although the design relies on a single supply voltage, pH sensors typically generate bipolar voltage output. In this case, however, the AD7124-8 provides a simple way to bias the sensor to a suitable level above ground. The AD7124-8 integrates an internal bias voltage generator that sets the common-mode voltage of a channel to AVDD/2. As in this case, designers can use an AD7124-8 output pin to deliver this bias voltage to the low side of the pH sensor (VBIAS in Figure 4). Developers can easily restore the biased input to a bipolar digital result in software.
The ADuCM360_demo_cn0398 open-source software package includes a sample read_ph()
routine that illustrates the process of converting pH sensor output voltage to pH values. As with the soil moisture routine, the pH sample routine demonstrates the use of two different approaches for generating pH values (Listing 2).
float CN0398::read_ph(float temperature)
{
float ph = 0;
#ifdef PH_SENSOR_PRESENT
int32_t data;
set_digital_output(P2, true);
adcValue[PH_CHANNEL] = data = read_channel(PH_CHANNEL);
float volt = voltage[PH_CHANNEL - 1] = data_to_voltage_bipolar(data, 1, 3.3);
if(use_nernst)
{
ph = PH_ISO -((volt - ZERO_POINT_TOLERANCE) / ((2.303 * AVOGADRO * (temperature + KELVIN_OFFSET)) / FARADAY_CONSTANT) );
}
else
{
float m = (calibration_ph[1][0] - calibration_ph[0][0]) / (calibration_ph[1][1] - calibration_ph[0][1]);
ph = m * (volt - calibration_ph[1][1] + offset_voltage) + calibration_ph[1][0];
}
set_digital_output(P2, false);
#endif
return ph;
}
Listing 2: Analog Device’s sample routine for reading pH sensor values illustrates use of the standard Nernst equation, or built-in calibration values to convert pH sensor voltage output to pH values. (Code source: Analog Devices)
By setting a variable use_nernst
to true in the sample package, developers can generate pH using the standard Nernst equation. Set to false, the variable causes the routine to use the values created during a two-point calibration procedure, typically performed using reference pH buffer solutions such as those in the SparkFun SEN-10972 pH kit. The sample software routines come with set default calibration values using NIST lookup tables for different pH buffer solutions and temperature corrected pH values ranging from 0°C to 95°C. Developers can replace the default values with their own custom calibration data, or easily modify the code to support both default and custom values.
Temperature measurement
As illustrated above in Listing 2, pH depends on temperature, either explicitly as in the Nernst equation, or implicitly in custom calibration values. Additionally, temperature impacts sensor sensitivity and the signal chain. Although the AD7124-8’s integrated temperature sensor (see Figure 1 again) can address some of these concerns, reliable soil measurement depends on accurate temperature readings. Accordingly, the CN0398 temperature sensor channel is designed to ensure accurate readings from an external 3-wire PT100 resistance temperature detector (RTD) such as the Adafruit Industries 3290.
As with any resistive sensor, RTDs require an excitation current to allow measurement of temperature-dependent voltage changes. Typically, developers using resistive sensors need to augment their sensor designs with external drivers, regulators and current sensors to maintain excitation current at precise levels. With the AD7124-8, however, developers need only add the appropriate passive networks required to support a 3-wire configuration (Figure 5).
Figure 5: To drive a 3-wire resistance temperature detector (RTD), the Analog Devices CN0398 design uses programmable constant current sources integrated in the Analog Devices AD7124-8. (Image source: Analog Devices)
Integrated in the AD7124-8, a pair of constant current generators provide excitation at various fixed levels from 50 to 1000 microamps (µA), including the 500 μA level used in the CN0398 design. Developers set the current level and output pin by programming the IOUTx and IOUTx_CH bits in the device’s IO_CONTROL configuration register, respectively. As part of its initialization routine, the CN0398 software package sets ADC channels AIN11 and AIN12 as output pins for two 500 μA excitation currents, IOUT1 and IOUT2.
Although the current generators are sufficiently accurate for many applications, developers can easily eliminate the impact of current variation by using a ratiometric measurement technique. The CN0398 temperature hardware sensor circuit shown in Figure 5 uses this approach. Here, the same IOUT1 current passes through the RTD and a precision reference resistor RREF, resulting in a ratiometric measurement. At the same time, IOUT2 produces a voltage drop across the RTD’s RTD SENSE lead resistance that cancels the voltage drop across the RTD+ lead resistance.
As with the moisture and pH sensors, conversion of resistance values to temperature requires an appropriate transfer function. For a typical RTD, the relationship between temperature and resistance can be reliably expressed mathematically. Even so, two different mathematical expressions need to be used for temperatures above and below 0°C. The ADuCM360_demo_cn0398 open-source software package supports both methods, as well as a simple linear conversion (Listing 3).
float CN0398::read_rtd()
{
float temperature = 0;
int32_t data;
adcValue[RTD_CHANNEL] = data = read_channel(RTD_CHANNEL);
float resistance = ((static_cast<float>(data) - _2_23) * RREF) / (TEMP_GAIN * _2_23);
#ifdef USE_LINEAR_TEMP_EQ
temperature = PT100_RESISTANCE_TO_TEMP(resistance);
#else
#define A (3.9083*pow(10,-3))
#define B (-5.775*pow(10,-7))
if(resistance < R0)
temperature = -242.02 + 2.228 * resistance + (2.5859 * pow(10, -3)) * pow(resistance, 2) - (48260.0 * pow(10, -6)) * pow(resistance, 3) - (2.8183 * pow(10, -3)) * pow(resistance, 4) + (1.5243 * pow(10, -10)) * pow(resistance, 5);
else
temperature = ((-A + sqrt(double(pow(A, 2) - 4 * B * (1 - resistance / R0))) ) / (2 * B));
#endif
return temperature;
}
Listing 3: For converting resistance values to temperature, an Analog Devices sample routine illustrates the basic design pattern for selecting the appropriate method based on static definitions (USE_LINEAR_TEMP_EQ)
or dynamic values (resistance < R0
). (Code source: Analog Devices)
As shown in Listing 3, the sample read_rtd() routine allows developers to select a simple linear conversion macro, PT100_RESISTANCE_TO_TEMP
, defined in the CN0398.cpp
module. Alternatively, developers can use the more complex mathematical expressions provided in the read_rtd()
sample routine. In this case, the 0°C inflection point for choosing the appropriate expression is implicit in R0
, which is the RTD resistance at 0°C.
Conclusion
To build soil measurement systems, engineers face an array of challenges in both hardware and software. Hardware designs must address sensor interface requirements, while software must accommodate different approaches for converting raw data to useful information.
The Analog Devices CN0398 board and ADuCM360_demo_cn0398 open-source software package address both aspects of soil measurement system design. Used in combination with Analog Device’s Arduino-compatible ADICUP360 baseboard, the CN0398 board and software provide a complete soil measurement solution.
Developers can use this turnkey solution to create soil measurement applications, or extend the associated reference design and sample software to build custom solutions.

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of DigiKey or official policies of DigiKey.