ESP32 S3 - Soil Moisture Sensor

Learning to read soil moisture with your ESP32 S3 opens the door to smart gardening projects, automated irrigation systems, and environmental monitoring. This tutorial covers everything from wiring the sensor and reading raw analog values to calibrating thresholds and detecting wet or dry soil conditions.

What you'll build:

  1. A circuit connecting a capacitive soil moisture sensor to the ESP32 S3
  2. A sketch that reads and displays raw analog moisture values on the Serial Monitor
  3. A calibrated version that prints "WET" or "DRY" status based on your threshold
  4. A foundation for automated plant watering and smart garden applications
ESP32 S3 - Soil Moisture Sensor

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Capacitive Soil Moisture Sensor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: Many soil moisture sensors available in the market are unreliable, regardless of their version. We strongly recommend buying the sensor with TLC555I Chip from the DIYables brand using the link provided above. We tested it, and it worked reliably.

Overview of Soil Moisture Sensor

Soil moisture sensors measure the water content in soil by outputting an analog voltage signal that your ESP32 S3 reads through its ADC (Analog-to-Digital Converter). There are two main types available, and understanding their differences will help you choose the right one for your project.

capacitive moisture sensor vs resistive moisture sensor

The resistive moisture sensor passes electrical current between two exposed metal probes to measure soil resistance. While inexpensive and simple, this design is prone to electrochemical corrosion over time, which degrades accuracy and requires frequent sensor replacement. The capacitive moisture sensor, by contrast, detects moisture through capacitance changes without exposing electrodes directly to soil. This eliminates corrosion, extends the sensor's lifespan significantly, and produces more consistent long-term readings — making it the preferred choice for permanent or semi-permanent installations.

resistive soil moisture sensor corrosion

The rest of this ESP32 S3 soil moisture sensor tutorial focuses on the capacitive type for its superior reliability.

Key Specifications

The capacitive soil moisture sensor operates on 3.3V–5V power, making it directly compatible with the ESP32 S3's 3.3V rail. Its analog output voltage is inversely proportional to soil moisture: higher water content produces a lower output voltage, while drier soil produces a higher voltage. The sensor has no exposed electrodes in contact with soil, which prevents the corrosion problems found in resistive designs.

Capacitive Soil Moisture Sensor Pinout

The capacitive soil moisture sensor exposes three pins for connecting to your ESP32 S3.

capacitive soil moisture sensor pinout
  1. GND: Ground connection — connect to GND (0V)
  2. VCC: Power supply — connect to 3.3V
  3. AOUT: Analog output pin — outputs a voltage inversely proportional to moisture level (higher moisture = lower voltage)

How the Capacitive Moisture Sensor Works

The ESP32 S3 reads the voltage on the AOUT pin through its built-in ADC. Because the relationship is inverse, you will observe lower ADC values when soil is wet and higher values when soil is dry. The sensor never touches or corrodes because it measures the dielectric properties of the surrounding soil through capacitance rather than direct electrical contact.

Wiring Diagram

Connect your capacitive soil moisture sensor to the ESP32 S3 using the pin assignments in the table below. The sensor runs comfortably on 3.3V, so no level shifting or additional components are required.

Safety Notes

Keep the circuit board (the top portion of the sensor with the electronics) above the soil or water line at all times. Only the probe section should be inserted into soil. If testing in liquid, use salt water rather than pure water — pure water has very low conductivity and will not affect the sensor readings. Operating the sensor at 3.3V on the ESP32 S3 is safe and avoids any voltage compatibility issues.

The wiring diagram between ESP32 S3 soil moisture sensor

This image is created using Fritzing. Click to enlarge image

Moisture Sensor Pin ESP32 S3 Pin
GND GND
VCC 3.3V
AOUT GPIO6 (ADC1_CH5)

ESP32 S3 Code - Reading Moisture Values

