Follow us:-
0

Smart Farming : ESP32 with Soil Moisture Sensor

  • 15-07-2025

How Soil Moisture Sensor Works and Interface it with Esp32

When you hear the term “smart garden,” one of the first things that might come to mind is a setup that automatically keeps your plants healthy—measuring how dry the soil is and watering plants only when they need it. No more guessing, no more soggy roots, and no more thirsty plants!

With the help of a simple Soil Moisture Sensor, you can build a system that knows exactly when your garden needs water and takes care of it. Whether you’re just curious about automation or planning to build a complete smart irrigation system, learning how to hook up and use a soil moisture sensor with Arduino is a great place to start.

In this tutorial, we’ll guide you through everything you need to know—from wiring to reading sensor data—so you can start building your own plant-friendly tech today.

Hardware Overview

A soil moisture sensor consists of two main parts: the sensor probes and the LM393 comparator module.

The Probe

The sensor has two large, exposed metal pads that function as probes. You stick these probes into the soil to measure moisture.

Ezoic
Soil Moisture Sensor Probe

These probes work as a variable resistor, which means their resistance changes depending on how wet or dry the soil is. When the soil is wet, the resistance is lower. When the soil is dry, the resistance is higher.Ezoic

The LM393 Comparator Module

Along with the probes, the sensor includes an LM393 comparator module that provides both digital and analog outputs.

Soil Moisture Sensor Sensitivity Adjustment

The analog output (AO pin) comes directly from the changing resistance of the probes. The wetter the soil, the lower the resistance and the lower the signal at this pin.

This analog signal also goes to the LM393 comparator, which compares it to a reference voltage set by a potentiometer on the module.

Ezoic
  • If the soil is drier than the set level, the comparator gives a HIGH digital output signal at the digital pin (DO).
  • If the soil is wetter than the set level, it outputs a LOW digital signal.

This digital output can be used to trigger actions—like turning on a relay to water plants when the soil gets too dry.

You can change the moisture level threshold by turning the potentiometer. Turn it clockwise to increase the threshold (requiring drier soil to trigger) and counterclockwise to decrease the threshold (triggering when the soil is less dry).

Soil Moisture Sensor Power and Status LEDs

The module also has two indicator LEDs:

    • The Power LED lights up when the module receives power
    • The Status LED turns on when the moisture level goes above the threshold
Ezoic

How Does a Soil Moisture Sensor Work?

The soil moisture sensor measures how much water is in the soil by checking the electrical resistance between the two metal probes placed in the soil.

When the sensor is powered (through its VCC and GND pins), a small electric voltage is applied to these probes.

    • In dry soil: The soil has high resistance, making it difficult for electricity to flow between the probes.
    • In wet soil: The soil contains more water, which helps electricity flow more easily. This means the soil has low resistance, and more current can flow between the probes.

The sensor detects this change in resistance and converts it into an electrical signal (voltage).

The module processes this signal in two ways:

Analog Output (AO pin): It provides a continuous voltage that corresponds to the moisture level. You can connect this to a microcontroller like Arduino to get a detailed reading of how wet or dry the soil is.

Digital Output (DO pin): The module compares the analog output to the threshold set by the potentiometer. If the soil moisture is lower (dry) than the threshold, the module’s digital output (DO) goes HIGH. If it’s higher (wet), it goes LOW.

Soil Moisture Sensor Pinout

The soil moisture sensor is extremely simple to use and only requires four pins to connect.

AO is the analog output pin. This pin gives a variable voltage that corresponds to the moisture level in the soil—the wetter the soil, the lower the output voltage. You connect this to an analog input pin on the Arduino (like A0).

DO is the digital output pin. This pin outputs LOW when the soil moisture exceeds the threshold value set by the potentiometer, and HIGH otherwise. You connect this to a digital input pin on the Arduino.

VCC pin provides power to the sensor. It’s best to power the sensor with 3.3V to 5V. Keep in mind that the analog output value will change based on the voltage you supply.

GND is the ground pin.

Experiment 1 – Measuring Soil Moisture using Analog Output (AO)

In our first experiment, we’re going to measure how much moisture is in the soil by reading the analog output from the sensor.

Wiring

Let’s start by connecting the soil moisture sensor to the Arduino.

First, connect the VCC pin on the sensor module to the 5V pin on the Arduino, and connect the GND pin on the sensor to one of the GND pins on the Arduino.

However, there’s an important thing to keep in mind. A common issue with these sensors is that they don’t last very long because they are always in contact with moisture. In addition, if the sensor is constantly powered while inserted in the soil, it tends to corrode more quickly.

