ESP32 C3 Super Mini - Soil Moisture Sensor Pump
Build a simple automatic plant watering system with the ESP32 C3 Super Mini, a soil moisture sensor and a pump. The board reads the capacitive soil moisture sensor and turns the 12V pump on when the soil is dry.
In this tutorial, you'll learn:
- How the ESP32 C3 Super Mini decides when the soil is wet or dry
- How to wire the soil moisture sensor, relay and 12V pump
- How to set the wet-dry threshold for your own soil
- How to program the board to turn the pump on and off automatically
- How to check the result on the Serial Monitor

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
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 and Pump
If you are new to these parts, these tutorials cover the pinout, how they work and how to program them:
- Soil moisture sensor: ESP32 C3 Super Mini - Soil Moisture Sensor tutorial
- Pump: ESP32 C3 Super Mini - Controls Pump tutorial
How It Works
The ESP32 C3 Super Mini reads the capacitive soil moisture sensor once per second and compares the value with a threshold.
- Value above the threshold (the soil is dry): The board activates the relay, and the relay turns the pump on.
- Value at or below the threshold (the soil is wet): The board deactivates the relay, and the relay turns the pump off.
- Value range: The 12-bit ADC gives analogRead() values from 0 to 4095. Drier soil gives a higher value.
Wiring Diagram
Connect the sensor to GPIO4 and the relay to GPIO7 of the ESP32 C3 Super Mini.
- Note: Disconnect all power before you change any wire.
- Note: Keep the circuit part on top of the sensor above the soil and water. Only the probe goes into the soil.
- Note: The 12V supply goes only to the relay terminals and the pump. Never connect 12V to the ESP32 C3 Super Mini.

This image is created using Fritzing. Click to enlarge image
No breadboard? The same circuit can be wired without one, as shown below:

This image is created using Fritzing. Click to enlarge image
| Moisture Sensor Pin | ESP32 C3 Super Mini Pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| AOUT | GPIO4 |
| Relay Module Pin | ESP32 C3 Super Mini Pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| IN | GPIO7 |
| Relay Module Terminal | Connection |
|---|---|
| COM | 12V Power Adapter (+) Positive |
| NO | Pump (+) Red Wire |
| Ground Connections | Connection |
|---|---|
| 12V Power Adapter (-) | Pump (-) Black Wire |
ESP32 C3 Super Mini Code
This code reads the soil moisture value and switches the pump through the relay.
What This Code Does:
- Reads the sensor: Gets the analog value from GPIO4 once per second
- Dry soil: Sets GPIO7 HIGH when the value is above THRESHOLD, so the pump runs
- Wet soil: Sets GPIO7 LOW otherwise, so the pump stops
- Shows the result: Prints the soil state and the value on the Serial Monitor
Detailed Instructions
- New to ESP32 C3 Super Mini? Complete our Getting Started with ESP32 C3 Super Mini tutorial first to set up your development environment.
- Wire the parts: Connect the sensor, relay, pump and power adapter as shown in the wiring diagram.
- Connect the board: Plug the ESP32 C3 Super Mini into your computer with the USB Type-C cable.
- Check the board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
- Calibrate the sensor: Find your wet-dry threshold with the ESP32 C3 Super Mini - Soil Moisture Sensor tutorial.
- Set the threshold: Update THRESHOLD in the code with your calibrated value.
- Open Serial Monitor: Set the baud rate to 115200.
- Upload: Upload the code to the ESP32 C3 Super Mini.
- Check the result: Read the messages on the Serial Monitor, then add water to the soil and see the state change.
- Pro Tip: Test with the pump in a cup of water first, so a wrong threshold does not flood your plant.
Serial Monitor Output
Code Explanation
Read the line-by-line explanation in the comment lines of the source code!
※ 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 C3 Super Mini'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 C3 Super Mini's ADC is not perfectly accurate and might require calibration for correct results. Each ESP32 C3 Super Mini 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 C3 Super Mini or using another board that has a more reliable ADC. If you still want to calibrate the ESP32 C3 Super Mini's ADC, refer to the ESP32 ADC Calibration Driver.
Application and Project Ideas
This ESP32 C3 Super Mini soil moisture sensor pump project is a good base for many garden projects:
- Automatic Plant Watering: Keep one house plant watered while you are away
- Balcony Garden: Water a planter box only when the soil is dry
- Greenhouse Helper: Run a small irrigation line for seedlings
- Hydroponic Starter: Refill a grow tray when the growing medium dries out
- Herb Garden Kit: Build a small self-watering pot for your kitchen
Challenge Yourself
Try these ideas to take your ESP32 C3 Super Mini watering project further:
- Easy: Add an LED on GPIO3 that lights up while the pump runs
- Easy: Change the code so it checks the soil every 5 seconds
- Medium: Stop the pump after a fixed time, so a failed sensor cannot flood the plant
- Medium: Use two thresholds, so the pump does not switch on and off too quickly near one value
- Advanced: Use WiFi to send the moisture value to a web page
- Advanced: Add a second sensor, relay and pump to water two plants with different thresholds