How to Use a Capacitive Soil Moisture Sensor V2.0 Module With Arduino12 min read

Soil Moisture Sensors are inexpensive, simple, easy to use and can be used to build interesting IoT & automation projects! They are available in a wide range of models, output types (analog, digital, wireless etc) and variants. Even the simplest soil moisture sensor with an analog output is accurate enough to detect between dry and wet soil conditions and can be used to build interesting projects!

Once we have the reading of these sensors to a microcontroller, we can use it to turn on an LED, control a water pump or even transmit it to the cloud! But once we understand how the sensors work, how to make the right connections, and how to interface it with a microcontroller, the difficult part is done.

This article explains this and lets you integrate a soil moisture sensor in your next project!

Types of Soil Moisture Sensor

There are two types of soil moisture sensors – resistive and capacitive based on the technology they use to detect soil moisture.

Resistive Soil Moisture Sensors

The sensor consists of two probes that are used to measure the volumetric content of water and indirectly the moisture. One probe transmits current and another measures the current. The resistance(soil moisture) between the probe determines the current being measured at the receiving probe. The resistance between the probes varies directly proportional to the soil moisture content.

A simple resistor divider circuit on the sensor module, converts this resistance to voltage which can then be measured by any microcontroller/processor with ADC.

When the water content is high, the soil will conduct more electricity and lead to a low less resistance between the probes. Therefore, the moisture level sensed will be higher. Dry soil conducts electricity poorly, when there will be less water, then the soil will conduct less electricity which will lead to less resistance between the probes. Therefore, the moisture level sensed will be lower

Probots Soil Moisture Sensor with Analog and Digital Output

A popular soil moisture sensor. Includes a probe(right) and module(left) with the resistor divider and opamp. The module outputs an analog signal proportional to the measured soil moisture.

It also outputs separate digital signal which outputs a digital signal when the moisture crosses a user set threshold

Capacitive Soil Moisture sensor

Capacitive soil moisture sensor measures soil moisture levels by capacitive sensing rather than resistive sensing. The major issue with the resistive soil moisture sensor is the corrosion of the sensor probes, not just because it is in contact with the soil but also because there is a DC current flowing which causes electrolysis of the sensors.

The probes of a capacitive soil moisture sensors are better resistant to corrosion and hence provide a longer life compared to resistive soil moisture sensors!

This module includes an onboard voltage regulator which gives it an operating voltage range of 3.3 ~ 5.5V. It works for both 3.3V and 5V microcontroller circuits.

Difference Between Capacitive and Resistive Soil Moisture Sensor

Capacitive measuring has some advantages, It not only avoids corrosion of the probe but also gives a better reading of the moisture content of the soil as opposed to resistance measuring

In reality, it does not measure moisture (as water is a bad conductor of current), instead, it measures the ions that are dissolved in the moisture i.e Adding fertilizer, for instance, will decrease the resistance of the soil, even though no water is added.

Capacitive sensors measure the dielectric that is formed by the soil and the water is the most important factor that effect the capacitance. By measure the capacitance, they indirectly measure the soil moisture!

Specifications of standard Capacitive Soil Moisture Sensor

  • Operating Voltage: 3.3 ~ 5.5 VDC ( good for both 5V and 3V3 digital circuits / microcontroller)
  • Operating Current: 5mA (low power consumption is great for battery operated IoT Nodes!)
  • Interface: PH2.54-3P (Standard JST Connects for easy connection to external PCBs and breadboard)
  • Dimensions mm(LxWxH): 98 x 23 x 4 mm (single board design for plug and play!)
  • Analog output (easy to interface with all Microcontrollers with ADC)
  • Weight (gm): 15

Capacitive Soil Moisture Sensor Board Overview

Capacitive Soil Moisture Sensors are very simple to use. Just power the board with 5V to the VCC and GND Pins. Plug the sensor into the soil and the AOUT pin will output an analog signal between 0 to 2.3V corresponding to the soil moisture level!

NumLabelDescription
1GndPower GND (0V)
2VccPower VCC (3.3~5.5V)
3AoutAnalog Signal Output(0~2.3V)
Pin Description

Check out our online store – www.probots.co.in to find all the parts for your projects! We have 2000+ Electronic Modules, Sensors, and Components for all your electronics projects.
You can purchase this Soil Moisture Sensor Capacitive V2.0 here – Buy Now


Requirements – Things need to get Started!

To use a capacitive soil moisture sensor in your project, you will need the following

How to connect a soil moisture sensor to your microcontroller / Arduino? – Connection Diagram

Circuit Diagram for Capacitive Soil Moisture Sensor and Arduino

Some Popular Applications

  • Automatic plants watering
  • Soil Moisture Detection Logging
  • Moisture Sensing
  • Intelligent agriculture / IoT Soil Moisture Sensor

Sensor Calibration (Optional)

To get accurate readings out of your soil moisture sensor, it is recommended that you first calibrate it for the particular type of soil that you plan to monitor. Soil moisture sensors do not give an abosolute reading of the the moisture content in percentage (0 to 100%) but only non-calibrated linear values. We have to linearise and calibrate these values by mapping the sensor output value to known soil moisture levels.

Since the sensor outputs only an analog output which may vary between soil types, it is good to benchmark the readings of the sensor from your desired target soil.

Run this calibration code to view the ADC readings in different soil conditions (Dry, Wet, Very Wet). Prepare a mini lookup table and use these values in the final program!

Calibration Code

void setup()
{
    Serial.begin(9600);     // open Serial Monitor and set baud rate
}

