Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversFall ResetAmazon USFall reset deals: check better picks before checkoutAmazon US: today's deals, useful picks and quick comparisons.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
Blog

Arduino Capacitive Soil Moisture Sensor (DIY) with ESP32

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

The simplest reliable build uses a 3.3 V-compatible capacitive soil-moisture module, with its analog output connected to GPIO34 on a classic ESP32 DevKit. You can read the sensor with Arduino IDE, calibrate dry and wet reference values, and convert the result into a useful relative moisture index for plant monitoring or automatic irrigation.

This guide also explains the genuinely DIY alternative: building a capacitive probe from metal electrodes and an oscillator/readout circuit. These are different projects, so the module-based build comes first and the homemade probe is treated separately.

Arduino Capacitive Soil Moisture Sensor (DIY) with ESP32

What you will build

For the beginner build, connect a capacitive soil-moisture module to an ESP32’s analog input, print the raw ADC value, and calibrate it for the soil and plant you actually use. The result is a relative moisture reading—not a universal laboratory measurement of volumetric water content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Capacitive sensing detects changes in the electrical properties around the probe. Unlike a basic resistive probe, it does not depend on continuous current flowing between exposed electrodes in wet soil, so it generally reduces electrode corrosion. It is not corrosion-proof, however: exposed PCB material, solder joints, connectors, fertilizer salts, water ingress, temperature, soil composition, and probe placement can all affect performance.

#1 Best Overall
HiLetgo 5pcs LM393 3.3V-5V Soil Moisture Detect Sensor Soil Moisture Sensor Soil Hygrometer Detection for Arduino Automatic Watering System Robot Smart car
  • This is a simple moisture sensor can be used to detect soil moisture, when the soil water shortage, the module outputs a high level, whereas the output low.
  • Use this sensor to make an automatic watering device that will keep your garden of plants unmanaged.
  • Module dual output mode, digital output is simple, more accurate analog output.
  • Sensitivity adjustable (Figure blue digital potentiometer adjustment)
  • Comparator using LM393 chip, stable job

For a construction or garden-monitoring project, the practical workflow is:

  • Power a compatible sensor from 3.3 V.
  • Read its analog output on an ADC1 pin.
  • Record dry and wet reference values.
  • Use a relative percentage or threshold that is specific to the installation.
  • Add filtering and hysteresis before controlling a valve or pump.

Choose the right build

Approach What you build Difficulty Main advantage Main weakness
Homemade probe Two isolated metal electrodes plus an oscillator and analog readout Intermediate/advanced Maximum learning and customization Requires analog design, careful wiring, and calibration
V1.2-style module A ready-made capacitive PCB connected to an ADC Beginner Fast, inexpensive prototype Clone quality and calibration vary
Professional probe A calibrated sensor with specified moisture units Advanced/budget-dependent Better repeatability Higher cost and integration complexity

Choose a module if you want a working plant monitor quickly. Choose a homemade probe if the electronics are the project. For several sensors, permanent outdoor deployment, or comparable readings across different soil types, consider a better-specified probe or an external ADC.

Parts for the beginner ESP32 build

  • Classic ESP32 DevKit or WROOM-style development board.
  • 3.3 V-compatible capacitive soil-moisture module with VCC, GND, and AOUT.
  • Jumper wires and a breadboard.
  • USB cable suitable for the ESP32 board.
  • Optional enclosure, cable strain relief, and a protected connector.

A V1.2-style module may be specified for approximately 3.3–5.5 V operation and may produce roughly 2.5 V in dry air and 1.0 V when fully submerged, depending on the exact board. Treat those figures as vendor reference points, not universal calibration values. See the V1.2 module manual for the particular board’s pinout and specifications.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

ESP32 ADC facts that affect the design

On the original, classic ESP32, the chip has two 12-bit SAR ADCs. A nominal 12-bit raw reading runs from 0 to 4095. That range describes the digital scale, not perfect voltage accuracy. Espressif documents ADC variation and recommends calibration, averaging, or filtering where appropriate. The ESP32 datasheet explains the device-level ADC characteristics.

Use an ADC1 pin when Wi-Fi is active on classic ESP32 hardware because ADC2 access can conflict with the radio. GPIO34 is a convenient input-only ADC1 example. GPIO32 through GPIO39 are ADC1 pins on the classic ESP32, although the exact pin availability and ADC behavior differ across ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6, and other family members.

Do not assume that a pin number from a classic ESP32 DevKit applies to every board sold as an “ESP32.” Check the pinout for your exact chip and board.

Rank #2
MTDELE 10Pcs 3.3V Capacitive Soil Moisture Sensor Module
  • Capacitive Soil Moisture Sensor: Compatible with for Arduino Raspberry Pi
  • Size:98*23mm
  • Operating Voltage:3.3V DC;Output Voltage:0-3.0V DC
  • Interface Type:PH2.54 3Pin
  • Commodities include:10Pcs Soil Moisture Sensor;10Pcs connecting wire

Wire a 3.3 V capacitive sensor module

Sensor module Classic ESP32 DevKit
VCC 3.3 V
GND GND
AOUT GPIO34

GPIO34 is input-only, which is fine for an analog measurement. The sensor and ESP32 must share a common ground.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Important voltage warning

Powering a module from 5 V can make its analog output too high for a 3.3 V ESP32 ADC input. The safest default is to power a compatible module from 3.3 V, provided the exact board works correctly at that voltage.

If 5 V operation is required, establish the module’s maximum AOUT voltage first and use an appropriately calculated voltage divider or level-shifting circuit. Never connect an unknown analog output directly to the ESP32.

Install Arduino IDE and ESP32 support

  1. Install the current Arduino IDE.
  2. Follow Espressif’s current Arduino-ESP32 installation instructions to add ESP32 board support.
  3. Select the board that matches your hardware, such as the applicable ESP32 Dev Module.
  4. Select the USB port used by the board.
  5. Upload the sketch below.
  6. Open Serial Monitor at 115200 baud.

Board-package menus and supported targets change over time, so use the current official documentation rather than an old, hard-coded Board Manager URL.

Upload a raw-reading sketch first

Start with raw values before displaying a percentage. This makes wiring, voltage, and sensor faults easier to diagnose.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const int SOIL_PIN = 34;

void setup() {
  Serial.begin(115200);

  // Nominal 12-bit readings on a classic ESP32: 0–4095.
  analogReadResolution(12);

  // Common setting for an input that may approach 3.3 V.
  analogSetAttenuation(ADC_11db);
}

void loop() {
  int raw = analogRead(SOIL_PIN);

  Serial.print("Raw ADC: ");
  Serial.println(raw);

  delay(1000);
}

Move the sensor between air and soil. The raw number should change. Do not expect a particular value: supply voltage, soil type, packing, insertion depth, salinity, temperature, cable length, ESP32 variant, and ADC behavior all influence the result.

Calibrate dry and wet values

Do not copy someone else’s thresholds. A vendor example may use dryValue = 3000 and wetValue = 1200, but those are starting values only.

Basic two-point calibration

  1. Power the sensor from the same voltage used in the final installation.
  2. Place the probe in air or another defined dry reference.
  3. Wait for the reading to settle and record an average as dryValue.
  4. Place the probe in thoroughly wetted soil of the same type used by the plant.
  5. Wait for the reading to settle and record an average as wetValue.
  6. Enter those measured values in the sketch.
  7. Repeat the test several times to check that the readings are reasonably stable.

Fully submerged water is convenient for testing, but it is not necessarily the same as the useful “well watered” condition of a pot. For plant monitoring, calibrate in the final soil mix.

Convert the result to a relative percentage

const int SOIL_PIN = 34;

// Replace these with values measured in your installation.
int dryValue = 3000;
int wetValue = 1200;

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
  analogSetAttenuation(ADC_11db);
}

void loop() {
  int raw = analogRead(SOIL_PIN);

  // Maps the measured dry point to 0% and wet point to 100%.
  int moisturePercent = map(raw, dryValue, wetValue, 0, 100);
  moisturePercent = constrain(moisturePercent, 0, 100);

  Serial.print("Raw ADC: ");
  Serial.print(raw);
  Serial.print("  Moisture: ");
  Serial.print(moisturePercent);
  Serial.println("%");

  delay(1000);
}

The percentage is a normalized index for one sensor, soil, container, supply voltage, and installation. It is not automatically an absolute soil-moisture percentage.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use plant-specific watering thresholds

A useful threshold is based on when the plant actually needs water. Record the reading just after thorough watering, then allow the soil to dry until watering is desirable and record that value. For example, a control system might start watering below 30% and stop only after the reading exceeds 45%. Those numbers are examples, not universal plant requirements.

Reduce noise with averaging

ADC readings can fluctuate. A short average is usually sufficient for a plant monitor:

int readAverage(int pin, int samples = 16) {
  long total = 0;

  for (int i = 0; i < samples; i++) {
    total += analogRead(pin);
    delay(10);
  }

  return total / samples;
}

More samples reduce random noise but increase response time and energy use. A median filter can help when occasional readings spike. The older reference project averages five readings taken one second apart, producing a much slower but visibly stable result.

Rank #4
Stemedu 5PCS Capacitive Analog Soil Moisture Sensor Module 3.3~5.5V Corrosion Resistant Humidity Detection Sensors DIY Electronic for Arduino for Raspberry Pi
  • 【Version】This capacitive analog soil moisture sensor is V1.2
  • 【Voltage】Working voltage: 3.3~5.5 VDC, output voltage: 0~3.0 VDC
  • 【Interface】Interface: PH2.54-3P, Pin: Analog signal output, GND, VCC
  • 【Feature】Capacitive humidity sensor has good linearity, good repeatability, small hysteresis, fast response, small size, and can be used at - 10 ℃ - 60 ℃ humidity environment
  • 【Comparision】This capacitive soil humidity sensor is different from most of the resistive sensors. It uses the capacitive sensing principle to detect soil humidity, avoiding the problem that the resistive sensor is easily corroded, and greatly extending its working life.

Automatic watering: add hysteresis and protection

Do not drive a pump directly from an ESP32 GPIO. Use a correctly rated MOSFET or relay driver, a separate pump supply, and flyback protection for inductive loads.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use separate start and stop thresholds so the pump does not chatter around one boundary:

  • Start watering below the dry threshold.
  • Stop above the higher wet threshold.
  • Enforce a minimum pump runtime only when appropriate.
  • Add a lockout period between watering cycles.
  • Set a maximum watering duration.
  • Take a confirmation reading after water has had time to spread through the soil.

If the ESP32 resets when the pump starts, separate the pump and logic supplies, provide suitable grounding and decoupling, and check for voltage dips and electrical interference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Building the genuinely DIY capacitive probe

The original Arduino Project Hub design is not simply a three-wire sensor module. It uses two metal pieces as electrodes, an excitation signal, and an analog circuit that converts the changing capacitive behavior into a voltage the ESP32 can measure.

The documented parts include:

  • ESP32 NodeMCU-32S.
  • Two fondue forks used as sensing electrodes.
  • 1 MΩ resistor.
  • 100 nF capacitor.
  • 10 kΩ resistor.
  • 221 Ω resistor.
  • 1N4007 diode.
  • A moisture-level indicator.

Its project-specific arrangement uses GPIO25 for approximately 600 kHz PWM excitation, GPIO4 for analog sensing, and GPIO16 for a WS2812/NeoPixel indicator. The original code averages five readings over approximately five seconds. Refer to the original project page for its schematic and complete reference implementation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Important limitations of the original design

  • GPIO25 and GPIO4 are not a universal capacitive-sensor wiring scheme.
  • The oscillator, rectifier, resistor network, and capacitor are part of the measurement circuit; they cannot simply be omitted.
  • GPIO4 is not the preferred ADC choice for a classic ESP32 Wi-Fi project because ADC1 is generally safer when the radio is active.
  • The older LEDC calls used by the reference code may require changes depending on the installed Arduino-ESP32 core version.
  • Its moisture thresholds are specific to that probe geometry, circuit, soil, and calibration.

This path is appropriate when you want to experiment with electrode spacing, plate shape, oscillator frequency, and analog signal conditioning. It is not the fastest route to a dependable plant monitor.

Best Value
AITRIP 10 Pack Capacitive Soil Moisture Sensor Corrosion Resistant for Arduino Moisture Detection Garden Watering DIY Electronic for Arduino and Raspberry Pi (10PCS)
  • This capacitive soil moisture sensor is distinguished from most resistive sensors on the market and uses capacitive sensing to detect soil moisture. The problem that the resistance sensor is easily corroded is avoided, and its working life is greatly extended.
  • The sensor has a built-in voltage regulator chip that supports a 3.3-5.5V working environment, which means it works even on a 3.3-5.5V Arduino control board. A miniature PC such as the Raspberry Pi only needs an external ADC (analog to digital signal) conversion module to work.
  • With an external screen and a motherboard, you can talk to your plants! See if it is thirsty and you don't need more water to moisten.Garden plants, Moisture detection, Intelligent agriculture
  • Interface: PH2.54-3P, Size: 98 x 23mm (LxW)
  • Package Includes: 10pcs Capacitive Soil Moisture Sensor

Physical installation matters

  • Insert the sensing section to a repeatable depth and orientation.
  • Keep the connector and electronics above the soil.
  • Do not pass the board’s marked insertion boundary unless the exact product is designed for it.
  • Protect the top of the PCB from splashing and condensation.
  • Strain-relieve the cable so movement does not change probe depth.
  • Calibrate in the final potting mix rather than only in air and water.

