Indoor Plant Watering System for Vacation using ESP32 Deep Sleep

Indoor Plant Watering System for Vacation using ESP32 Deep Sleep

Build an ESP32 indoor plant watering system with deep sleep & 12V battery. Automatic irrigation for vacation with smart moisture control.

Taking care of indoor plants during long vacations can be challenging. Overwatering or underwatering can damage plants, especially when there is no one available to monitor them regularly. To solve this problem, I built a battery-powered indoor plant watering system using ESP32, designed specifically for vacation use.

indoor plant watering system

This smart irrigation system uses deep sleep technology, a 12V lithium battery, and a soil moisture sensor to automatically water plants only when required. The system is completely autonomous, energy-efficient, and perfect for long-term unattended operation.

Required Components for Plant Watering System

Required Components for Plant Watering System
  • ESP32 Development Board
  • Capacitive Soil Moisture Sensor
  • Relay Module (for water pump)
  • Small 12V Water Pump
  • 12V lithium battery
  • DC-DC Buck converter (MP1584 or XL4015)
  • Jumper Wires

Circuit of ESP32 Plant Watering Project

ESP32 plant watering system circuit

In this project, the ESP32 acts as the main controller, powered by a 12V battery through a buck converter (MP1584 or XL4015 or LM2596) that steps down the voltage to 5V.

A capacitive soil moisture sensor is connected to GPIO34 to measure soil moisture levels, and the ESP32 processes this data to decide when watering is needed.

A relay module connected to GPIO25 is used to control the 12V water pump, allowing the ESP32 to safely switch the pump ON and OFF based on moisture conditions.

The pump is powered directly from the 12V battery, while the relay provides isolation between the control and power circuits.

Additionally, a BOOT button on GPIO0 is used to wake the ESP32 and enter setup mode, and an LED on GPIO2 indicates the setup status.

This simple yet effective circuit enables automatic, low-power plant watering ideal for vacation use.

Tutorial video on Indoor Plant Watering System

Program ESP32 with Arduino IDE

For this IoT-based project, I have used the Arduino IDE to program ESP32.

First update the Preferences –> Aditional boards Manager URLs: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json

  • Then install the ESP32 board (2.0.5) from the Board Manager or Click Here to download the ESP32 board.

Source Codes for ESP32 Indoor Plant Watering Project

Click on the following buttons to download the source code for this ESP32 project.

This code is provided free for project purpose and fair use only.
Please do mail us to [email protected] if you want to use it commercially.
Copyrighted © by Tech StudyCell

Get the Sensor reading for DRY & WET soil

To get the Calibration values for moisture reading from the sensor, first, upload the code “Get Sensor reading” to the ESP32.

Connect the Moisture Sensor AOUT pin with D34 and supply 3.3V across VCC and GND.

Then open the serial monitor with the Baud rate 115200.

Get Sensor reading for the DRY & WET soil

Now, note down the following values.

  • Soil is very dry.
  • Soil is very wet.

Later on, the ESP32 will calculate the moisture percentage according to these two values.

Now open the main sketch in Arduino IDE and update the following values.

plant watering system p9

Select the relay type. For the Active-LOW relay, make the flag true, for the Active-HIGH relay, make the flag false.

Then enter the calibration values of the moisture sensor for the DRY and WET soil types.

Paragraph-by-paragraph explanation

Below is a paragraph-by-paragraph explanation for every major code block, describing exactly what each section does and how it contributes to the project.

Library Includes

#include <Arduino.h>
#include <WiFi.h>
#include <WebServer.h>
#include <Preferences.h>

These libraries provide the core functionality required for the project. Arduino.h includes basic Arduino functions. WiFi.h enables WiFi features, which are used in setup mode. WebServer.h allows the ESP32 to host a local web server for configuration. Preferences.h is used to store user settings (like moisture threshold and sleep time) in non-volatile memory, so they are retained even after restart or power loss.

GPIO Configuration

#define MOISTURE_PIN 34
#define PUMP_PIN 25
#define BOOT_PIN 0
#define LED_PIN 2

#define RELAY_ACTIVE_LOW false

Here, all GPIO pins are defined. GPIO34 is used as an analog input to read the soil moisture sensor. GPIO25 controls the relay that switches the water pump ON or OFF. GPIO0 is connected to the BOOT button and is used to wake the ESP32 and enter setup mode. GPIO2 controls an LED that indicates setup mode status.

The RELAY_ACTIVE_LOW flag defines the relay logic; in this case, false means the relay turns ON when the pin goes HIGH.

Object Creation

WebServer server(80);
Preferences pref;

A web server is created on port 80 to serve the configuration webpage during setup mode. The Preferences object is used to store and retrieve user-defined settings from the ESP32’s internal flash memory.

User Settings (Default Values)

int MOISTURE_THRESHOLD = 30;
int PUMP_RUNTIME = 20;
int SLEEP_TIME = 1;
bool sleepInMinutes = true;

These are default configuration values. The ESP32 waters the plant if moisture drops below 30%. The pump runs for 20 seconds during watering. The system sleeps for a defined duration (default 1 unit), and the unit is determined by sleepInMinutes (true = minutes, false = hours). These values can be changed via the web interface.

Sensor Calibration

int DRY_ADC = 2910;
int WET_ADC = 925;

These values define calibration points for the moisture sensor. DRY_ADC represents completely dry soil, and WET_ADC represents fully wet soil. These values are used to convert raw ADC readings into a percentage for easier interpretation.

Setup Mode Timing

#define LONG_PRESS_TIME 3000
#define SETUP_TIMEOUT 300000UL