The following sketch configures GPIO6 as an analog input, reads the moisture sensor value every 500 milliseconds, and prints the result to the Serial Monitor. Running this code first is the essential step for calibrating your sensor before moving on to wet/dry detection.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-soil-moisture-sensor */ #define AOUT_PIN 6 // The ESP32 S3 pin GPIO6 that connects to AOUT pin of moisture sensor void setup() { Serial.begin(115200); // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); } void loop() { int value = analogRead(AOUT_PIN); // read the analog value from sensor Serial.print("Moisture value: "); Serial.println(value); delay(500); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the capacitive soil moisture sensor to your ESP32 S3 as shown in the diagram above.
  3. Connect the ESP32 S3 to your computer via USB Type-C cable.
  4. Open Arduino IDE and select the ESP32 S3 board and correct COM port.
  5. Copy the code above and paste it into Arduino IDE.
  6. Click the Upload button to program your ESP32 S3.
  7. Place the sensor probe in soil and open the Serial Monitor at 115200 baud.
  8. Observe how the values change as you slowly add water to the soil.
  9. Record your dry and wet readings — you will need them for calibration.
  10. Pro Tip: Use a consistent soil type and sensor insertion depth during calibration to get threshold values that transfer reliably across your project.

Serial Monitor Output

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-06-16 09:14:02] Moisture value: 2231 [2026-06-16 09:14:02] Moisture value: 2228 [2026-06-16 09:14:03] Moisture value: 2255 [2026-06-16 09:14:03] Moisture value: 2281 [2026-06-16 09:14:04] Moisture value: 2314 [2026-06-16 09:14:04] Moisture value: 2351 [2026-06-16 09:14:05] Moisture value: 1263 [2026-06-16 09:14:05] Moisture value: 1271 [2026-06-16 09:14:06] Moisture value: 1258 [2026-06-16 09:14:06] Moisture value: 1265 [2026-06-16 09:14:07] Moisture value: 1249 [2026-06-16 09:14:07] Moisture value: 1262 [2026-06-16 09:14:08] Moisture value: 1488 [2026-06-16 09:14:08] Moisture value: 1649 [2026-06-16 09:14:09] Moisture value: 1747
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

※ NOTE THAT:

  • Do not use pure water for testing because it doesn't conduct electricity, so it won't impact sensor readings.
  • Sensor readings never drop to zero. It's normal for values to be between 3100 and 2600, although this may change due to factors such as the depth of sensor placement, soil or water composition, and power supply voltage.
  • Avoid burying the circuit part (located on top of the sensor) in soil or water, as this could potentially harm the sensor.

Calibration for Capacitive Soil Moisture Sensor

Because the capacitive soil moisture sensor outputs relative values that shift depending on soil type, water salinity, and insertion depth, calibration is a necessary step before your ESP32 S3 can make accurate wet or dry decisions. A threshold that works perfectly in loamy garden soil may be completely wrong for sandy or clay-heavy soil.

The calibration process is straightforward: run the first sketch on your ESP32 S3, insert the sensor into the actual soil you plan to monitor, and record readings at both extremes.

  1. Start dry: Note the Serial Monitor value for completely dry soil
  2. Add water gradually: Irrigate slowly while watching the values decrease
  3. Find the transition point: Identify the reading when the soil feels damp to the touch
  4. Record the threshold: Write down the value at that dry-to-wet transition
  5. Test fully saturated soil: Note the lowest value you observe when soil is fully wet

Typical calibration results for common garden soil fall in the range of 2200–2500 for dry conditions and 1200–1500 for wet conditions. Your threshold should be the midpoint between your recorded dry and wet extremes.

Determine if the Soil is Wet or Dry

After calibration, you can update the threshold constant in the following sketch and upload it to your ESP32 S3 to get clear "WET" or "DRY" status messages alongside the raw sensor reading.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-soil-moisture-sensor */ #define AOUT_PIN 6 // The ESP32 S3 pin GPIO6 that connects to AOUT pin of moisture sensor #define THRESHOLD 1500 // CHANGE YOUR THRESHOLD HERE void setup() { Serial.begin(115200); // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); } void loop() { int value = analogRead(AOUT_PIN); // read the analog value from sensor if (value > THRESHOLD) Serial.print("The soil is DRY ("); else Serial.print("The soil is WET ("); Serial.print(value); Serial.println(")"); delay(500); }

