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:

ESP32 C3 Super Mini - Soil Moisture Sensor Pump

Hardware Preparation

1×ESP32 C3 Super Mini
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×Relay
1×12V Pump
1×Vinyl Tube
1×12V Power Adapter
1×Optionally, DC Power Jack
1×Breadboard
1×Jumper Wires

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 and Pump

If you are new to these parts, these tutorials cover the pinout, how they work and how to program them:

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.
The wiring diagram between ESP32 C3 Super Mini soil moisture sensor Pump

This image is created using Fritzing. Click to enlarge image

No breadboard? The same circuit can be wired without one, as shown below:

The wiring diagram between ESP32 C3 Super Mini soil moisture sensor Pump  (No Breadboard)

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
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-soil-moisture-sensor-pump */ #define RELAY_PIN 7 // The ESP32 C3 SuperMini pin that connects to relay #define SENSOR_PIN 4 // The ESP32 C3 SuperMini pin 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); pinMode(RELAY_PIN, OUTPUT); } void loop() { int value = analogRead(SENSOR_PIN); // read the analog value from soild moisture sensor if (value > THRESHOLD) { Serial.print("The soil moisture is DRY => activate pump"); digitalWrite(RELAY_PIN, HIGH); } else { Serial.print("The soil moisture is WET => deactivate the pump"); digitalWrite(RELAY_PIN, LOW); } Serial.print(" ("); Serial.print(value); Serial.println(")"); delay(1000); }

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

∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
The soil moisture is DRY => activate pump (2312) The soil moisture is DRY => activate pump (2187) The soil moisture is DRY => activate pump (1896) The soil moisture is DRY => activate pump (1604) The soil moisture is WET => deactivate the pump (1473) The soil moisture is WET => deactivate the pump (1398) The soil moisture is WET => deactivate the pump (1342) The soil moisture is WET => deactivate the pump (1311)
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2

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

※ 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!