- LED Blink with Button
- Motion Detection Alarm System
- Simple RGB LED Controller
- Blinking LED with WebSocket Control
- Control LED Brightness using PWM
- Web Page with HTML and CSS on ESP32
- Control Multiple LEDs
- ESP32 with Bluetooth Serial Communication
- EEPROM with ESP32
- ESP32 Push Button Input: Reading Digital States
- Interfacing DHT11 Sensor
- Interfacing Ultrasonic Sensor
- Interfacing Flame Sensor
- Interfacing Sound Sensor
- Interfacing Potentiometer
- Interfacing IR Sensor
- Interfacing Servo Motor
- Interfacing Cam Wireless
- Interfacing DC Motor
- Interfacing Shock Sensor
- Interfacing Color Recognition Sensor
- Interfacing RFID Module
- TTGO LoRa32 SX1276 OLED
- Interfacing Keypad
- Interfacing Solenoid Lock
- Interfacing 16x2 LCD
- Interfacing Soil Moisture
- Interfacing MQ-7 Gas Sensor
- Interfacing Light Sleep Mode
- Interfacing Smart Light Control
- Interfacing (IoT) Weather Station
- Interfacing Web Server for Temperature Data Display
- Interfacing Home Automation System with Relay Control
- Interfacing IoT Smart Garden
- Face Recognition-Based Door Unlock System
- Interfacing Wi-Fi Jammer Detector
- Interfacing Health Band with Pulse
- Interfacing Sound Level Logger for Classrooms
- Night Vision Surveillance Camera
- Solar Panel Monitoring System
- Smart Farming Robot for Crop Surveillance
- Smart Water Quality Monitoring System
- Industrial IoT Gateway for Real-Time Monitoring
- Agriculture System with Automated Drone Control
ESP32 IoT Smart Garden
Introduction to Smart Garden System with ESP32
A smart garden system automates the process of managing plant care by monitoring environmental factors like soil moisture, temperature, and light intensity. In this project, we will use an ESP32 microcontroller to build an IoT-based smart garden. The ESP32 will gather sensor data and send it to a web interface for remote monitoring and control. This system also allows automatic irrigation by controlling a water pump based on soil moisture levels.
Components Required
To build the ESP32-powered smart garden system, you'll need a variety of sensors and components, including an ESP32 development board, a soil moisture sensor, temperature and humidity sensor, a light sensor, a relay module to control the water pump, and a water pump for automatic irrigation.
- Install necessary libraries (WiFi, DHT, Soil Moisture, Relay control, and ESPAsyncWebServer) in Arduino IDE.
- Connect the soil moisture sensor, temperature & humidity sensor, light sensor, and relay module to the ESP32.
- Write code to collect data from all the sensors and send it to a web interface.
- Create a simple web page that displays the sensor readings and allows the user to control the irrigation system (turning the water pump ON/OFF).
- Program the ESP32 to trigger the water pump based on the soil moisture levels.
- Upload the code to the ESP32 and test the system by checking sensor readings and controlling the water pump.
Formula: Irrigation Control: If (soilMoisture < 30) { relay.setState(ON); } else { relay.setState(OFF); }
Components List
- 1 × ESP32 Development Board
- 1 × Soil Moisture Sensor
- 1 × DHT11 or DHT22 Temperature & Humidity Sensor
- 1 × LDR (Light Dependent Resistor) for light monitoring
- 1 × Relay Module
- 1 × Water Pump
- 1 × Breadboard and Jumper Wires
- 1 × Power Supply (e.g., 5V USB power adapter)
- 1 × Wi-Fi Network
- 1 × Computer or Smartphone with Web Browser
Pin Configuration
- GPIO 23 (Soil Moisture Sensor): Soil moisture sensor's analog output connected to GPIO 23 on the ESP32.
- GPIO 22 (Temperature and Humidity Sensor): DHT sensor's data pin connected to GPIO 22 for temperature and humidity readings.
- GPIO 21 (Light Sensor): LDR sensor connected to GPIO 21 to measure light intensity.
- GPIO 19 (Relay Module Control Pin): Relay module's control pin connected to GPIO 19 for water pump control.
- GPIO 18 (Relay VCC Pin): Relay module's VCC pin connected to the 5V pin of the ESP32.
- GPIO 17 (Relay GND Pin): Relay module's GND pin connected to the ESP32 GND.
Ensure the water pump is rated for the appropriate voltage and is compatible with the relay module's specifications.
Wiring and Connections
- -> GPIO 23 (Analog Input)
- -> GPIO 22 (Data Pin)
- -> GPIO 21 (Analog Input)
- -> GPIO 19 (Control Pin)
- -> 5V (Power Pin)
- -> GND (Ground)
- ->
Code for ESP32 Smart Garden System
1#include <WiFi.h>
2#include <ESPAsyncWebServer.h>
3#include <DHT.h>
4#include <Wire.h>
5
6const char* ssid = "Your_SSID";
7const char* password = "Your_PASSWORD";
8
9#define DHTPIN 22
10#define DHTTYPE DHT11
11#define SOIL_PIN 23
12#define LDR_PIN 21
13#define RELAY_PIN 19
14
15DHT dht(DHTPIN, DHTTYPE);
16AsyncWebServer server(80);
17
18void setup() {
19 Serial.begin(115200);
20 WiFi.begin(ssid, password);
21 while (WiFi.status() != WL_CONNECTED) {
22 delay(1000);
23 Serial.println("Connecting to WiFi...");
24 }
25 Serial.println("Connected to WiFi");
26 dht.begin();
27 pinMode(SOIL_PIN, INPUT);
28 pinMode(RELAY_PIN, OUTPUT);
29 digitalWrite(RELAY_PIN, LOW); // Initial state (OFF)
30
31 server.on("/getSensorData", HTTP_GET, [](AsyncWebServerRequest *request) {
32 int soilMoisture = analogRead(SOIL_PIN);
33 float temp = dht.readTemperature();
34 float humidity = dht.readHumidity();
35 int lightLevel = analogRead(LDR_PIN);
36 String response = "<h1>Sensor Data</h1><p>Soil Moisture: " + String(soilMoisture) + "</p><p>Temperature: " + String(temp) + "°C</p><p>Humidity: " + String(humidity) + "%</p><p>Light Level: " + String(lightLevel) + "</p>";
37 request->send(200, "text/html", response);
38 });
39
40 server.on("/controlPump", HTTP_GET, [](AsyncWebServerRequest *request) {
41 int soilMoisture = analogRead(SOIL_PIN);
42 if (soilMoisture < 30) {
43 digitalWrite(RELAY_PIN, HIGH); // Turn ON the water pump
44 } else {
45 digitalWrite(RELAY_PIN, LOW); // Turn OFF the water pump
46 }
47 request->send(200, "text/html", "<h1>Water Pump Control</h1>");
48 });
49
50 server.begin();
51}
52
53void loop() {
54 // No need for continuous code in loop() as the web server handles it
55}
Code Explanation
- #include <WiFi.h>: This line includes the WiFi library to allow the ESP32 to connect to a wireless network.
- #include <DHT.h>: Includes the DHT library for reading temperature and humidity data from the DHT sensor.
- server.on("/getSensorData", HTTP_GET, [](AsyncWebServerRequest *request) {: Defines the web route for fetching sensor data (soil moisture, temperature, humidity, light level).
- int soilMoisture = analogRead(SOIL_PIN);: Reads the analog value from the soil moisture sensor.
- if (soilMoisture < 30) { digitalWrite(RELAY_PIN, HIGH); }: Turns ON the water pump if the soil moisture is below 30%.
Applications
- Automated irrigation systems for gardens or farms.
- Remote monitoring and control of garden environment via the web.
- Smart gardening solutions that optimize water usage based on sensor data.
- IoT-based systems for home gardening enthusiasts and hobbyists.
Conclusion
The ESP32-based smart garden system demonstrates how to automate garden care by monitoring key environmental parameters. By using IoT technology, the system not only keeps plants healthy but also allows remote control and monitoring via a web interface. This project serves as a great introduction to IoT-based automation and can be expanded with more sensors or features for advanced gardening solutions.