To avoid this problem, it’s a good idea to power the sensor only when you need to take a reading. A simple way to do this is by connecting the sensor’s power pin to one of the Arduino’s digital output pins, and then turning that pin HIGH (on) or LOW (off) in your code as needed.

So instead of connecting the VCC pin directly to 5V, we’ll connect it to digital pin #7 on the Arduino. This way, the Arduino can control when the sensor is powered.

Finally, connect the AO pin of the sensor to the A0 analog input pin on the Arduino.

Here’s a quick reference table for the pin connections:

 HOW TO OPERATE

// #include <LiquidCrystal_I2C.h>

#define MOI 15

// LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display


void setup() {
 pinMode(MOI,INPUT);
  Serial.begin(9600);
  Serial.println("MOISTURE START");
// lcd.init();
//  lcd.backlight();
//   lcd.setCursor(3,0);
//   lcd.print("moisture data");
//   lcd.setCursor(3, 1);
}

void loop() {
 
 int data=analogRead(MOI);
 Serial.println(data);
// lcd.print(data);
 delay(1000);
//  lcd.clear();

}

Smart Farming : ESP32 with Soil Moisture Sensor

Related Post

How do I run a script at Pico on boot?

How do I run a script at Pico on boot?

As per official documentation Step by step process for pico program run after power on:Save your pyt...

ESP32 Setup in Arduino IDE

ESP32 Setup in Arduino IDE

ESP32 Board are so popular? Mainly because of the following featuresLow-costBluetoothWiFiLow PowerDu...

Node MCU ESP8266 Setup in Arduino IDE

Node MCU ESP8266 Setup in Arduino IDE

Node MCU ESP8266 Board are so popular? Mainly because of the following features.Its true Arduino Kil...

ESP32 with L298N DC Motor Driver

ESP32 with L298N DC Motor Driver

πŸ”§ Basic IntroductionL298N is a dual H-Bridge motor driver IC that allows controlling the direction...

MotorBot with Esp32

MotorBot with Esp32

