1 Project Aim: optimizing water usage in home gardening

This study is part of an ongoing personal project to optimize water usage in domestic vegetable gardens.

More and more countries are considered under water stress, as classified by the World Resources Institute’s Aqueduct Projected Water Stress Country Rankings.

It is hence to be expected that in the coming years, in many of these countries water resources will be primarily reserved for industrial and agricultural use, while water for domestic uses might be subject to more restrictions. Finding ways to reduce water usage becomes a necessity.

The project includes these steps:

  1. laying down a watering system for the vegetable garden boxes
  2. setting up a system for web-service-based watering
  3. setting up a system for continuous soil moisture monitoring to activate the watering system only when and only where needed

Steps 1 and 2 are now complete, while step 3 is still in progress. This report aims at calibrating the soil moisture sensor for one specific type of soil: the one present in the salad box.

An overview of the project steps / components can be seen in Figure 1. The electronic parts (i.e. excluding the valves) cost less than $100.
The software components of the project will soon be released under a permissive copyleft license.

Figure 1: automatic soil watering flow

The project leverages one or more wireless soil moisture sensors.

These sensors host a small computer on board, which is capable of sending soil moisture information over-the-air by leveraging the LoRa technology, which is a long-range, low-power radio transmission protocol widely used, among others, in agritech and environmental applications.
The sensor computer can also read ambient temperature and humidity information. However, this feature cannot be leveraged outdoors, since the T/H sensor is hosted on the minicomputer itself, and this needs to be made waterproof.

Once the system is complete, the soil moisture data will be received by a LoRa gateway which in turn, whenever appropriate, will send instructions to the watering programmer to open the right latching solenoid valve, for the right duration.

2 Study Goal: calibrating the soil moisture sensor for one of the garden soil types

The soil moisture sensor is of the capacitive type. This means that the sensor does not provide soil moisture information directly. Rather, such information can be approximated by exploiting the dielectric contrast between water and soil, which gives origin to the voltage values that the sensor provides.

Since the type of soil has an impact on the voltage values that the sensor provides, for practical applications it is essential to map the voltage values to some standard soil moisture measure.

Among the many methods available, we chose to follow the gravimetric method proposed in Hrisko 2020, which calibrates a sensor of the very same type. The theoretical details of the approach are provided in that document. In short, by measuring volume and mass of the soil while adding water at regular steps, it is possible to obtain the slope and intercept parameters of a linear function that can be used to map voltage readings to the volumetric water content of the soil. The volumetric water content can then be used to decide when to start (and possibly stop) the watering process. The mapping function is

Formula 1
\(\displaystyle \theta_V = \frac{a}{V} + b\)

where \(\theta_V\) represents the volumetric water content, \(V\) the voltage reading, \(a\) the slope and \(b\) the intercept of the linear function that best fits the mass and volume readings for the moist soil.

The method proposes to measure soil mass and sensor voltage by gradually increasing the water content of a soil sample of constant volume. By combining this information with a few more known constants (like the density of water), we can obtain a scatter plot where, for each measurement, we plot the inverse of the sensor voltage (\(V^{-1}\)) against \(\theta_V\).

2.1 Input data

The input data to determine the volumetric water content function consists of:

Table 1: Soil weight and sensor voltage by gradually increasing the water content of the soil sample
Added water (\(ml\)) Soil weight + container (\(g\)) Sensor reading (\(V\))
0 59.43 2.74
5 64.52 2.25
10 69.65 2.13
15 74.86 2.12
20 79.48 1.94
25 85.42 1.89
Table 2: Further constants and variables needed to obtain the volumetric water content function of \(V\)
Soil volume (\(ml\)) Container mass (\(g\)) Sensor reading in air (\(V\)) Density of water (\(kg/m^3\))
100 3.53 2.75 997

According to the method proposed by Hrisko, the value of \(\theta_V\) for each step where water is added to the soil sample can be calculated as follows:

Formula 2
\(\displaystyle \theta_V = \frac{m_{wet} - m_s}{m_s} * \frac{\rho_s}{\rho_w}\)

where:

  • \(m_{wet}\) is the mass of soil with added water
  • \(m_s\) is the mass of dry soil
  • \(\rho_s\) is the bulk density of soil (mass of dry soil divided by sample volume)
  • \(\rho_w\) is the bulk density of water

The first step is thus the calculation of \(\rho_s\), the bulk density of soil.

2.2 Calculating the bulk density of soil

As suggested in Hrisko 2020, we calculate the bulk density of the soil by measuring the mass of the dry soil, and dividing it by the sample volume.

The bulk density of the soil (\(g/cm^3\)), is:

Calculation 1

soil_gross_weight_g_dry = soil_moisture_data$soil_gross_weight_g[1]
container_mass_g = soil_moisture_data$container_mass_g[1]
soil_dry_mass = soil_gross_weight_g_dry - container_mass_g
soil_volume_ml = soil_moisture_data$soil_volume_ml[1]

soil_bulk_density_g_cm3 = soil_dry_mass / soil_volume_ml
water_density_g_cm3 = soil_moisture_data$water_density_kg_m3[1]/1000

print(soil_bulk_density_g_cm3)
## [1] 0.559

2.3 Calculating volumetric content of water for each data point

By applying Formula 2 to each data point (hence, with varying \(m_{wet}\)), we obtain the following:

Calculation 2

# Calculate and store theta_V values for each data point
soil_moisture_data$theta_V = (((soil_moisture_data$soil_gross_weight_g - container_mass_g) - soil_dry_mass) / soil_dry_mass) * (soil_bulk_density_g_cm3 / water_density_g_cm3)
Table 3: Calculated volumetric water content for each data point
Added water (\(ml\)) Soil weight + container (\(g\)) theta_V
0 59.43 0.0000000
5 64.52 0.0510532
10 69.65 0.1025075
15 74.86 0.1547643
20 79.48 0.2011033
25 85.42 0.2606820

Plotting, as suggested in Hrisko 2020, the inverse of the sensor reading voltage against \(\theta_V\), give origin to a pattern with a strongly positive correlation coefficient of 0.94:

cor(sensor_reading_V_invert, theta_V)
## [1] 0.9423932

2.4 Extrapolating a linear approximation of the relationship between voltage and volume of water content

Given the strong correlation, it seems sensible to extrapolate a function that linearly approximates the relationship between \(V_{-1}\) and \(\theta_V\):

The found intercept (\(-0.6\)) and slope (\(1.55\)) values can then be used to send volumetric water content readings from the LoRa soil moisture sensor, and acted upon by the watering system.

Here is an extract of the corresponding Arduino C++ source code:

Code Listing 1: calculating volumetric water content from sensor voltage

...

float slope = 1.55; // slope from linear fit
float intercept = -0.6; // intercept from linear fit

...

void loop()
{
  sensorPowerOn();//
  delay(100);
  sensorValue = analogRead(sensorPin);
  delay(200);
  Serial.print(F("Moisture ADC: "));
  Serial.println(sensorValue);
  float voltage, vol_water_cont;
  Serial.print("Voltage: ");
  voltage = (float(sensorValue)/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");
}

3 Future work

More rounds of measurements would be needed to account for the variability of voltage readings when adding water to the soil sample, in order to have a better characterisation of sensor reliability.

Also, the same activity should be extended to the soil types of the remaining two vegetable boxes.

Despite the approximations adopted, this method represents a cheap, but likely effective way of predicting soil moisture from capacitive sensor readings.