Build a Wi‑Fi Plant‑Watering System with ESP32: Complete DIY Guide

Plants are great, but remembering to water them? Not so much. One missed watering can turn a thriving fern into a sad, droopy mess. That’s why a little Wi‑Fi brain in your pot can be a game‑changer, especially when you’re juggling work, kids, and the occasional Netflix binge. In this guide I’ll walk you through building a smart watering system using an ESP32, a few cheap parts, and a dash of code. By the end you’ll have a plant that drinks on schedule, and you’ll get bragging rights for turning a hobby into a handy home‑automation project.

What You’ll Need

The Core: ESP32 Development Board

The ESP32 is a low‑cost microcontroller with built‑in Wi‑Fi and Bluetooth. Think of it as a tiny computer that can talk to your router and run simple programs. Any generic ESP32 dev kit will do – I use the “ESP32‑DevKitC” because it’s easy to solder and fits nicely on a breadboard.

Sensors and Actuators

  • Soil moisture sensor – a pair of probes that change resistance based on how wet the soil is. Most kits come with a simple analog sensor that outputs a voltage between 0 V (dry) and 3.3 V (wet).
  • Mini water pump – a 5 V submersible pump works well for small pots. Look for one that runs on 5 V DC and has a flow rate of about 100 ml/min.
  • Relay module – the ESP32 can’t drive a pump directly, so a small 5 V relay acts as a switch. Choose a “single‑channel” board with an optocoupler for safety.
  • Power supply – a 5 V 2 A wall adapter will power the ESP32, sensor, and pump together. If you prefer battery power, a 2‑cell Li‑Po pack with a step‑up converter can work, but keep an eye on voltage stability.

Miscellaneous

  • Breadboard and jumper wires
  • Small piece of heat‑shrink tubing (optional, for waterproofing the sensor leads)
  • 3D‑printed or DIY holder for the pump (I printed a simple clip on my own printer – see the link in the blog archive)

Wiring It Up

Hook Up the Sensor

  1. Connect the sensor’s VCC pin to the ESP32’s 3.3 V pin.
  2. Connect GND to any ground pin on the ESP32.
  3. Connect the analog output (often labeled “A0”) to GPIO 34 – a pin that can read analog voltages but cannot be used for output.

Wire the Relay and Pump

  1. The relay module has three pins on the “control” side: VCC, GND, and IN. Connect VCC to 5 V, GND to ground, and IN to GPIO 26 (any free digital pin works).
  2. On the “switch” side, connect the pump’s positive lead to the normally open (NO) terminal, the pump’s negative lead to the power supply’s ground, and the common (COM) terminal to the 5 V supply. When the ESP32 drives the relay high, the pump receives power.

Power Considerations

The ESP32 runs at 3.3 V, but the pump needs 5 V. Using a single 5 V adapter keeps things tidy. Just be sure the adapter can supply enough current for the pump when it runs (most small pumps draw under 500 mA).

Coding the Brain

Setting Up the Environment

I use the Arduino IDE because it’s quick to install and works fine for ESP32. Install the ESP32 board package via the Boards Manager, then select “ESP32 Dev Module” as your target.

Sketch Overview

The code does three things:

  1. Read the soil moisture – the analog value is mapped to a percentage.
  2. Decide when to water – if moisture drops below a threshold (say 30 %), turn the pump on for a set time.
  3. Report to Wi‑Fi – we’ll push the latest reading to a simple web page using the ESPAsyncWebServer library, so you can check plant health from any phone.
#include <WiFi.h>
#include <ESPAsyncWebServer.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

AsyncWebServer server(80);

const int moisturePin = 34;   // analog input
const int relayPin    = 26;   // digital output
const int dryThresh   = 30;   // percent

void setup() {
  Serial.begin(115200);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW); // relay off

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi connected");

  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    int moisture = readMoisture();
    String html = "<h2>Plant Status</h2>";
    html += "<p>Soil moisture: " + String(moisture) + "%</p>";
    request->send(200, "text/html", html);
  });

  server.begin();
}

int readMoisture() {
  int raw = analogRead(moisturePin);
  // ESP32 ADC is 12‑bit (0‑4095). Map to 0‑100%
  int percent = map(raw, 4095, 0, 0, 100); // dry = high voltage
  return constrain(percent, 0, 100);
}

void loop() {
  int moisture = readMoisture();
  if (moisture < dryThresh) {
    Serial.println("Soil dry – watering");
    digitalWrite(relayPin, HIGH); // turn pump on
    delay(5000);                  // water for 5 seconds
    digitalWrite(relayPin, LOW);  // pump off
  }
  delay(60000); // check once a minute
}

Explanation of key parts

  • analogRead() reads the voltage from the sensor. The ESP32’s ADC returns a number from 0 to 4095, where 0 is 0 V and 4095 is 3.3 V.
  • map() converts that raw number into a percentage. The sensor gives higher voltage when the soil is dry, so we invert the range.
  • digitalWrite(relayPin, HIGH) energizes the relay coil, closing the switch and powering the pump.
  • AsyncWebServer lets us serve a tiny web page without blocking the main loop. You can open http://<esp32_ip>/ on any browser to see the current moisture level.

Fine‑Tuning and Safety Tips

Calibrate Your Sensor

Every soil type behaves a bit differently. Grab a dry piece of soil and a fully soaked one, record the raw ADC values, and adjust the map() call accordingly. A quick spreadsheet can save you from over‑watering.

Protect Against Over‑watering

The simple code above waters for a fixed 5 seconds. If you have a larger pot, you might need more time. A safer approach is to water in short bursts (e.g., 2 seconds on, 2 seconds off) and re‑check the moisture after each burst. That way the system stops automatically once the soil reaches the target level.

Keep Electrical Parts Dry

Even though the pump is submersible, the relay and ESP32 should stay dry. Mount the relay on a small piece of acrylic or a 3D‑printed case, and seal the sensor leads with heat‑shrink tubing. A little silicone sealant around the sensor’s entry point adds extra peace of mind.

Power Surge Protection

When the pump starts, it can draw a brief surge of current. If you notice the ESP32 resetting, add a small capacitor (100 µF) across the 5 V line near the pump. It smooths out the spike and keeps the microcontroller happy.

Going Further

Now that you have a basic system, the sky’s the limit. Here are a few ideas I’ve tried on my own setup:

  • Push notifications – integrate with IFTTT or Telegram to get a text when the plant is watered.
  • Multiple pots – use a single ESP32 with a multiplexer to read several moisture sensors and control separate relays.
  • Solar power – pair a small solar panel with a charge controller and a Li‑Po battery for a truly off‑grid garden.

I posted a short video of the whole build on the Tech DIY Hub YouTube channel, and the full 3D‑print files are in the “Resources” section of the blog. Feel free to tweak the design; the only rule is to keep the electronics safe from water.

Building a Wi‑Fi plant‑watering system is a perfect entry point into home automation. You get to practice analog sensing, digital control, and a bit of networking—all while keeping your green friends happy. Grab the parts, follow the wiring diagram, flash the code, and watch your plant thrive on its own schedule. Happy hacking!

Reactions