Capacitive Soil Moisture Sensor Calibration with Arduino

cap_soil_moisture_sensor_in_soil.JPG

“As an Amazon Associates Program member, clicking on links may result in Maker Portal receiving a small commission that helps support future projects.”

Soil moisture can be measured using a variety of different techniques: gravimetric, nuclear, electromagnetic, tensiometric, hygrometric, among others [read about the specifics types of soil moisture sensors here]. The technique explored here uses a gravimetric technique to calibrate a capacitive-type electromagnetic soil moisture sensor. Capacitive soil moisture sensors exploit the dielectric contrast between water and soil, where dry soils have a relative permittivity between 2-6 and water has a value of roughly 80 [find more specific values here]. Accurate measurement of soil water content is essential for applications in agronomy and botany - where the under- and over-watering of soil can result in ineffective or wasted resources. With water occupying up to 60% of certain soils by volume, depending on the specific porosity of the soil, calibration must be carried out in every environment to ensure accurate prediction of water content [more on this here]. Luckily, the accuracy of measurement devices has been increasing while the cost of the sensors have been decreasing. In this experiment, an Arduino board will be used to read the analog signal from the capacitive sensor, which will output voltage values which can be calibrated to volumetric soil moisture content via gravimetric methods (using volume and weight of dry and wet soil).


Parallel-Plate Capacitor

As the name suggests, capacitive soil moisture sensors use the working principle of a capacitor to approximate the moisture content in soil. Capacitance is defined as the amount of charge a material can store under a given applied electrical potential [Engineering Electromagnetics textbook]. Commonly, capacitors are visualized as parallel-plate configurations similar to what is shown in the drawing below:

capacitor_drawing.png

In equation form, capacitance can be written as the ratio between charge and electrical potential :

The definition of charge, Q, uses the surface integral between the electric field, E, and dielectric material with relative permittivity, ε, across the surface area of the capacitor. The definition of electric potential, V, uses the line integral of the electric field. For the parallel plate capacitor, we can assume the electric field is constant across the surface of the dielectric. This results in the following simplification:

And this is the commonly held relationship between the geometric properties of a parallel plate capacitor and the dielectric material present in the capacitor.

Planar Capacitance from Moisture in Soil

The capacitance measured by a soil moisture sensor is different from a parallel plate capacitor in that the plates of the capacitor are not parallel, but planar. This means that the plates are next to each other, rather than atop each other; and the dielectric material is the soil, rather than a thin layer pressed between the plates. This is visually demonstrated in the drawing below:

coplanar_capacitor_drawing.png
We can see that the electrodes of the sensor act as the ‘plates’ of the capacitor, which are both exposed to the dielectric material, assumed to be the soil (dry or wet). The capacitive soil moisture sensor is paired with a timer circuit (TLC555 in the case of our sensor) and outputs a duty cycle that corresponds to an analog voltage. This voltage, in turn, can be read with an Arduino board. The capacitance for a planar capacitor is very complicated, and so it will not be explored in depth, but is essentially a function of the dielectric constant and geometry of the sensor:
where the only new introduction is G, which is a function that encapsulates the geometric properties of the sensor. This can be a very complicated function due to the surface and line integrals involved in the planar configuraiton, but that is outside the scope of the current analysis. For the timer circuit, the voltage can be written as a function of the input capacitance and a group of constants, A:

Finally, solving for the dielectric constant:

This essentially means that we can expect a relationship between the inverse of the voltage read by the sensor and the dielectric constant. In the next section, the volumetric water content will be separated from the dielectric constant.

Volumetric Water Content

The volumetric water content is the ratio of volume of liquid water to volume of soil. It is defined as [source]:

where mw and ms represent the mass of water and soil, respectively. The soil parameter defined here is for dry soil only. The density, ρ, is defined similarly for water (ρw) and dry soil (ρs). The volumetric water content is related to the dielectric content of soil and water by partitioning them as follows:

Inserting the function for voltage into the equation above for dielectric constant:

Lastly, if we compress the equation above, since we do not know a lot of the constants, we can write the relationship between voltage and volumetric water content as a linear function with an unknown slope and intercept:

The above is a massive result! It states that the voltage reading taken from our capacitive-type electromagnetic soil moisture sensor can be related to the volumetric water content using a linear fit between the two via a slope, a, and intercept, b. In the next section, the parts list for calibrating this relationship will be introduced.


