Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Interface Capacitive Soil Moisture Sensor v1.2 with Arduino
Arduino Projects

Interface Capacitive Soil Moisture Sensor v1.2 with Arduino

Mamtaz AlamBy Mamtaz AlamUpdated:November 19, 202219 Comments6 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Interface Capacitive Soil Moisture Sensor with Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

In this project, we are going to interface Capacitive Soil Moisture Sensor with Arduino & 16×2 LCD Display & display the soil moisture value in percentage (%) both in Serial Monitor and LCD Display & OLED Display. We will learn the calibration method for displaying the correct value.


Overview

This project is about Arduino and Capacitive Soil Moisture Sensor & LCD/OLED Interfacing Tutorial. Soil moisture is basically the amount/content of water present in the soil. This can be measured using a soil moisture sensor either resistive or capacitive. Here we will use Capacitive Soil Moisture Sensor v1.2. This sensor measures the volumetric content of water inside the soil and gives us the moisture level as output.

This soil moisture sensor measures soil moisture levels by capacitive sensing rather than resistive sensing like other sensors on the market. It is made of corrosion-resistant material which gives it excellent service life. Insert it into the soil around your plants and monitor the real-time soil moisture data. This module includes an onboard voltage regulator which gives it an operating voltage range of 3.3 ~ 5.5V. It is perfect for low-voltage microcontroller with both 3.3V and 5V power supply.



Bill of Materials

The following are the components that you need for making this project. You can purchase all the components from Amazon.

S.N.Components QuantityPurchase Links
1Arduino UNO Board1Amazon | AliExpress
2Capacitive Soil Moisture Sensor1Amazon | AliExpress
316x2 LCD Display1Amazon | AliExpress
40.96" OLED Display1Amazon | AliExpress
5Connecting Wires10Amazon | AliExpress
6Breadboard1Amazon | AliExpress


Capacitive Soil Moisture Sensor v1.2

Overview

This is an analog capacitive soil moisture sensor which measures soil moisture levels by capacitive sensing, i.e capacitance is varied on the basis of water content present in the soil. The capacitance is converted into voltage level basically from 1.2V to 3.0V maximum. The advantage of Capacitive Soil Moisture Sensor is that they are made of a corrosion-resistant material giving it a long service life.

Capacitive Soil Moisture Sensor v1.2

Features & Specifications

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

Capacitive Soil Moisture Sensor Schematic

The Hardware Schematic for Capacitive Soil Moisture Sensor is given below.

Capacitive Soil Moisture Sensor Schematic

There is a fixed frequency oscillator that is built with a 555 Timer IC. The square wave generated is then fed to the sensor like a capacitor. To a square wave signal that capacitor, however, has a certain reactance, 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 greater is the soil moisture, the higher the capacitance of the sensor. Consequently, there is a smaller reactance to the square wave, thus lowering the voltage on the signal line. The voltage on the Analog signal pin can be measured by an analog pin on the Arduino which represents the humidity in the soil.

To learn more about the sensor, check the Capacitive Soil Moisture Sensor Datasheet.




Interface Capacitive Soil Moisture Sensor with Arduino

Now lets interface the Capacitive Soil Moisture Sensor with Arduino and display the analog value or soil moisture value in percentage. The circuit diagram for this is very simple.

Capacitive Soil Moisture Sensor Arduino Circuit

Connect the VCC pin to 3.3V of Arduino and GND to GND. Similarly, connect the Analog output pin to A0 pin of Arduino.

Soil Moisture Sensor %


Basic Source Code/Program

Here is a simple source code for Interfacing Capacitive Soil Moisture Sensor with Arduino. Copy the code from below and upload it to your Arduino board.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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);
}

Once the code is uploaded you can click on serial monitor & check soil moisture value in percentage(%). Then test the soil moisture value by dipping the soil moisture sensor probe in water or in soil or any liquid.


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

Now lets interface the Capacitive Soil Moisture Sensor with Arduino & LCD Display and display the analog value or soil moisture value in percentage. The circuit diagram for this is very simple.

Capacitive Soil Moisture Sensor Arduino

Connect the VCC pin to 3.3V of Arduino and GND to GND. Similarly, connect the Analog output pin to A0 pin of Arduino. Connect 1, 3, 16 pin of LCD to GND & connect 2, 15 to 5V VCC. Similarly connect pin 4, 6, 11, 12, 13, 14 of LCD to Arduino 12, 11, 5, 4, 3, 2 of Arduino.

Source Code/Program

Here is a simple source code for Interfacing Capacitive Soil Moisture Sensor with Arduino & 16×2 LCD Display. Copy the code from below and upload it to your Arduino board.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#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();
}  
}

Once the code is uploaded you can LCD starting to display the soil moisture value in percentage(%). Then test the soil moisture value by dipping the soil moisture sensor probe in water or in soil or any liquid.


Interface Capacitive Soil Moisture Sensor with OLED Display & Arduino

Now lets interface the Capacitive Soil Moisture Sensor with OLED Display & Arduino and display the analog value or soil moisture value in percentage. The circuit diagram for this is very simple.

Capacitive Soil Moisture Sensor Arduino OLED

Connect the VCC pin to 3.3V of Arduino and GND to GND. Similarly, connect the Analog output pin to A0 pin of Arduino. The I2C OLED Display has 4 pins as VCC, GND, SDA & SCL. So Connect VCC to 5V of Arduino & GND to GND. Connect its SDA pin to A4 of Arduino & SCL to A5.



Source Code/Program

Here is a simple source code for Interfacing Capacitive Soil Moisture Sensor with OLED Display & Arduino. Copy the code from below and upload it to your Arduino board.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#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 (128x64)
  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();
}  
}

