IOT

How to Interface Capacitive Soil Moisture Sensor v1.2 with Arduino

We are living in a technology-based society where we have lots of innovative ideas day by day. These new innovations in IoT communications-based projects, strive constantly to share and gather insight on the latest trends in the industrial IoT landscape.

Plants require water on a regular basis for proper growth. Water resources such as rivers, canals, ponds, lakes, wells, and many more have become contaminated nowadays due to human activities. Water became a scarce resource due to growing population, climate changes and rapid urbanization.

In this project, we’ll connect a Capacitive Soil Moisture Sensor to an Arduino and a 16×2 LCD Display, and display the soil moisture value as a percentage (percent) on both the Serial Monitor and the LCD and OLED displays. We’ll learn how to calibrate a display to show the right value.

Hardware Required

  • Arduino UNO/Nano or any other Board
  • Capacitive Soil Moisture Sensor V1.2
  • 16×2 LCD Display
  • 0.96″ I2C OLED Display
  • Connecting Wires
  • Breadboard

Proposed System

The Arduino with Capacitive Soil Moisture Sensor & LCD/OLED Interfacing Tutorial is the basis of this project. The amount/content of water in the soil is referred to as soil moisture. A soil moisture sensor, either resistive or capacitive, can be used to measure this. The Capacitive Soil Moisture Sensor v1.2 will be used in this example. This sensor calculates the moisture level by measuring the volumetric content of water in the soil.

This soil moisture sensor uses capacitive sensing rather than resistive sensing like other sensors on the market to assess soil moisture levels. It’s composed of corrosion-resistant material, so it’ll last a long time. Place it in the soil around your plants and use the real-time soil moisture data to keep track of them. This module has an integrated voltage regulator that allows it to operate between 3.3 and 5.5V. It’s ideal for low-voltage microcontrollers that require both 3.3V and 5V power.

Benefits of the proposed system:

  • Visual display using LCD display unit.
  • Watering depends on the moisture level present in the field.
  • All the farm parameters can view through online in graphical notation.
  • Efficient and low-cost design.
  • Fast response.
  • User friendly.
  • Better control of the overall internal process
  • High Productivity

Capacitive Soil Moisture Sensor v1.2

For optimum growth, plants need to be watered on a regular basis. This soil moisture sensor is used to determine the amount of moisture or water in the soil. This is an analog capacitive soil moisture sensor that uses capacitive sensing to assess soil moisture levels. Capacitance is adjusted according to the amount of water in the soil. The capacitance is transformed to a voltage level ranging from 1.2V to 3.0V. Capacitive Soil Moisture Sensors have the advantage of being built of a corrosion-resistant substance, resulting in long service life.

Features & Specifications

  • Supports 3-Pin Sensor interface
  • Analog output
  • Operating Voltage: DC 3.3-5.5V
  • Output Voltage: DC 0-3.0V
  • Interface: PH2.0-3P
  • Size: 99x16mm/3.9×0.63″

Capacitive Soil Moisture Sensor Schematic

The Capacitive Soil Moisture Sensor Hardware Schematic is shown below.

Capacitive Soil Moisture Sensor Schematic

A 555 Timer IC is used to create a fixed-frequency oscillator. The square wave is then sent to the sensor as if it were a capacitor. That capacitor, on the other hand, has a particular reactance to a square wave signal, or, for argument’s sake, a resistance that forms a voltage divider with a pure ohm type resistor (the 10k one on pin 3). The sensor’s capacitance increases as the soil moisture level rise. As a result, the square wave has a reduced reactance, lowering the voltage on the signal line. An analog pin on the Arduino may measure the voltage on the Analog signal pin, which indicates the humidity in the soil.

Interface Capacitive Soil Moisture Sensor with Arduino

Let’s connect the Capacitive Soil Moisture Sensor to the Arduino and show the analog value or percentage soil moisture value. This is a very simple circuit schematic.

Capacitive Soil Moisture Sensor Arduino Circuit

Connect the VCC pin of the Arduino to 3.3V and the GND pin to GND. Connect the Analog output pin to the Arduino’s A0 pin in the same way.

Soil Moisture Sensor %

Basic Source Code/Program

The source code for interfacing a capacitive soil moisture sensor with an Arduino is available here. Copy and paste the code below into your Arduino board.

After the code has been uploaded, go to the serial monitor and check the soil moisture value in percentages ( percent ). Then, dip the soil moisture sensor probe in water, soil, or other liquid to determine the soil moisture value.

const int AirValue = 620; //you need to replace this value with Value_1
const int WaterValue = 310; //you need to replace this value with Value_2
int soilMoistureValue = 0;
int soilmoisturepercent=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
Serial.println(soilMoistureValue);
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
if(soilmoisturepercent >= 100)
{
Serial.println(“100 %”);
}
else if(soilmoisturepercent <=0)
{
Serial.println(“0 %”);
}
else if(soilmoisturepercent >0 && soilmoisturepercent < 100)
{
Serial.print(soilmoisturepercent);
Serial.println(“%”);

}
delay(250);
}

Interface Capacitive Soil Moisture Sensor with Arduino & 16X2 LCD Display

Now we’ll connect the Capacitive Soil Moisture Sensor to the Arduino and display the analog value or soil moisture value in percentage on the LCD Display. This is a very simple circuit schematic.

Capacitive Soil Moisture Sensor Arduino

Connect the VCC pin of the Arduino to 3.3V and the GND pin to GND. Connect the Analog output pin to the Arduino’s A0 pin in the same way. Connect the LCD’s 1, 3, 16 pins to GND and the 2, 15 pins to 5V VCC. Connect LCD pins 4, 6, 11, 12, 13, 14 to Arduino pins 12, 11, 5, 4, 3, 2 on the Arduino.