πŸ”§ Components Needed:ComponentQuantityESP32 Dev Board1L298N Motor Driver Module1DC Gear Motors (TT o...

ESP32 with ADXL335 Accelerometer

ESP32 with ADXL335 Accelerometer

The ADXL335 is a small, thin, low-power 3-axis analog accelerometer manufactured by Analog Devices....

ESP32 with Ultrasonic Sensor (HC-SR04)

ESP32 with Ultrasonic Sensor (HC-SR04)

🧠 What is an Ultrasonic Sensor?An ultrasonic sensor is a device that uses sound waves to detect how...

ESP32 with DHT11 Temperature & Humidity Sensor

ESP32 with DHT11 Temperature & Humidity Sensor

πŸ“Œ What is the DHT11 Sensor?The DHT11 is a basic, low-cost digital temperature and humidity sensor....

ESP32-Based Autonomous Fire Extinguisher Bot

ESP32-Based Autonomous Fire Extinguisher Bot

πŸ”₯ FIRE BOT – Bluetooth Controlled Fire Extinguisher RobotWelcome to the FIRE BOT project! This robo...

ESP32 with BMP180 Pressure & Temperature Sensor

ESP32 with BMP180 Pressure & Temperature Sensor

BMP180 Sensor: Digital Barometric Pressure SensorThe BMP180 is a digital barometric pressure sensor...

ESP32 with 1.8" TFT LCD Display (ST7735S)

ESP32 with 1.8" TFT LCD Display (ST7735S)

πŸ”§ 1. Hardware Overview: 1.8" TFT DisplayMost 1.8" TFT modules are based on the ST7735 driver and co...

Smart Display Interface Using SSD1306 OLED & ESP32

Smart Display Interface Using SSD1306 OLED & ESP32

The SSD1306 is a popular controller used in OLED (Organic Light Emitting Diode) displays, most commo...

ESP32 with Servo Motor

ESP32 with Servo Motor

A servo motor is a type of motor designed for precise control of angular position, making it ideal f...

ESP32 with Gravity Voice Recognition Module

ESP32 with Gravity Voice Recognition Module

The Gravity Voice Recognition Module is a user-friendly module developed by DFRobot that allows micr...

ESP32 with APDS-9960 Gesture Sensor

ESP32 with APDS-9960 Gesture Sensor

The APDS-9960 is an advanced, compact sensor from Broadcom (formerly Avago Technologies) that offers...

Smart Control: Stepper Motor with ESP32

Smart Control: Stepper Motor with ESP32

πŸ” What is the 28BYJ-48 Stepper Motor?The 28BYJ-48 is a 5V unipolar stepper motor with a built-in re...

Control in Your Hands: ESP32 with 2-Axis Joystick

Control in Your Hands: ESP32 with 2-Axis Joystick

πŸ”§ What is an Analog Joystick?An analog joystick typically has:2 potentiometers (one for X-axis, one...

ESP32 with NEO-8M GPS Module

ESP32 with NEO-8M GPS Module

πŸ“‘ What is the NEO-8M GPS Module?The NEO-8M is a high-precision GNSS GPS receiver by u-blox, capable...

ESP32 with WS2812 NeoPixel LED

ESP32 with WS2812 NeoPixel LED

πŸ”§ What is a NeoPixel?NeoPixel is Adafruit’s name for individually addressable RGB LEDs using the WS...

Motion Detected: ESP32 with PIR Sensor (HC-SR501)

Motion Detected: ESP32 with PIR Sensor (HC-SR501)

🧠 What is a PIR Sensor?PIR = Passive Infrared SensorA PIR sensor detects motion by measuring change...

ESP32 with AI Thinker GP-02 GPS Module

ESP32 with AI Thinker GP-02 GPS Module

βœ… What is AI Thinker GP-02?The AI Thinker GP-02 is a GNSS (GPS) module, designed to work with satel...

ESP32 with SIM900A GSM Module

ESP32 with SIM900A GSM Module

πŸ“‘ What is SIM900?The SIM900 is a GSM/GPRS module from SIMCom. It allows microcontrollers like ESP32...

Button with ESP32

Button with ESP32

🧠 What is a Push Button?A push button is a simple mechanical switch that connects two points in a c...

Tilt Sensor Module SW520D

Tilt Sensor Module SW520D

πŸ€” What is a Tilt Sensor?A tilt sensor (also called a ball switch or mercury switch) is a digital sw...

ESP32 with TCS34725 RGB Sensor

ESP32 with TCS34725 RGB Sensor

🎨 What is the TCS34725?The TCS34725 is a color sensor made by AMS (now part of Renesas).It detects...

ESP32 + I2C LCD for Real-Time Feedback

ESP32 + I2C LCD for Real-Time Feedback

πŸ“˜ What is an I2C LCD?An I2C LCD is a Liquid Crystal Display that uses the I2C communication protoco...

MPU6050 Accelerometer and Gyroscope Sensor

MPU6050 Accelerometer and Gyroscope Sensor

🧠 What is MPU6050?The MPU6050 is a 6-axis motion tracking device made by InvenSense. It combines:βœ…...

Digital Temperature Monitoring: ESP32 + DS18B20 Sensor System

Digital Temperature Monitoring: ESP32 + DS18B20 Sensor System

🌑️ What is DS18B20?The DS18B20 is a digital temperature sensor from Maxim Integrated (now Analog Dev...

ESP32 with DS1307 RTC Module

ESP32 with DS1307 RTC Module

⏰ What is DS1307 RTC?The DS1307 is a real-time clock IC by Maxim Integrated that keeps track of:Sec...

DFPlayer Mini with Esp32

DFPlayer Mini with Esp32

🎡 What is DFPlayer Mini?The DFPlayer Mini is a tiny, standalone MP3 audio player module. It can pla...

IR Receiver VS1838B with ESP32

IR Receiver VS1838B with ESP32

πŸ“‘ What is an IR Receiver?An IR (Infrared) Receiver module receives signals from an IR remote contro...

Rotary Encoder with Esp32

Rotary Encoder with Esp32

πŸ“Œ What is a Rotary Encoder?A rotary encoder is an electro-mechanical sensor that converts the angul...

ESP32 with Dot Matrix Display (MAX7219)

ESP32 with Dot Matrix Display (MAX7219)

πŸ“Œ What is the Dot Matrix Display with MAX7219?A Dot Matrix Display is an arrangement of LEDs in a g...

ESP-NOW with ESP32

ESP-NOW with ESP32

πŸ“Œ What is ESP-NOW?ESP-NOW is a wireless communication protocol developed by Espressif, allowing ESP...

ESP32 Joystick Controlled Robot Using ESP-NOW Protocol & L298N Motor Driver

ESP32 Joystick Controlled Robot Using ESP-NOW Protocol & L298N Motor Driver

πŸ€– ESP32 Joystick Controlled Robot Using ESP-NOW Protocol & L298N Motor DriverWireless bot control w...

ESP32 with MAX30100 HEART SENSOR

ESP32 with MAX30100 HEART SENSOR

❀️ Heart Rate & SpOβ‚‚ Sensor (MAX30100/MAX30102)πŸ”¬ Pulse Sensor | SpOβ‚‚ Monitor | Wearable Health Tech...