Once the code is uploaded the OLED Display will start showing the soil moisture value in percentage(%). Then test the soil moisture value by dipping the soil moisture sensor probe in water or in soil or any liquid.




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.

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

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


Video Tutorial: Interface Capacitive Soil Moisture Sensor with Arduino & LCD

Interfacing Capacitive Soil Moisture Sensor v1.2/v2 with Arduino & Monitoring on Display
Watch this video on YouTube.

You can check the application of this sensor here: IoT Based Smart Agriculture System.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleRFID RC522 Attendance System Using Arduino with Data Logger
Next Article Interfacing RGB LED Strip with Arduino with Fade & Color Effect

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 19 Comments

19 Comments

  1. Γιάννης Σαμπιωτάκης on April 24, 2020 8:32 PM

    Hi .Thanks a lot for the project.Its my first project, although i have arduino over 10 years now.I had a small issue :When moisture is 0% or 100% lcd doesn’t print “Soil Moisture 0%” or “Soil Moisture 100%” , it starts printing from 1 to 99 .Add symbol “=” after symbol “>” and “<” to these lines ” if(soilmoisturepercent > 100)” “else if(soilmoisturepercent <0)” and its ok.
    So, you have ” if(soilmoisturepercent >= 100)” “else if(soilmoisturepercent <=0)”

    Reply
    • Mr. Alam on April 24, 2020 8:47 PM

      Thanks for the correction and for letting me know my small mistake.
      I forgot to add ” if(soilmoisturepercent >= 100)” “else if(soilmoisturepercent <=0)”.

      Reply
  2. Rene on May 28, 2020 1:09 AM

    Hey,

    nice work! i was seachring for a shematic of the 555 Timer circuit used in this sensor. Now i found yours, and simulated it using Falstad. However is there a connection Between RST Pin 4 and VCC missing?

    The simulated circuit only works if I connect RST and VCC, but they are not connected in you shematic right?

    Reply
  3. Manue on July 27, 2020 3:32 AM

    Hi,

    Have you monitored the readings over time when the sensor is dipped in soil? I am using it for a irrigation project, but the sensor readings are hard to interpret since there is no visible pattern showing the soil getting dry.

    Thanks,
    Manuel

    Reply
  4. Raghul on September 26, 2020 9:38 PM

    Is the code above for oled is with changes?

    Reply
  5. Raghul Prasanth on October 7, 2020 1:09 PM

    I used the same code. But it shows only soil and moisture in the display. Percentage is not displaying in the display

    Reply
  6. Bassem zayed on March 25, 2021 9:45 PM

    Hi

    Did u find a solution for these soil sensors reliability, as I am experiencing something similar to what u just explained.

    Thanks

    Reply
  7. itdir on March 30, 2021 10:03 AM

    I think it is because the output is not buffered. I would suggest very short (and shielded) leads from the sensor to a unity gain amp (buffer) before connecting it to the analog input. Also be aware the Vref for the internal ADC is not regulated, so power fluctuations in the supply will cause both the 555 output and the Analog input to vary. This can partly be smoothed out by taking multiple samples and averaging them.

    Reply
  8. itdir on April 1, 2021 10:07 AM

    The 555 circuit is not correct. R3 is 330 ohms, not 330k. Pin 4 (RST) should be tied to Vcc

    Reply
  9. Anthony Johnson on April 4, 2021 3:05 AM

    Could you please explain where Value_1 and Value_2 are obtained. There seems to be no mention of them elsewhere?

    Reply
  10. Dejmos on May 12, 2021 5:03 PM

    I think the analog read function will help you – read the values from a given pin in air and water

    Reply
  11. wrybread on June 9, 2021 8:28 AM

    You left out some really important information…

    The value of “AirValue” (or “Value_1”) is the value of the moisture sensor when dry in air, and “WaterValue” (or “Value_2”) is the value of the moisture sensor when submerged in water.

    Reply
  12. wrybread on June 9, 2021 9:34 AM

    He forgot a critical component, see my comment below.

    Reply
  13. Kipper on June 17, 2021 5:00 PM

    Thank you!

    Reply
  14. Henri Jim Collins on February 6, 2022 3:10 AM

    we tried to set this up and run it… LED gave us garbage lines on line 1, and never worked. Also – you never really explained, listed or showed how the potentiometer is a part of this or what it does. Are we missing something here?

    Reply
  15. Faby on June 1, 2022 2:41 PM

    What does VCC stand for ?

    Reply
  16. Hugo Lutz on November 18, 2022 12:04 PM

    Quellcode für die Schnittstelle des kapazitiven Bodenfeuchtesensors mit Arduino und einem 16×2 LCD Display hat Fehler.Muss ich jetzt mit 75 Jahren noch Linux lernen.
    MfG. H. Lutz

    Reply
  17. Khoo Xin Yie on June 12, 2023 10:43 AM

    Thank you so much! Your finding really helps me when I am still wondering why my serial print value keeps showing 0%.

    Reply
  18. Phineas Cook on March 5, 2024 7:47 PM

    Thank you so much! I used this as part of my auto irrigation system, and it worked great. Thank you!

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 16, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • RS-485 Half-Duplex Communication with MAX485 & Arduino
    RS-485 Half-Duplex Communication with MAX485 & Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • IoT Based PM & Air Quality Monitoring System using ESP32
    IoT Based PM & Air Quality Monitoring System using ESP32
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
  • ESP32 CAM Object Detection & Identification with OpenCV
    ESP32 CAM Object Detection & Identification with OpenCV
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.