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 » Capacitive Soil Moisture Sensor with ESP8266/ESP32 & OLED Display
ESP8266 Projects

Capacitive Soil Moisture Sensor with ESP8266/ESP32 & OLED Display

Mamtaz AlamBy Mamtaz AlamUpdated:May 26, 20238 Comments6 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Capacitive Soil Moisture Sensor ESP8266
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

In this project, we are going to interface Capacitive Soil Moisture Sensor with NodeMCU ESP8266/ESP32 & OLED Display. We will display the soil moisture value in percentage (%) both in Serial Monitor and 0.96″ OLED Display. We will learn the calibration method for displaying the correct value as well.


Overview

This project is about NodeMCU ESP8266 or ESP32 and Capacitive Soil Moisture Sensor with OLED Display. 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 on-board 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.



You can go through our previous post to learn more about this sensor:
1. Interfacing Capacitive Soil Moisture Sensor with Arduino
2. IoT Based Smart Irrigation System
3. LoRa Based Smart Agriculture


Components Required

The following are the components required for making this project. All the components can be easily purchased from the Amazon. The components purchase links are given below as well.

S.N.Components NameQuantityPurchase Links
1NodeMCU ESP8266 Board1Amazon | AliExpress
2ESP32 Board1Amazon | AliExpress
3Capacitive Soil Moisture Sensor1Amazon | AliExpress
40.96" I2C 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 ESP8266 which represents the humidity in the soil.




0.96″ I2C OLED Display

This is a 0.96 inch blue OLED display module. The display module can be interfaced with any microcontroller using SPI/IIC protocols. It is having a resolution of 128×64. The package includes display board, display,4 pin male header pre-soldered to board.

I2C OLED Display

OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin, multi-layered organic film placed between an anode and cathode. In contrast to LCD technology, OLED does not require a backlight. OLED possesses high application potential for virtually all types of displays and is regarded as the ultimate technology for the next generation of flat-panel displays.


Capacitive Soil Moisture Sensor with ESP8266 & OLED Display

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

Capacitive Soil Moisture Sensor ESP8266

Connect the VCC pin to 3.3V of NodeMCU and GND to GND. Similarly, connect the Analog output pin to A0 pin of NodeMCU ESP8266. The I2C OLED Display has 4 pins as VCC, GND, SDA & SCL. So Connect VCC to 3.3V of NodeMCU & GND to GND. Connect its SDA pin to D2 of NodeMCU & SCL to D1.

Soil Moisture Sensor ESP8266


Source Code/Program