These constants define timing behavior. The BOOT button must be pressed for 3 seconds to enter setup mode. Once in setup mode, the system will automatically exit after 5 minutes (300000 milliseconds) to save power.

Pump Control Function

void setPump(bool on) {

This function controls the pump state. It prints the current pump status to the Serial Monitor for debugging. Based on the relay type (active HIGH or LOW), it sets the correct logic level on GPIO25. This abstraction allows easy switching between relay types without modifying the main logic.

Moisture Reading Function

int readMoisture() {

This function reads the analog value from the moisture sensor and maps it between dry and wet calibration values to produce a percentage (0–100%). It also prints both raw ADC and percentage values to the Serial Monitor, which helps in debugging and calibration.

Wakeup Detection Function

bool wokeFromButton() {

This function checks why the ESP32 woke up from deep sleep. If the wakeup source is the BOOT button (EXT0), it returns true and prints a message. If the wakeup is due to the timer, it prints that information. This helps differentiate between normal wake cycles and user-triggered setup mode.

HTML Page Function

String htmlPage() {

This function returns a complete HTML webpage stored in flash memory using raw string literals. The page includes input fields for moisture threshold, pump runtime, and sleep time. It also displays live moisture data using JavaScript, which fetches values from the ESP32 every 2 seconds. The UI is styled with CSS for a clean and modern look, and includes a footer credit.

Save Configuration Function

void handleSave() {

This function handles data submitted from the web page. It reads user inputs, converts them into appropriate data types, and saves them in flash memory using the Preferences library. After saving, it sends a confirmation message to the browser and restarts the ESP32 so that the new settings take effect immediately.

Setup Mode Function

void startSetupMode() {

This function is executed when the user enters setup mode. It turns ON the LED to indicate setup mode, starts a WiFi hotspot named “Plant_Setup”, and initializes the web server. It defines routes for the main page, saving configuration, and live moisture data. The ESP32 continuously handles client requests until the timeout is reached, after which it automatically restarts to return to normal operation.

Main Setup Function

void setup() {

This is the main initialization function. It starts Serial communication, configures GPIO pins, and initializes the system. It loads saved settings from memory and prints them to the Serial Monitor. If the ESP32 wakes due to a button press, it checks for a long press to enter setup mode. Otherwise, it reads the soil moisture and decides whether to water the plant. After completing its task, it prepares for deep sleep.

Deep Sleep Configuration

esp_sleep_enable_timer_wakeup(...)

The ESP32 is configured to wake up after a specific time interval, which can be in minutes or hours based on user settings. Additionally, external wakeup via the BOOT button is enabled using esp_sleep_enable_ext0_wakeup. This allows the user to wake the device manually at any time.

Enter Deep Sleep

esp_deep_sleep_start();

Finally, the ESP32 enters deep sleep mode. In this state, power consumption drops to a very low level. The system will wake up either after the timer expires or when the BOOT button is pressed.

Loop Function

void loop() {}

The loop function is empty because the ESP32 completes all operations inside the setup() function and then goes into deep sleep. This is a typical design pattern for ultra-low-power applications.

How the Plant Monitoring System Works

plant watering system p1

The working principle of this system is simple yet highly effective. The ESP32 operates in cycles to conserve power and ensure efficient watering.

How the indoor plant watering System Works

Step-by-Step Working:

  • The ESP32 remains in deep sleep mode most of the time to save battery.
  • It wakes up at a predefined interval (minutes or hours).
  • Reads the soil moisture using a capacitive sensor.
  • Converts the sensor value into a moisture percentage.
  • If moisture is below the set threshold:
    • The ESP32 activates the 12V water pump.
    • Water is supplied to the plant.
  • After a fixed duration, the pump turns OFF.
  • The ESP32 returns to deep sleep mode.

This cycle repeats automatically, ensuring plants get water only when needed.

Deep Sleep – The Key Feature

Deep sleep is what makes this system ideal for vacation use.

  • Benefits of Deep Sleep:
  • Reduces power consumption drastically
  • Extends battery life significantly
  • Eliminates unnecessary processing
  • Enables long-term autonomous operation

Instead of running continuously, the ESP32 wakes only when needed, making the system highly efficient.

Smart Setup Mode (User Configuration)

plant watering system p4

The system also includes a user-friendly setup mode for configuration.

Features of Setup Mode:

  • Activated by long-pressing the BOOT button
  • ESP32 creates a WiFi hotspot (“Plant_Setup”)
plant watering system p5
  • Opens a web-based configuration page (IP: “192.168.4.1”)
  • Displays live soil moisture reading
  • Allows adjustment of:
    • Moisture threshold
    • Pump runtime
    • Sleep duration (minutes or hours)
plant watering system p6
  • Auto exits after 5 minutes to save power

All settings are stored in memory and remain even after a power loss.

The ESP32 is a powerful microcontroller widely used in IoT projects. In this project, we use it to create a low-power smart plant watering system that can operate for weeks without human intervention.

Unlike traditional irrigation systems that run continuously, this setup is optimized using deep sleep mode, ensuring minimal battery consumption while maintaining efficient plant care.

Perfect Use Cases

This ESP32 smart irrigation system is ideal for:

  • Indoor plants
  • Balcony gardening
  • Small home gardens
  • Office plants
  • Travel or vacation periods
  • Off-grid watering setups

Conclusion

The ESP32 Indoor Plant Watering System with Deep Sleep and 12V Battery is a powerful, efficient, and practical solution for modern plant care. By combining automation, low-power design, and smart sensing, this system ensures your plants stay healthy even during extended vacations.

This project is a perfect example of how IoT and embedded systems can simplify everyday life while conserving energy.