Skip to content
Circuits Playground
Menu
BeginnerRule-checked

ESP32 Smart Irrigation System

Read a capacitive soil moisture sensor with an ESP32 and switch a small 5 V water pump through a relay when the soil gets dry.

Board
ESP32 DevKit V1 (30-pin)
Build time
1 h
Status
Rule-checked
Last revised

Passed the automatic wiring rules. Not yet physically built and tested.

Quick answer

To build the ESP32 Smart Irrigation System you need a ESP32 DevKit V1 (30-pin) and Capacitive Soil Moisture Sensor v1.2, 1-Channel 5 V Relay Module, Mini Submersible Water Pump (3–6 V DC), 5 V DC Supply (2 A), 9× Jumper wires + breadboard. It is a beginner project with 9 connections, takes about 1 h and costs roughly ₹800–₹1,200 in parts.

This project waters a plant automatically. An ESP32 reads a capacitive soil moisture probe on an ADC1 pin, and when the reading crosses a dry threshold it energises a relay that powers a small submersible pump from a separate 5 V supply.

The pump runs from its own supply so motor noise cannot reset the ESP32. The relay's contacts keep the pump circuit isolated from the ESP32's logic.

ESP32 DevKit V1 (30-pin)ENVPVND34D35D32D33D25D26D27D14D12D13GNDVIND23D22TX0RX0D21D19D18D5TX2RX2D4D2D15GND3V3Soil moisture sensorGNDVCCAOUTPump relayVCCGNDINCOMNONCWater pump+ (red)− (black)Pump 5 V supply+5VGND
Circuit diagram for ESP32 Smart Irrigation System (revision 2026-11-12). Wire colours: red = power, grey = ground, blue = signal, purple = I2C, green = analog, orange = switched load.

Download

Parts list

QtyPartNotesBuy
1ESP32 DevKit V1 (30-pin)ESP32-WROOM-32 development board with Wi-Fi and Bluetooth, 3.3 V logic and USB power. Common 30-pin DOIT layout.Amazon.inRobu.in
1Capacitive Soil Moisture Sensor v1.2Corrosion-resistant capacitive soil moisture probe with an analog output (higher reading = drier soil).Amazon.inRobu.in
11-Channel 5 V Relay ModuleSingle SPDT relay with transistor driver, indicator LED and flyback diode.Amazon.inRobu.in
1Mini Submersible Water Pump (3–6 V DC)Small brushed DC submersible pump for plant watering projects.Amazon.inRobu.in
15 V DC Supply (2 A)Regulated 5 V supply, e.g. a USB power adapter on a breakout or a 5 V wall adapter.Amazon.inRobu.in
9Jumper wires + breadboardMale/female jumpers as required by the modules' headers.Amazon.inRobu.in

Estimated cost: ₹800–₹1,200 including a breadboard and jumper wires (typical Indian online prices, 2026-11). Some links may be affiliate links, they cost you nothing extra and help keep this site free.

Pin-to-pin wiring

FromPinToPinType
Pump 5 V supply+5VPump relayCOMpower
Pump relayVCCESP32 DevKit V1 (30-pin)VINpower
Pump relayGNDESP32 DevKit V1 (30-pin)GNDground
Pump relayINESP32 DevKit V1 (30-pin)D26signal
Pump relayNOWater pump+ (red)load
Soil moisture sensorVCCESP32 DevKit V1 (30-pin)3V3power
Soil moisture sensorGNDESP32 DevKit V1 (30-pin)GNDground
Soil moisture sensorAOUTESP32 DevKit V1 (30-pin)D34analog
Water pump− (black)Pump 5 V supplyGNDground

Step-by-step build

  1. 1

    Check the parts

    Confirm your relay module is a 5 V coil type and note whether it is active-LOW (most are). Make sure the pump is rated 3–6 V DC.

  2. 2

    Wire the soil sensor

    Sensor VCC to ESP32 3V3, GND to GND and AOUT to GPIO34. GPIO34 is an ADC1 pin, so readings keep working while Wi-Fi is on.

  3. 3

    Wire the relay control side

    Relay VCC to ESP32 VIN (5 V from USB), GND to GND and IN to GPIO26.

  4. 4

    Wire the pump circuit

    5 V supply + to relay COM, relay NO to the pump's red wire, and the pump's black wire back to the supply's GND. The pump only receives power while the relay is on.

  5. 5

    Calibrate the sensor

    Upload a sketch that prints analogRead(34). Note the value in dry air and in a glass of water. Set DRY_THRESHOLD between the two, closer to the dry value.

  6. 6

    Test without water first

    Hold the probe in dry air and confirm the relay clicks and the pump spins briefly. Then place the pump in water and test in real soil.