Here is a simple source code for Interfacing Capacitive Soil Moisture Sensor with NodeMCU ESP8266 OLED Display. Copy the code from below and upload it to your ESP8266 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
92
93
94
95
96
97
98
99
100
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
const int AirValue = 790;   //you need to replace this value with Value_1
const int WaterValue = 390;  //you need to replace this value with Value_2
const int SensorPin = A0;
int soilMoistureValue = 0;
int soilmoisturepercent=0;
 
 
void setup() {
  Serial.begin(115200); // 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(SensorPin);  //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 with ESP32 & OLED Display

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

Capacitive Soil Moisture Sensor ESP32

Connect the VCC pin to 3.3V of ESP32 and GND to GND. Similarly, connect the Analog output pin to the GPIO15 pin of ESP32. The I2C OLED Display has 4 pins as VCC, GND, SDA & SCL. So Connect VCC to 3.3V of ESP32 & GND to GND. Connect its SDA pin to D21 of ESP32 & SCL to D22.

Capacitive Soil Moisture Sensor with ESP32 & OLED Display


Source Code/Program

Here is a simple source code for Interfacing Capacitive Soil Moisture Sensor with ESP32 & OLED Display. Copy the code from below and upload it to your ESP32 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
92
93
94
95
96
97
98
99
100
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
const int AirValue = 3620;   //you need to replace this value with Value_1
const int WaterValue = 1680;  //you need to replace this value with Value_2
const int SensorPin = 15;
int soilMoistureValue = 0;
int soilmoisturepercent=0;
 
 
void setup() {
  Serial.begin(115200); // 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(SensorPin);  //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 ESP8266/ESP32 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 value that can be mapped to percentage value from 0 to 100% as per 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.

If you want to learn about the Resistive Soil Moisture Sensor you can following the following post: Monitor Resistive Soil Moisture Sensor Data with Nodemcu on Thingspeak

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleIoT Based Patient Health Monitoring on ESP32 Web Server
Next Article IoT ECG Monitoring with AD8232 ECG Sensor & ESP8266

Related Posts

Humidity & Temperature Monitoring using DHT11 & NodeMCU on ThingSpeak

ESP8266 & DHT11 Humidity Temperature Monitor on ThingSpeak

Updated:October 19, 20253443K
Water Tank Level Monitoring System with GSM & ESP8266

Monitor Water Tank Level with GSM & ESP8266 on Blynk

Updated:June 28, 20255K
IoT-enabled Smart Fridge with ESP8266 & DS18B20

IoT-enabled Smart Fridge with ESP8266 WebServer

Updated:February 2, 202525K
How to Flash or Upgrade Firmware on ESP8266 (ESP-01)

How to Flash or Upgrade Firmware on ESP8266 (ESP-01)

Updated:February 2, 202514K
IoT Based Patient Health Monitoring System using ESP8266 & Arduino

IoT Patient Health Monitoring with ESP8266 & Arduino

Updated:February 2, 2025156K
IoT Solar Panel Monitoring System with ESP8266 & MQTT

IoT Solar Panel Monitoring System with ESP8266 & MQTT

Updated:February 2, 202518K
View 8 Comments

8 Comments

  1. SR on March 29, 2020 12:17 AM

    Great (and timely) project for the season. I wonder if this can be made more useful by incorporating multiple sensors? I also wonder how far from the sensor the ESP8266 can be?

    Great project, though!

    -SR

    Reply
    • Mr. Alam on March 29, 2020 8:52 PM

      Hi, thanks for the valuable feedback. I am thinking to incorporate automatic irrigation system on the basis of soil moisture analysis. I will do that in coming week. Cheers

      Reply
  2. d3m on July 14, 2020 12:12 AM

    Could you please quantify :
    How much do the calibration numbers vary from one individual sensor to another?
    How long does Vcc have to remain stable before the analog output is stable?
    How does analog output vary with Vcc slowly (over days) declining from 5V to 3..5 volts?

    Thanks.

    Reply
  3. Jeffrey D'Silva on September 21, 2020 6:10 PM

    Great tutorial!! Just one quick question.. Everything has been connected correctly but when not in water, the screen is outputting 100% moisture and the value is not changing – regardless if in water or not. Any idea why this is happening?

    Reply
  4. Jeffrey D'Silva on September 22, 2020 3:57 AM

    Great tutorial!! Just one quick question.. Everything has been connected correctly but when not in water, the screen is outputting 100% moisture and the value is not changing – regardless if in water or not. Any idea why this is happening?

    Reply
  5. Rodrigo Moura Pereira on October 7, 2020 9:05 PM

    Is it possible to obtain the dielectric permittivity with this sensor?

    Reply
  6. Kristy Merriam on October 12, 2020 2:28 AM

    I had the same issue but resolved it by swapping the around the values in the map function. So it looks like this:

    soilmoisturepercent = map(soilMoistureValue, WaterValue, AirValue, 100, 0);

    Reply
  7. haohaozhu21 on April 30, 2022 2:09 PM

    hi,Can you tell me how the analog circuit used in your article is drawn, I want to write an undergraduate thesis and want to use this beautiful illustration. Thank you so much for being able to tell me

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 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
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use INA226 DC Current Sensor with Arduino
    How to use INA226 DC Current Sensor with Arduino
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • IoT Based Electricity Energy Meter using ESP32 & Blynk
    IoT Based Electricity Energy Meter using ESP32 & Blynk
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
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 (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • 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.