Full width home advertisement

Post Page Advertisement [Top]

 I've killed more plants than I'd like to admit. Not on purpose — I just travel a lot, forget to water them for a week, and come home to something that looks like it belongs in a botany horror movie. After the third dead basil plant in a row, I decided enough was enough and built myself an automatic watering system using an ESP32 and a cheap soil moisture sensor.

The best part? It cost me less than $15 in parts, took about an hour to wire up, and it's been running non-stop for months without a single dead leaf. In this guide, I'll walk you through exactly how to build it yourself — wiring, code, and all the little mistakes I made so you don't have to repeat them.

ESP32 Automatic Plant Watering System

Why Use an ESP32 Instead of a Regular Arduino?

You could technically build this with a basic Arduino Uno, and plenty of people do. But I went with the ESP32 for one simple reason: Wi-Fi. Since the ESP32 has built-in wireless connectivity, you can check your plant's moisture level from your phone, log the data over time, or even get a notification when the water tank runs low. If you just want the simplest possible build with no smart features, an Arduino Uno works fine too — the wiring and logic are almost identical.

What You'll Need

Here's the full parts list. None of this is expensive, and you can find all of it on AliExpress, Amazon, or your local electronics shop.

  • 1x ESP32 development board (ESP32-WROOM-32 or similar)
  • 1x Capacitive soil moisture sensor (avoid the cheap resistive ones — they corrode in soil within weeks)
  • 1x 5V submersible mini water pump
  • 1x 1-channel 5V relay module (this is what lets the ESP32 switch the pump on and off safely)
  • Silicone/vinyl tubing (5mm works well for small pots)
  • A small container or bottle for the water reservoir
  • Jumper wires and a breadboard
  • A separate 5V power source for the pump (don't power it directly from the ESP32 — more on that below)

A quick but important note: capacitive sensors read soil moisture without direct metal-to-soil contact, which means they don't rust or degrade the way resistive sensors do. It's a couple of dollars more, but it will save you from replacing your sensor every month.

Understanding the Wiring

This is where most beginners get stuck, so let's slow down here.

Soil moisture sensor to ESP32:

  • VCC → 3.3V on the ESP32
  • GND → GND
  • Analog output (AOUT) → one of the ADC-capable pins, such as GPIO 34

Relay module to ESP32:

  • VCC → 5V (use the ESP32's VIN pin, or an external 5V source)
  • GND → GND
  • IN (signal pin) → GPIO 26 (or any free digital pin)

Water pump to relay:

  • The pump connects through the relay's NO (normally open) terminal, powered by its own 5V supply — not through the ESP32 directly.

Here's the part that trips people up: the ESP32's GPIO pins can't handle the current a water pump draws. If you try to power the pump straight from the board, you'll either damage the ESP32 or the pump just won't run reliably. The relay acts like a remote-controlled switch — the ESP32 just tells it "on" or "off," and the actual pump power comes from a separate 5V source.

ESP32 Automatic Plant Watering System 2

The Code

Here's a simple version to get you started. It reads the moisture level, and if the soil is too dry, it runs the pump for a few seconds.

cpp
#define SENSOR_PIN 34
#define RELAY_PIN 26

int dryThreshold = 2800;  // adjust based on your sensor's readings

void setup() {
  Serial.begin(115200);
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, HIGH); // relay off (most modules are active LOW)
}

void loop() {
  int moistureLevel = analogRead(SENSOR_PIN);
  Serial.print("Moisture reading: ");
  Serial.println(moistureLevel);

  if (moistureLevel > dryThreshold) {
    Serial.println("Soil is dry - watering now");
    digitalWrite(RELAY_PIN, LOW);   // turn pump on
    delay(3000);                    // water for 3 seconds
    digitalWrite(RELAY_PIN, HIGH);  // turn pump off
  }

  delay(1800000); // check again every 30 minutes
}

A couple of tips from experience:

  • Every sensor is a little different, so don't trust the "dryThreshold" number I used above. Stick your sensor in dry soil, note the reading, then stick it in wet soil and note that too. Set your threshold somewhere in between.
  • Don't water for too long in one go. Three seconds might sound like nothing, but with a decent pump, it adds up fast — I flooded a pot pretty badly during testing before I dialed this in.
  • The 30-minute check interval is a starting point. For small pots, checking more often is safer than checking too little.

Adding Wi-Fi Monitoring (Optional but Worth It)

If you want to check your plant's status remotely, you can have the ESP32 host a simple web page or send readings to a service like Home Assistant or Blynk. This part isn't required for the system to work, but it's genuinely satisfying to glance at your phone and see "soil moisture: healthy" instead of wondering if your fern is dying while you're at work.

Common Problems (And How I Fixed Them)

The pump won't turn on at all. Check your relay wiring polarity first. Most relay modules are "active LOW," meaning they turn on when the signal pin receives LOW, not HIGH — this catches almost everyone the first time.

The sensor reading jumps around randomly. This is usually a loose jumper wire or a cheap sensor with a noisy analog output. Try averaging several readings instead of relying on a single one.

The pump runs, but barely any water comes out. Check that your tubing isn't kinked, and make sure the pump is fully submerged — some mini pumps struggle if they're not.

ESP32 Arduino Projects IoT Projects DIY Electronics Smart Home Sensors & Automation

Final Thoughts

This project is one of those rare builds where the effort-to-reward ratio is genuinely great. It's simple enough for a weekend afternoon, but it solves a real problem — and once it's running, you basically forget about it, which is exactly the point.

If you build your own version, I'd love to hear what tweaks you made. Everyone's setup ends up a little different once real plants and real pots get involved.

Bottom Ad [Post Page]