The parts used in this experiment will need to capture the two basic principles used in calibrating soil moisture sensors: measuring the volume and weight of soils, both moist and dry. Thus, along with the capacitive soil moisture sensor, a digital scale will be necessary, as well as a container or method to measure the volume of soil. The parts list used in this tutorial are given below, for reference:

  • 1x Capacitive Soil Moisture Sensor - $7.00 [Our Store]

  • 1x Arduino Uno Board - $13.00 [Our Store]

  • 1x High Resolution Digital Scale With Calibration Masses - $25.00 [Our Store]

  • 250ml Graduated Containers - $11.99 (6pcs) [Amazon]

  • Soil Samples - $8.97 (6pcs) [Amazon]

  • Mini Breadboard - $3.00 [Our Store]

  • Raspberry Pi 4 Computer - $55.00 [2GB from Our Store]

The soil samples referenced above can be substituted for any other type of soil based on the application. The soil was purchased because it arrives already dried, however, it was unnecessary as the soil needed to be moistened to break up the block of soil anyway. Therefore, it is recommended that a soil type be used that is somewhat dried already, and still loose enough to pack in a sensor.

Below is the diagram for wiring the soil moisture sensor to the Arduino Uno board:

cap_soil_sensor_arduino_wiring.png

One thing to note is that the capacitive soil sensor uses 3.3V as its supply voltage, therefore, the AREF pin also should be wired to 3.3V to ensure the best resolution in the ADC around 3.3V, instead of 5.0V. Lastly, the Arduino code to test the soil moisture sensor is given below:

// Simple code for Measuring Voltage from
// Capacitive soil moisture sensor
//
int soil_pin = A0; // AOUT pin on sensor

void setup() {
  Serial.begin(9600); // serial port setup
  analogReference(EXTERNAL); // set the analog reference to 3.3V
}

void loop() {
  Serial.print("Soil Moisture Sensor Voltage: ");
  Serial.print((float(analogRead(soil_pin))/1023.0)*3.3); // read sensor
  Serial.println(" V");
  delay(100); // slight delay between readings
}

Under the assumption that the Arduino board and sensor have been wired correctly, the code above should print out values between 0V - 3.3V. If the sensor is in air, the value should be around 3.15V, and if the sensor is in a moist soil, the value will be between 1.9V - 3.0V. In the next section, the calibration procedure will be introduced, where the actual volumetric soil moisture content will be approximated by carrying out gravimetric techniques for measuring the moisture content in a soil.


The volumetric water content, as defined in the first section, is the ratio of volume of water to volume of soil contained within a sample. Therefore, if we want to measure the instantaneous water content in a soil sample, we have to measure the volume and mass of each sample. Every time water is added to the soil, the mass of the sample will change. Soil moisture is consistently approximated by keeping the volume of each sample the same every time water is added, while also measuring the mass of every sample. The way this is done is by using one of the 250ml containers with graduated markings and making sure the soil level reaches the same level each time water is added to the soil.

Returning to the definition for volumetric water content, we can see how each component factors into the experimental process:

since we don't know the mass of the water, we can equate the mass of water to the difference between the mass of wet soil and mass of dry soil:
We can see the four measurable components involved in approximating the volumetric water content in the soil:
 
  • mwet - The measured mass of the soil (wet or dry)
  • ms - The measured mass of the dry soil
  • ρs - Bulk density of soil (mass of dry soil divided by sample volume)
  • ρw - density of water
In reality, only one of these measurements is measured after each loop: the mass of the wet soil. At the start of the experiment, the soil should be completely dry. The best way to determine this is to take a few measurements of the same soil over a few hours. If the mass keeps changing significantly, then there is still likely some water evaporating. Once the mass is consistent over a few measurements, this can be considered the dry soil mass. The density of water is widely known and can be considered around 997 kg/m3. Lastly, the bulk density of the soil can be approximated based on the dry soil mass divided by the sample volume.

Calibration Procedure:

  1. Measure the mass of the soil sample container

  2. Fill container to 200ml (or any volume) with dry soil

  3. Measure mass of the dry soil in the container

  4. Wet the soil with 10ml of water (this is 5%, but any higher % is okay)

  5. Mix the wet soil around to ensure the water is evenly distributed, then refill the container to 200ml

  6. Measure the mass of the wet soil

  7. Repeat steps 4., 5., and 6. until the soil is saturated and starts to seep water

  8. Once the procedure of watering has reached saturation, lay the 200ml of soil out on an array of wax paper to allow it to dry out

  9. When the soil is dry, measure the mass of this dry soil - this will be the mass of the dry soil used for soil density

The above procedure can take up to 7 days, when factoring the drying procedure. The experimental process can take roughly 10-minutes per measurement (packing, watering, settling), and with about 6-10 measurements per experiment - the actual work can be 1-2 hours. Thus, after the initial few days of drying the soil, plus 2 hours of experiments, along with a few days of drying the soil out - the full-scale experiment takes about 7 days. The way to ensure the fastest experimentation is to lay the soil out very thinly on the wax paper. This will give about 7 days per soil calibration.

