Index
Introduction
The Soil Moisture Sensor measures the water content in soil by outputting analog values that vary based on moisture levels. When connected to an ESP32-S3, you can read these values to automate irrigation systems or trigger alerts. In this tutorial, we’ll learn how to connect the sensor to the ESP32-S3 and monitor soil moisture effectively.
Required Components
- ESP32-S3 Board
- Soil Sensor
- Jumper Wires
- Breadboard (optional)
Pinout

Circuit Diagram / Wiring
- Soil Sensor VCC → VIN/5V (ESP32-S3)
- Soil Sensor GND → GND (ESP32-S3)
- Soil Sensor Analog → GPIO 14 (ESP32-S3)

Code / Programming
/*****************************************************
* Project : Soil_Moisture_Sensor_Monitor.ino
* Description : Reads analog values from a soil moisture sensor
* and converts it to percentage for display.
* Author : www.oceanlabz.in
* Modified : 1/4/2025
*****************************************************/
#define MoisturePin 14
void setup() {
Serial.begin(115200); // ESP32-S3 commonly uses 115200 baud
}
void loop() {
int soilMoistureValue = analogRead(MoisturePin); // Read raw analog value (0-4095 on ESP32-S3)
// Optional: Convert to percentage (roughly)
int moisturePercent = map(soilMoistureValue, 4095, 0, 0, 100); // Adjust based on dry/wet calibration
Serial.print("Soil Moisture Level: ");
Serial.print(moisturePercent);
Serial.println("%");
delay(1000);
}
Explanation
- The ESP32-S3 reads soil moisture using an analog-capable pin (e.g., GPIO 14).
- The sensor output is mapped to a percentage to represent moisture levels.
- The moisture value is displayed on the Serial Monitor every second.
Troubleshooting
- Incorrect readings? Make sure you’re using an ADC-capable pin
- Always reading 0 or 4095? Check sensor wiring and power supply (usually 3.3V for ESP32-S3).
- Unstable values? Place the sensor properly in the soil and avoid shorting the probes with water.