Quick Steps for Wet/Dry Detection

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Replace the THRESHOLD value in the code with the number you recorded during calibration.
  3. Upload the updated code to your ESP32 S3.
  4. Insert the sensor probe into your soil at the intended monitoring depth.
  5. Open the Serial Monitor at 115200 baud.
  6. Add water to verify that the threshold correctly triggers the WET and DRY messages.
  7. Fine-tune the THRESHOLD value if needed based on your results.
  8. Pro Tip: Set your threshold slightly higher than the actual transition point so that the ESP32 S3 triggers a watering action before the soil becomes critically dry.

Serial Monitor Output - Wet/Dry Status

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-06-16 09:22:11] The soil is DRY (2131) [2026-06-16 09:22:11] The soil is DRY (1943) [2026-06-16 09:22:12] The soil is DRY (1769) [2026-06-16 09:22:12] The soil is DRY (1551) [2026-06-16 09:22:13] The soil is WET (1473) [2026-06-16 09:22:13] The soil is WET (1421) [2026-06-16 09:22:14] The soil is WET (1399) [2026-06-16 09:22:14] The soil is WET (1375) [2026-06-16 09:22:15] The soil is WET (1266)
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

※ NOTE THAT:

This tutorial uses the analogRead() function to read values from an ADC (Analog-to-Digital Converter) connected to a sensor or component. The ESP32 S3's ADC is suitable for projects that do not require high accuracy. However, for projects needing precise measurements, keep the following in mind:

  • The ESP32 S3's ADC is not perfectly accurate and might require calibration for correct results. Each ESP32 S3 board can vary slightly, so calibration is necessary for each individual board.
  • Calibration can be challenging, especially for beginners, and might not always yield the exact results you want.

For projects requiring high precision, consider using an external ADC (e.g ADS1115) with the ESP32 S3 or using another Arduino, such as the Arduino Uno R4 WiFi, which has a more reliable ADC. If you still want to calibrate the ESP32 S3's ADC, refer to the ESP32 ADC Calibration Driver.

Application/Project Ideas

The ESP32 S3 paired with a capacitive soil moisture sensor is a versatile foundation for a wide range of smart gardening and environmental monitoring applications.

  1. Automatic Plant Watering System: Trigger a relay-controlled water pump when the ESP32 S3 detects soil has become too dry.
  2. Smart Garden Monitor: Transmit live moisture data to your smartphone via the ESP32 S3's built-in Wi-Fi using MQTT or HTTP notifications.
  3. Multi-Plant Monitor: Connect multiple sensors to separate ADC pins on the ESP32 S3 to track different plants or garden zones simultaneously.
  4. Data Logger: Record moisture readings over time to an SD card or cloud service for long-term plant care analysis and seasonal comparisons.
  5. Greenhouse Automation: Integrate the ESP32 S3 soil moisture readings with temperature and humidity sensors to control irrigation systems based on real-time environmental conditions.
  6. Plant Health Alert: Use an LED, buzzer, or push notification through the ESP32 S3's Wi-Fi to alert you the moment a plant needs watering.

Video Section

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

...VIDEO P7tG-t4dXZ0

...VIDEO

Challenge Yourself

These exercises will build on your ESP32 S3 soil moisture sensor skills, progressing from simple output enhancements to more sophisticated multi-sensor and power-aware designs.

  1. Beginner: Add an LED that lights up on the ESP32 S3 whenever the soil moisture sensor reports a DRY condition.
  2. Beginner: Convert the raw ADC value to a moisture percentage (0–100%) and display it on the Serial Monitor alongside the raw reading.
  3. Intermediate: Build an automatic watering system using a relay module and a small water pump controlled by the ESP32 S3.
  4. Intermediate: Send moisture data from the ESP32 S3 to a web dashboard using its Wi-Fi capabilities so you can monitor your plants remotely.
  5. Advanced: Build a multi-sensor garden system that monitors three or more plants, each with its own threshold and watering control via the ESP32 S3.
  6. Advanced: Implement deep sleep mode on the ESP32 S3 so the board wakes periodically to check moisture and then returns to sleep, enabling months of battery-powered operation.

Function References

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!