AI code-generation prompt

Paste this into Gemini, ChatGPT, Claude or another coding assistant. It includes the exact pin map. Treat the generated code as untested until you have run it.

You are an experienced embedded firmware engineer. Write complete, compilable firmware for the project below.

## Project
Title: ESP32 Smart Irrigation System
Description: Reads soil moisture and switches a 5 V pump through a relay.
Board: ESP32 DevKit V1 (30-pin), 3.3 V logic
Development environment: Arduino IDE
Connectivity: wifi

## Required behaviour
Read the soil moisture sensor every 5 seconds (average 10 samples). If the soil is drier than DRY_THRESHOLD, turn the pump on for at most 10 seconds, then wait at least 60 seconds before watering again. Never run the pump for more than 30 seconds in any 10 minutes. Serve a simple web page on the local network that shows the latest moisture %, pump state and last watering time, with a button to water once manually.

## Components
- 1 × ESP32 DevKit V1 (30-pin)
- 1 × Capacitive Soil Moisture Sensor v1.2
- 1 × 1-Channel 5 V Relay Module
- 1 × Mini Submersible Water Pump (3–6 V DC)
- 1 × 5 V DC Supply (2 A)

## Exact pin map (do not change these pins)
- Soil moisture sensor GND → GND
- Soil moisture sensor VCC → 3V3
- Soil moisture sensor AOUT → GPIO34 (D34)
- Pump relay VCC → VIN
- Pump relay GND → GND
- Pump relay IN → GPIO26 (D26)

## Known wiring warnings from the circuit checker
- [warning] Pump relay IN: Many 5 V relay modules switch reliably from 3.3 V logic but some do not; check your module or use a 3.3 V-trigger variant. Many modules are active-LOW.

## Assumptions
- The ESP32 is powered from USB, so VIN provides about 5 V for the relay coil.
- The relay module triggers from a 3.3 V signal (most optocoupler/transistor modules do; check yours).
- The pump is a 3–6 V DC submersible pump drawing under 250 mA.

## Requirements for the code
- Use only the pins listed above, defined once as named constants at the top.
- Non-blocking structure using millis() (no long delay() calls in loop()).
- Put all outputs (relays, motors, buzzers) in a safe OFF state in setup() before anything else.
- Print readable debug output to Serial at 115200 baud.
- Handle sensor read failures (e.g. NaN, timeouts, missing I2C device) without crashing, and report them.
- Put thresholds and calibration values in clearly named constants with comments.
- Wi-Fi: use placeholder constants WIFI_SSID / WIFI_PASSWORD, reconnect automatically, and keep working locally when Wi-Fi is down. Never hard-code real credentials.

## What to return
1. The complete source file(s), ready to compile in Arduino IDE.
2. The exact libraries (with the library manager names) and board package to install.
3. A short explanation of how the code works and how to calibrate it.
4. A testing checklist I can follow step by step.

Do not invent pins, libraries or functions that do not exist. If something in this spec is ambiguous or unsafe, say so before writing code.

Troubleshooting & common mistakes

Readings stay at 0 or 4095
Check that AOUT goes to GPIO34 and that the sensor has 3.3 V. A reading of 4095 constantly means the input is floating or over-range.
Relay clicks but the pump does not run
Make sure the pump is on NO (not NC) and that the 5 V supply's ground returns to the pump's black wire.
The ESP32 resets when the pump starts
The pump must be on its own supply. Add a 1N4007 diode across the pump terminals (stripe to +) and a 100 µF capacitor across the pump supply.
Relay is always on
Most modules are active-LOW: write HIGH to turn them off. Set the pin HIGH before pinMode(OUTPUT) to avoid a click at boot.

Safety, assumptions & checks