Drying soil (left) and near saturation soil (right)

dry_and_wet_soils.JPG

A Note on Packing Soil:
Take care to pack the soil into the 200ml container. The best method for packing soil effectively is to pack layer-by-layer to ensure a vertically even distribution of soil. This will also ensure the most consistent results from the sensor.

grad_cylinder_10ml.JPG

10ml of Water to be Added to the Soil Sample

A Note on Capacitive Sensor Settling Time:
The capacitive soil moisture sensor can take some time to equalize and give a steady reading, so be sure to wait approximately 1 minute after the sensor settles to a given value. It should settle in 1-5 minutes, depending on the saturation level of the soil.

Under the assumption of a successful calibration, we can take the data and analyze it. This will be done in the next section, where the results will be presented and analyzed in order to properly calibrate the linear relationship between the inverse of the sensor voltage and the gravimetric approximation of volumetric water content in soil.


The specific type of soil being used can cause large deviations in calibration results. This is due to the effect of bulk density on the gravimetric procedure, where bulk density for soils can vary from 0.05-2.0 g/cm3. This results in a possible error of 5% - 200%. Thus, it is very important to properly identify the bulk density each time the capacitive sensor is moved to a new soil. It is also recommended that the digital scale used be accurate down to 0.1g or even 0.01g, however, with the variability involved in soil density, I don't find the 0.01g resolution to be realisticly accurate.

The soil presented in the parts list above is a coconut coir. A study on coconut coir states that the bulk density of coconut coir dust is roughly 0.074 g/ml, which is quite low for a soil density. For most sandy soils, the bulk density is around 1g/ml. Thus, the calibration given here may be considerably different compared to many soils.

Below is the example spreadsheet used to capture all of the information that is needed for calibrating the soil moisture sensor:

Screen Shot 2020-06-18 at 12.20.08 PM.png

We can see that our calculated bulk density for our coconut coir soil is roughly 0.132 g/ml, which is reasonable considering our soil is somewhere between dust and pulp (the pulp can be seen as the elongated sections of soil). The resulting calibration data and fit is given in the figure below:

soil_moisture_calibration_results.png

For the soil that is used in our case, we can see that the calibration produces an error of roughly 6% across the range of measured volumetric water content. The fit, for our soil and particular sensor, was found to be the following:

This is the equation that can now be used to predict the water content in our soil, under a given voltage measurement from the capacitive sensor.

capacitive_soil_moisture_experiment_setup.JPG

The new calibrated implementation code for the prediction of volumetric water content in soil using the capacitive sensor is given below for the Arduino board:

// Simple Arduino code to predict volumetric
// water content in soil using a capacitive
// soil moisture sensor
//
int soil_pin = A0; // AOUT pin on sensor

float slope = 2.48; // slope from linear fit
float intercept = -0.72; // intercept from linear fit

void setup() {
  Serial.begin(9600); // serial port setup
  analogReference(EXTERNAL); // set the analog reference to 3.3V
}

void loop() {
  float voltage,vol_water_cont; // preallocate to approx. voltage and theta_v
  Serial.print("Voltage: ");
  voltage = (float(analogRead(soil_pin))/1023.0)*3.3;
  Serial.print(voltage); // read sensor
  Serial.print(" V, Theta_v: ");
  vol_water_cont = ((1.0/voltage)*slope)+intercept; // calc of theta_v (vol. water content)
  Serial.print(vol_water_cont);
  Serial.println(" cm^3/cm^3"); // cm^3/cm^3
  delay(100); // slight delay between readings
}

And this completes the calibration of the capacitive soil moisture sensor!


The theory, calibration, and operation of a capacitive-type soil moisture sensor was introduced here as a way to predict volumetric water content in soils in an efficient and easy manner. Using an Arduino board and digital scale, the real-time measurement of both the mass of the soil and the readings from the capacitive sensor were recorded. By adding water to dry soil, the mass of the soil changes across the same volumetric sample. This gives users the ability to approximate the water content in soil by measuring the weight against a dry sample of the soil - giving an instantaneous approximation of soil moisture content. The voltage was then linearly correlated to the gravimetric moisture approximations, to give an effective relationship between the reading from the capacitive sensor and the water content in the soil. The method used here produced an error of about 6% for readings, indicating a fairly good approximation of the water content in the soil used in our case (coconut coir). This calibration procedure demonstrated that these low-cost capacitive-type soil moisture sensors are capable of predicting the water content in soils to a fairly high degree of accuracy, with little required outside of the device itself, which is in direct contrast to the time it takes to traditionally measure the water content in soils.

Some relevant tutorials and publications:

 
Citation for This Page:
 

See More in Engineering and Sensors: