Want to try a small electronics project without complicated circuits? In this beginner tutorial, we’ll build check soil moisture using esp32 and capacitive soil sensor. You’ll connect one sensor, upload a short Arduino IDE sketch, and see the result. No Wi-Fi account or cloud service is required.

What does it do?
The sensor’s analog voltage changes as moisture around it changes. Because exact numbers depend on sensor and soil, first measure dry and wet reference readings, then set a threshold.
Parts you’ll need
ESP32 board, 3.3V-compatible analog capacitive soil moisture sensor, jumper wires, pot of soil. You will also need a computer with the free Arduino IDE installed.
Wiring connections
Disconnect USB power before moving any wires. Make these connections carefully:
| Sensor / component pin | Connect to |
|---|---|
| Sensor VCC | 3.3V |
| Sensor GND | GND |
| Sensor AOUT | GPIO 34 (ADC input) |
Important: ESP32 GPIO pins work at 3.3V. Do not connect a 5V output directly to an ESP32 input. Board and sensor-module pin labels vary, so double-check the markings on your hardware.
Arduino IDE code
Select the correct board and USB port in Arduino IDE, paste the complete sketch below, and click Upload.
const int sensorPin = 34;
const int dryThreshold = 2500; // Calibrate for your sensor
void setup() { Serial.begin(115200); }
void loop() {
int moisture = analogRead(sensorPin);
Serial.print("Soil sensor: ");
Serial.print(moisture);
Serial.println(moisture > dryThreshold ? " (check water level)" : " (moisture detected)");
delay(1000);
}
Expected result
Soil sensor: 1800 (moisture detected) Open Tools → Serial Monitor and set the baud rate shown in Serial.begin() in the sketch.
Troubleshooting
Sensor voltage direction and range vary between models. Compare readings in air and moist soil, and reverse the comparison if your sensor’s values run the other way. Never feed 5V into an ESP32 ADC pin.
If nothing appears, first check the USB cable, correct board and port, sensor power and ground, and the Serial Monitor baud rate. Recheck every wire against the connection table before changing code.
What to try next
Once this simple example works, try changing the measurement interval or using the sensor reading to control an LED. This is an easy way to learn inputs, outputs, and basic programming.
For more hands-on electronics tutorials, explore CircuitMagic. If you later want to control Arduino or ESP32 projects from a phone over Bluetooth, see our BLE Controller app tutorial. This project itself does not need Bluetooth.









