Interfacing Capacitive Soil Moisture Sensor with Arduino

926 views

Introduction

Soil moisture is a crucial factor in the growth and health of plants. It affects the amount of water and nutrients that plants receive and can ultimately impact their overall productivity. One way to monitor soil moisture is by using a capacitive soil moisture sensor, which measures the amount of water in the soil by detecting changes in capacitance.

In this article, we will explore how to interface a “Capacitive Soil Moisture” sensor with an Arduino microcontroller, allowing us to accurately measure soil moisture levels and create automated watering systems for plants.

What is Capacitive Soil Moisture Sensor?

A capacitive soil moisture sensor is a device used to measure the water content of soil by detecting changes in capacitance. The sensor consists of two conductive probes that are inserted into the soil. One probe acts as a capacitor plate, while the other probe acts as the ground. The moisture content in the soil acts as a dielectric between the two plates, and as the water content changes, the capacitance of the sensor changes as well. By measuring the changes in capacitance, the sensor can provide an accurate reading of the soil moisture level.

Hardware Components

To interface a Capacitive Soil Moisture Sensor with Arduino, you’ll need the following hardware components to get started:

ComponentsValueQty
Arduino UNO1
USB Cable Type A to B1
DC Power for Arduino1
Soil Moisture Sensor1
Jumper Wires1

Soil Moisture Sensor Pinout

Capacitive Soil Moisture Sensor Pinout
Capacitive Soil Moisture Sensor Pinout
PinsPin function
A or AOUT or OUTAnalog Output (the equivalent of the soil moisture)
+ or V+ VCC or 5VPositive Supply voltage (most of the sensors are 3.3 V to 5 V compatible)
GND or – or V-Ground connection

Soil Moisture Sensor Circuit

Make connections according to the circuit diagram given below.

Wiring / Connections

ArduinoSoil Moisture Sensor
5VVCC
GNDGND
A0Analog OUT

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.

const int OpenAirReading = 700;   //calibration data 1
const int WaterReading = 280;     //calibration data 2
int MoistureLevel = 0;
int SoilMoisturePercentage = 0;
 
void setup() {
  Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
 
void loop() {
  MoistureLevel = analogRead(A0);  //update based on the analog Pin selected
  Serial.println(soilMoistureValue);
  SoilMoisturePercentage = map(MoistureLevel, OpenAirReading, WaterReading, 0, 100);
 
  if (SoilMoisturePercentage >= 100)
  {
    Serial.println("\n Maximum - 100 %");
  }
  else if (SoilMoisturePercentage <= 0)
  {
    Serial.println("\n Minimum - 0 %");
  }
  else if (SoilMoisturePercentage > 0 && SoilMoisturePercentage < 100)
  {
    Serial.print(SoilMoisturePercentage);
    Serial.println("%");
  }
 
  delay(1000);
}

Code Explanation

This Arduino code is used to interface a capacitive soil moisture sensor with an Arduino microcontroller. The code consists of two calibration data variables, OpenAirReading and WaterReading, which are used to calibrate the sensor readings. The setup() function initializes the serial communication at a baud rate of 9600 bps, while the loop() function repeatedly reads the analog value from the sensor connected to pin A0, converts the analog value to a percentage of soil moisture level using the map() function, and prints the result to the serial monitor. The code also includes some conditional statements to check if the soil moisture percentage is within the range of 0-100% and prints out the result accordingly. Finally, the delay() function is used to pause the loop for 1000 milliseconds between each reading to avoid overloading the serial monitor.

Applications

Here are some applications of Capacitive Soil Moisture Sensors:

  • Agriculture: Used to optimize irrigation and fertilization for crops.
  • Horticulture: Used to monitor soil moisture levels in indoor and outdoor plants.
  • Landscaping: Used to maintain the health of lawns, gardens, and trees.
  • Environmental monitoring: Used to measure soil moisture levels in natural ecosystems such as forests, wetlands, and deserts.
  • Sports field management: Used to maintain optimal playing conditions for sports fields such as golf courses and soccer fields.
  • Soil research: Used to study the effects of different soil types, land use practices, and environmental factors on soil moisture levels.
  • Weather monitoring: Used to collect data on soil moisture levels as a parameter for weather forecasting models.
  • Construction: Used to assess the soil moisture levels in the construction site to ensure the stability of structures.

Conclusion

Interfacing a capacitive soil moisture sensor with an Arduino is a simple and effective way to monitor soil moisture levels and ensure the health and productivity of your plants.