Source Code/Program

The source code for interfacing a capacitive soil moisture sensor with an Arduino and a 16×2 LCD display is available here. Copy and paste the code below into your Arduino board.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int AirValue = 600; //you need to replace this value with Value_1
const int WaterValue = 350; //you need to replace this value with Value_2
int soilMoistureValue = 0;
int soilmoisturepercent=0;
void setup() {
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
lcd.begin(16, 2);
}
void loop() {
soilMoistureValue = analogRead(A0); //put Sensor insert into soil
Serial.println(soilMoistureValue);
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
if(soilmoisturepercent >= 100)
{
Serial.println(“100 %”);
lcd.setCursor(0, 0);
lcd.print(“Soil Moisture”);
lcd.setCursor(0, 1);
lcd.print(“100 %”);
delay(250);
lcd.clear();
}
else if(soilmoisturepercent <=0)
{
Serial.println(“0 %”);
lcd.setCursor(0, 0);
lcd.print(“Soil Moisture”);
lcd.setCursor(0, 1);
lcd.print(“0 %”);
delay(250);
lcd.clear();
}
else if(soilmoisturepercent >0 && soilmoisturepercent < 100)
{
Serial.print(soilmoisturepercent);
Serial.println(“%”);
lcd.setCursor(0, 0);
lcd.print(“Soil Moisture”);
lcd.setCursor(0, 1);
lcd.print(soilmoisturepercent);
lcd.print(” %”);
delay(250);
lcd.clear();
}
}

After the code has been uploaded, the LCD will begin to display the soil moisture value as a percentage ( percent ). Then, dip the soil moisture sensor probe in water, soil, or other liquid to determine the soil moisture value.

Interface Capacitive Soil Moisture Sensor with OLED Display & Arduino

Let’s connect the Capacitive Soil Moisture Sensor to an OLED Display and an Arduino to display the analogue value or percentage soil moisture value. This is a very simple circuit schematic.

Capacitive Soil Moisture Sensor Arduino OLED

Connect the VCC pin of the Arduino to 3.3V and the GND pin to GND. Connect the Analog output pin to the Arduino’s A0 pin in the same way. VCC, GND, SDA, and SCL are the four pins of the I2C OLED Display. So, connect VCC to Arduino’s 5V and GND to GND. Connect the SDA pin to Arduino pin A4 and the SCL pin to Arduino pin A5.

Source Code/Program

Here’s how to connect a capacitive soil moisture sensor to an OLED display and an Arduino. Copy and paste the code below into your Arduino board.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

const int AirValue = 620; //you need to replace this value with Value_1
const int WaterValue = 310; //you need to replace this value with Value_2
int soilMoistureValue = 0;
int soilmoisturepercent=0;
void setup() {
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128×64)
display.clearDisplay();
}
void loop() {
soilMoistureValue = analogRead(A0); //put Sensor insert into soil
Serial.println(soilMoistureValue);
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
if(soilmoisturepercent >= 100)
{
Serial.println(“100 %”);

display.setCursor(45,0); //oled display
display.setTextSize(2);
display.setTextColor(WHITE);
display.println(“Soil”);
display.setCursor(20,15);
display.setTextSize(2);
display.setTextColor(WHITE);
display.println(“Moisture”);

display.setCursor(30,40); //oled display
display.setTextSize(3);
display.setTextColor(WHITE);
display.println(“100 %”);
display.display();

delay(250);
display.clearDisplay();
}
else if(soilmoisturepercent <=0)
{
Serial.println(“0 %”);

display.setCursor(45,0); //oled display
display.setTextSize(2);
display.setTextColor(WHITE);
display.println(“Soil”);
display.setCursor(20,15);
display.setTextSize(2);
display.setTextColor(WHITE);
display.println(“Moisture”);

display.setCursor(30,40); //oled display
display.setTextSize(3);
display.setTextColor(WHITE);
display.println(“0 %”);
display.display();

delay(250);
display.clearDisplay();
}
else if(soilmoisturepercent >0 && soilmoisturepercent < 100)
{
Serial.print(soilmoisturepercent);
Serial.println(“%”);

display.setCursor(45,0); //oled display
display.setTextSize(2);
display.setTextColor(WHITE);
display.println(“Soil”);
display.setCursor(20,15);
display.setTextSize(2);
display.setTextColor(WHITE);
display.println(“Moisture”);

display.setCursor(30,40); //oled display
display.setTextSize(3);
display.setTextColor(WHITE);
display.println(soilmoisturepercent);
display.setCursor(70,40);
display.setTextSize(3);
display.println(” %”);
display.display();

delay(250);
display.clearDisplay();
}
}

The soil moisture value in percentage will be displayed on the OLED Display once the code has been uploaded ( percent ). Then, dip the soil moisture sensor probe in water, soil, or other liquid to determine the soil moisture value.

Capacitive Soil Moisture Sensor Calibration

While talking about the accuracy, the capacitive soil moisture sensor is not so much accurate as expected. But you can do the calibration to get the closest accurate reading. Just upload the simple code to Arduino and check the sensor analog reading when the sensor is in dry air and when the sensor is in water. From here you can find the maximum and minimum analog values that can be mapped to percentage values from 0 to 100% as per the program.

constintAirValue = 600; //you need to replace this value with Value_1
constintWaterValue = 350; //you need to replace this value with Value_2

From the above change the AirValue and WaterValue with the value you got.

Conclusion

I hope all of you had understand how to Interface Capacitive Soil Moisture Sensor v1.2 with Arduino. We Matha Electronics will be back soon with more informative blogs.

Leave a Reply

Your email address will not be published.