Smart watering timer

Waters plants by soil moisture or schedule with a 12 V pump and sends a notice when the tank is empty.

Smart home Board: ESP32 DevKit V1 (WROOM-32) Level: ●●○ ⏱ 2–3 h

⚠ Caution

Switch only low-voltage loads yourself. For mains loads use a certified isolated module in a box or call an electrician.

The sensor that decides how long the plants live

Resistive moisture probes corrode in weeks. Use capacitive ones and record the two reference values yourself: the reading in dry air and the reading in a glass of water. Everything between those two numbers is your percentage.

A pump should never trust one sensor

If a probe slips out of the soil it reads "dry" forever and the pump floods the balcony. So combine rules: water only inside a time window, only if the moisture is below the threshold, never longer than a set number of seconds per run and a set number of runs per day. Add a tank check with a float switch or an ultrasonic sensor, because a pump running dry burns out.

  • Put a flyback diode across a 12 V pump and drive it through a MOSFET rather than a mechanical relay if you can.
  • Morning is the best time to water; evening watering invites fungus in humid weather.
  • If you use deep sleep, wake up once an hour, read the probe, and decide. Constant polling just wastes battery.

Components

  • ESP32 DevKit V1 (30 pin, WROOM-32)
  • Capacitive soil moisture sensor v1.2
  • Relay module 1-channel 5V (opto-isolated)
  • 12V mini water pump / solenoid valve
  • USB charger 5V 2A
  • Inline fuse holder + fuses

Wiring

Module Module pin ESP32 pin Note
Soil sensor AO analog GPIO34 (ADC1) capacitive type lasts longer
Relay IN signal GPIO26
Pump 12 V relay NO via a separate supply common GND, fuse, flyback diode on a motor

Code

const int PIN_SOIL = 34, PIN_RELAY = 26;   // relay active LOW
int DRY = 2800, WET = 1200;                // calibrate: raw value in air and in water
int THRESH_PCT = 35;                       // water when the soil is drier than this
uint32_t PUMP_MS = 8000, MIN_GAP_MS = 3600000UL;   // pump time and minimum gap between waterings
uint32_t lastWater = 0;

int soilPct() {
  long v = 0; for (int i = 0; i < 16; i++) { v += analogRead(PIN_SOIL); delay(5); }
  v /= 16;
  return constrain(map(v, DRY, WET, 0, 100), 0, 100);
}
void setup() {
  pinMode(PIN_RELAY, OUTPUT); digitalWrite(PIN_RELAY, HIGH);
  Serial.begin(115200);
  lastWater = millis() - MIN_GAP_MS;
}
void loop() {
  int p = soilPct();
  Serial.printf("soil %d%%n", p);
  if (p < THRESH_PCT && millis() - lastWater >= MIN_GAP_MS) {
    digitalWrite(PIN_RELAY, LOW); delay(PUMP_MS); digitalWrite(PIN_RELAY, HIGH);   // fixed run time: no flooding if the sensor fails
    lastWater = millis();
  }
  delay(10000);
}

Build tips

  • Calibrate SOIL_DRY and SOIL_WET with the sensor in air and in water.
  • Seal the top of the capacitive sensor electronics with varnish or hot glue.

What you need

Buy the parts kit · Estimated total: $17.50

ESP32 DevKit V1 (30 pin, WROOM-32) × 1
$4.00
Buy at AliExpress Buy at Amazon.com
Capacitive soil moisture sensor v1.2 × 1
$1.50
Buy at AliExpress Buy at Amazon.com
Relay module 1-channel 5V (opto-isolated) × 1
$1.50
Buy at AliExpress Buy at Amazon.com
12V mini water pump / solenoid valve × 1
$5.00
Buy at AliExpress Buy at Amazon.com
USB charger 5V 2A × 1
$4.00
Buy at AliExpress Buy at Amazon.com
Inline fuse holder + fuses × 1
$1.50
Buy at AliExpress Buy at Amazon.com
🇺🇦 Ukraine🌍 Other countries

Other countries: order these parts on AliExpress with the links below.

Some links are affiliate links: we may earn a commission at no extra cost to you.

Related ideas

⚠ Caution

Switch only low-voltage loads yourself. For mains loads use a certified isolated module in a box or call an electrician.

Greenhouse vent and irrigation controller

Opens the vent or starts the fan by temperature and humidity, checks the soil moisture, and keeps a daily log for the whole season.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit
⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Night-tariff water heater scheduler

Heats the water heater only in the cheap night tariff zone or from surplus solar power, with a temperature limit.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●● Advanced
  • Build time 3–5 h
Pick parts / kit
⛔ High risk

Mains 220–230 V can kill. Work with the power off, use certified isolated modules in an enclosure, fuse the line, and ask a qualified electrician if you are not sure.

Aquarium heater and light controller

Holds the water temperature within a fraction of a degree with a cross-checking second probe, runs the lamp on a schedule and reports a cold tank.

  • Board ESP32 DevKit V1 (WROOM-32)
  • Level ●●○ Intermediate
  • Build time 2–3 h
Pick parts / kit

← All module ideas →

Comments

No comments yet. Share your experience or ask a question.

Comments are moderated.