Safety notes

  • Keep water away from the ESP32 and power supply; mount electronics above the water container.
  • This design is low-voltage DC only. Do not switch a mains-powered pump with this wiring.
  • GPIO pins are 3.3 V only and are not 5 V tolerant.
  • Do not draw more than about 12–20 mA from a single GPIO.
  • Mains (AC) wiring through relay contacts can kill. Only qualified people should wire mains loads, in an enclosure.
  • Contacts rated 10 A 250 VAC / 30 VDC on the relay itself; cheap modules' PCB traces may be lower.
  • Never run the pump dry for long.
  • Keep water away from the electronics and power supply.

Assumptions

  • The ESP32 is powered from USB, so VIN provides about 5 V for the relay coil.
  • The relay module triggers from a 3.3 V signal (most optocoupler/transistor modules do; check yours).
  • The pump is a 3–6 V DC submersible pump drawing under 250 mA.

Automatic wiring check (rules-2026.11.1)

  • warning: Pump relay IN: Many 5 V relay modules switch reliably from 3.3 V logic but some do not; check your module or use a 3.3 V-trigger variant. Many modules are active-LOW.
  • info: Water pump is switched by a relay. Consider a flyback diode (e.g. 1N4007) across the motor terminals to protect the relay contacts.

The checker finds known wiring mistakes. It is not a simulator and cannot guarantee the circuit is safe or will work.

Viva and interview questions

Questions examiners commonly ask about the parts in this circuit, with short answers.

  1. Q1. What logic voltage does the ESP32 use, and is it 5 V tolerant?

    3.3 V. Its GPIO pins are not 5 V tolerant, so 5 V signals need a level shifter or a resistor divider.

  2. Q2. Why use ADC1 pins (GPIO32–39) for analog sensors on the ESP32?

    ADC2 is shared with the Wi-Fi radio, so ADC2 readings fail while Wi-Fi is active. ADC1 keeps working.

  3. Q3. Which ESP32 pins are input-only?

    GPIO34, 35, 36 (VP) and 39 (VN). They have no output driver and no internal pull-up/pull-down.

  4. Q4. Why is a capacitive soil sensor better than a resistive one?

    Its electrodes are insulated, so it does not corrode by electrolysis and lasts much longer in wet soil.

  5. Q5. How do you calibrate a soil moisture sensor?

    Record the reading in dry air and in water, then map readings between those two values to 0–100 %.

  6. Q6. Why use a relay instead of driving a pump directly from a GPIO?

    A GPIO can supply only a few milliamps. The relay lets a small signal switch a separate, higher-current circuit.

  7. Q7. What does active-LOW mean on a relay module?

    The relay turns on when the input pin is pulled LOW, which is common on opto-isolated modules.

  8. Q8. Why should a pump use its own power supply?

    Motor start-up current causes voltage dips and noise that can reset the microcontroller.

Frequently asked questions

What components do I need for the ESP32 Smart Irrigation System?

You need a ESP32 DevKit V1 (30-pin) and Capacitive Soil Moisture Sensor v1.2, 1-Channel 5 V Relay Module, Mini Submersible Water Pump (3–6 V DC), 5 V DC Supply (2 A), 9× Jumper wires + breadboard, plus a breadboard, jumper wires and a USB cable.

How much does the ESP32 Smart Irrigation System cost to build in India?

About ₹800–₹1,200 for new parts from Indian online stores (estimate, 2026-11). Reusing a board you already own makes it much cheaper.

How long does it take to build?

About 1 h for a beginner maker, including wiring and uploading code.

Is this project suitable as a college or school project?

Yes. It is a beginner project that suits school science exhibitions, diploma practicals and first-year engineering mini projects. Extend it with a web dashboard or data logging for a bigger project.

What should I do if: Readings stay at 0 or 4095?

Check that AOUT goes to GPIO34 and that the sensor has 3.3 V. A reading of 4095 constantly means the input is floating or over-range.

What should I do if: Relay clicks but the pump does not run?

Make sure the pump is on NO (not NC) and that the 5 V supply's ground returns to the pump's black wire.

What should I do if: The ESP32 resets when the pump starts?

The pump must be on its own supply. Add a 1N4007 diode across the pump terminals (stripe to +) and a 100 µF capacitor across the pump supply.

What should I do if: Relay is always on?

Most modules are active-LOW: write HIGH to turn them off. Set the pin HIGH before pinMode(OUTPUT) to avoid a click at boot.

Report a mistake in this project

Related