ESP32, ESP8266 & Raspberry Pi, lesson 32 of 33
Building an Automated Plant Watering System using ESP32
Introduction
Do you ever worry about your plants not getting enough water when you're away from home? Or perhaps you find it challenging to maintain a consistent watering schedule? An ESP32-based plant watering system might be the solution for you. In this article, we'll explore how to create an automated plant watering system using the ESP32 microcontroller, ensuring your plants stay healthy and hydrated even when you're not around.
The ESP32 microcontroller is a powerful and versatile device, widely used in IoT (Internet of Things) projects due to its built-in Wi-Fi and Bluetooth capabilities. Leveraging these features, we can create a smart plant watering system that monitors soil moisture and waters the plants accordingly.
Working Principle
The plant watering system utilizes sensors to measure soil moisture levels. The ESP32 reads these values and decides whether to water the plants based on predefined thresholds. When watering is required, the ESP32 triggers a water pump to supply water to the plants until the desired moisture level is reached.
Things We Need
To build this plant watering system, gather the following components:
- ESP32 microcontroller
- Soil moisture sensor (e.g., FC-28)
- Water pump
- Relay module
- Power supply
- Jumper wires
- Breadboard
- Peristaltic tubing for water delivery
Circuit Diagram
Insert here a well-labeled circuit diagram illustrating the connections between the ESP32, soil moisture sensor, water pump, and relay module.
Working of the System with Arduino
- Connect the Hardware:
Set up the hardware by connecting the soil moisture sensor to the ESP32 and linking the water pump through a relay module. - Read Soil Moisture:
Read the soil moisture levels using the soil moisture sensor. The sensor will provide analog data that varies with the moisture content in the soil. - Interpret Moisture Levels:
Define moisture thresholds based on the sensor readings. For example, if the moisture level falls below a certain threshold, the system determines that the plants need watering. - Activate Water Pump:
When the moisture level is below the defined threshold, activate the water pump through the relay module to supply water to the plants. - Monitor Moisture Changes:
Continuously monitor the soil moisture and adjust the water pump's operation accordingly to maintain optimal moisture levels.
Arduino Code
Here's a simplified example of the code to achieve the working described above:
#include <Wire.h>
const int soilMoisturePin = A0; // Soil moisture sensor connected to analog pin A0
const int pumpRelayPin = 12; // Relay module connected to pin 12
void setup() {
pinMode(soilMoisturePin, INPUT);
pinMode(pumpRelayPin, OUTPUT);
}
void loop() {
int moistureLevel = analogRead(soilMoisturePin);
// Define moisture threshold values based on your requirements
int moistureThreshold = 500;
if (moistureLevel < moistureThreshold) {
// Activate the water pump
digitalWrite(pumpRelayPin, HIGH);
delay(5000); // Pump for 5 seconds (adjust as needed)
digitalWrite(pumpRelayPin, LOW); // Turn off the pump
}
delay(10000); // Delay for 10 minutes before checking again (adjust as needed)
}Conclusion
With an ESP32 microcontroller, soil moisture sensor, and a water pump, you can create a smart and efficient plant watering system. This system ensures that your plants receive adequate hydration by autonomously monitoring and watering them based on their specific moisture needs. Experiment with different moisture thresholds and watering intervals to tailor the system to your plants' requirements, ultimately contributing to healthier and happier plants. Happy gardening!