Capacitive sensing reduces the corrosion mechanism associated with resistive probes, but exposed PCB traces, solder, connectors, and cut edges can still degrade. Do not describe an unsealed PCB module as waterproof unless it has a stated ingress-protection rating.

Troubleshooting

The reading is 0, 4095, or completely unchanged

  • Confirm common ground between the sensor and ESP32.
  • Check that the sensor is powered.
  • Verify the connector order; VCC, GND, and AOUT are not always arranged identically.
  • Confirm that the selected GPIO is ADC-capable on your exact ESP32 variant.
  • Check that AOUT is not shorted to VCC or GND.
  • Confirm that a 5 V-powered module is not exceeding the ADC input limit.
  • Inspect the board for water damage.

The reading changes in the wrong direction

Many modules output a higher voltage when dry and a lower voltage when wet, but do not assume that behavior for every board or circuit. Measure the two reference conditions and set dryValue and wetValue accordingly.

Wi-Fi makes the readings erratic

On classic ESP32 hardware, move the sensor to an ADC1 pin such as GPIO34. Do not apply the classic ESP32 ADC2 restriction automatically to every newer ESP32-family chip; check the documentation for the exact device.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The sensor becomes unreliable over time

Possible causes include soil settling, fertilizer or salt concentration, temperature, supply-voltage changes, sensor aging, moisture gradients, and moving the probe between readings. Fix the installation depth and periodically verify the calibration in the actual soil.

When to use an external ADC or better sensor

The ESP32 ADC is adequate for a basic relative wet/dry monitor, but an external ADS1115 or MCP3008 can help when you need additional channels, different analog characteristics, or more consistent measurement behavior. These add wiring, software, power consumption, and cost.

Choose a higher-quality or professionally specified probe when several sensors must agree, the installation is permanently outdoors, the system needs repeatable measurements across soil types, or the application requires actual volumetric-water-content units rather than a normalized index.

Possible upgrades

  • Switch sensor power with a suitable transistor or load switch and sample only when needed.
  • Use deep sleep for battery-powered monitoring.
  • Send readings over Wi-Fi using MQTT or HTTP.
  • Add an OLED or NeoPixel status indicator.
  • Store calibration values in nonvolatile storage.
  • Use one calibration record per sensor and soil type.
  • Mount the electronics in a protected enclosure.
  • Add a properly isolated MOSFET or relay driver for irrigation.

Bottom line

For most ESP32 plant-monitoring projects, start with a 3.3 V-powered capacitive module on a classic ESP32 ADC1 pin such as GPIO34. Read raw values first, calibrate in the actual soil, and treat the resulting percentage as a relative index. Build the fork-electrode oscillator circuit only when designing and learning the analog sensor is the main goal. For long-term outdoor systems or comparable multi-sensor measurements, use a better-specified probe and protect the electronics from water and pump noise.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
HiLetgo 5pcs LM393 3.3V-5V Soil Moisture Detect Sensor Soil Moisture Sensor Soil Hygrometer Detection for Arduino Automatic Watering System Robot Smart car
HiLetgo 5pcs LM393 3.3V-5V Soil Moisture Detect Sensor Soil Moisture Sensor Soil Hygrometer Detection for Arduino Automatic Watering System Robot Smart car
Module dual output mode, digital output is simple, more accurate analog output.; Sensitivity adjustable (Figure blue digital potentiometer adjustment)
$7.89
Bestseller No. 2
MTDELE 10Pcs 3.3V Capacitive Soil Moisture Sensor Module
MTDELE 10Pcs 3.3V Capacitive Soil Moisture Sensor Module
Capacitive Soil Moisture Sensor: Compatible with for Arduino Raspberry Pi; Size:98*23mm
$12.99
Bestseller No. 4
Stemedu 5PCS Capacitive Analog Soil Moisture Sensor Module 3.3~5.5V Corrosion Resistant Humidity Detection Sensors DIY Electronic for Arduino for Raspberry Pi
Stemedu 5PCS Capacitive Analog Soil Moisture Sensor Module 3.3~5.5V Corrosion Resistant Humidity Detection Sensors DIY Electronic for Arduino for Raspberry Pi
【Version】This capacitive analog soil moisture sensor is V1.2; 【Voltage】Working voltage: 3.3~5.5 VDC, output voltage: 0~3.0 VDC
$8.98
Bestseller No. 5

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.