void loop()
{
    Int val;
    val = analogRead(0);    // sensor Aout pin connected to A0 pin of Ardiuno
    Serial.println(val);    // print the value in serial monitor
    delay(100);
}

Calibration Range

Calibration of Capacitive Soil Moisture Sensor

Note: All components on these sensor boards are not WATERPROOF do not expose to moisture further than the red line

Calibration Results!

The final output value is also affected by probe insertion depth and how tight the soil packed around it. We regard “value_1” as dry soil and “value_2” as soaked soil. This is the sensor detection range. For example: Value_1 = 520; Value_2 = 260.

Since this range is linear, we can approximate the range into three sections: dry, wet, water. For the readings that we got from our sensor, their related values are:

  • Dry: (520 430]
  • Wet: (430 350]
  • Water: (350 260]
Testing of Capacitive Soil Moisture Sensor

Final Code

Once the connections are made and you have performed the calibration, you can use this code to interface the soil moisture sensor to an Arduino. The code is quite simple and self explanatory. Make sure you follow whats happening in each line and are able to trace the program flow.

The program constantly checks the soil moisture sensor reading every 100milliseconds and prints Dry, Wet or Very Wet based on the sensor reading!

const int AirValue = 520;   //you need to replace this value with Value_1
const int WaterValue = 260;  //you need to replace this value with Value_2
int intervals = (AirValue - WaterValue)/3;
int soilMoistureValue = 0;

void setup()
{
  Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}

void loop()
{
  soilMoistureValue = analogRead(A0);  //put Sensor insert into soil
  if(soilMoistureValue > WaterValue && soilMoistureValue < (WaterValue + intervals))
  {
    Serial.println("Very Wet");
  }
  else if(soilMoistureValue > (WaterValue + intervals) && soilMoistureValue < (AirValue - intervals))
  {
    Serial.println("Wet");
  }
  else if(soilMoistureValue < AirValue && soilMoistureValue > (AirValue - intervals))
  {
    Serial.println("Dry");
  }
  delay(100);
}

You can use this code as a reference to test and play around with the soil moisture sensor. You can use it to understand how it works and build ontop of this code to add features specific to your project!

All the components used in this article are readily available on our online store – www.probots.co.in Order online and get the products delivered in 1-7 days throughout India! Order with confidence, we only stock original and tested products!

FAQ – Soil Moisture Sensors

  1. How to use a soil moisture sensor with Arduino / Microcontroller?
    • Soil Moisture sensors are one of the easiest sensors to use with microcontroller. They usually come with an analog & digital output and can be directly connected to most standard microcontrollers including Arduino UNO, NANO, ESP32, Raspberry Pi, Zero, etc
    • Just follow this tutorial from the start to use a soil moisture sensor in your next project. This tutorial covers – the working of popular soil moisture sensor, types, connections, sample codes, instructions, etc
  2. How to connect a soil moisture sensor to Microcontroller?
    • Soil Moisture Sensors are the simplest and easiest sensors to use with Microcontrollers. You should not face any problems if you understand the fundamentals, and follow the right practices!
    • Connections are simple and straightforward. Detailed connections are explained step by step in this page above!
  3. How to program a soil moisture sensor? What is the simplest source code to get started with a soil moisture sensor?
    • Basic code to read digital inputs and analog values should be sufficient to interface with microcontrollers. This is always provided by the manufacturer of your microcontroller. With just a little customisation, you can use it to interface with a soil moisture sensor.
    • This page provides a basic reference source code to interface a capacitive soil moisture sensor with Arduino UNO!
  4. How to debug a soil moisture sensor and that is not working as expected / not generating the right readings?
    If you have followed all steps in this article, but are still not able to get readings from a soil moisture sensor, you can follow these steps to get it working –
    • Grab a multimeter, power VCC and GND pins on your soil moisture sensor and measure the voltage output on the AOUT pin. A good sensor should output a voltage between 0 to 3V. This value will change based on soil the sensor is inserted into!
      If you dont see this behaviour from your sensor, get a new original sensor. You have a fake/defective sensor.
    • Once the sensor is working independently, connect AOUT to the analog in ADC pin on your microcontroller/Arduino and run a basic ADC program. You should see varying ADC values for different soil types!
      If you are unable to varying ADC values, your ADC pin is probably damaged, use a different ADC pin or microcontroller
  5. How to interface a soil moisture sensor with ESP32?
    • Interfacing a soil moisture sensor with ESP32 is same as interfacing it with a Arduino UNO. Just change pin mappings and modify code accordingly. IF you follow the fundamentals in this tutorial, getting it working with an ESP32 is simple and easy!
  6. How to interface a soil moisture sensor with a Raspberry Pi 5 / Zero?
    • Same as above!
    • If your Raspberry Pi doesnt have an ADC pin, use an I2C ADC Converter to access the ADC values through I2C.
  7. How to connect multiple soil moisture sensors simultaneously to a microcontroller / Arduino?
    • You can connect as many soil sensors as the number of ADC pins on your microcontroller. All of them can be accessed simultaneously. Use a multiplexer or I2C ADC Converter to add more ADC pins to your microcontroller.
  8. How to build a IoT Plant Watering System using a Soil Moisture Sensor? How to connect a soil moisture sensor to the Cloud?
    • Make sure you read this article completely and get a soil moisture sensor working independently. This tutorial is more than enough to help you get a soil moisture sensor working with Arduino or any microcontroller.
    • Once you have done this, connect it through MQTT, Rest / Post APIs or any other protocol to your cloud or database!

Chidananda

Leave a Comment

Your email address will not be published. Required fields are marked *

Contents
Exit mobile version