Wi-Fi Controlled Smart Irrigation System with ESP32 and Multiple Sensors
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This document provides a detailed overview of a circuit designed to monitor environmental conditions and control a motor based on specific criteria. The circuit includes an ESP32 microcontroller, various sensors (DHT22, Ultrasonic Sensor, Soil Moisture Sensor), a relay, a buzzer, and a power supply unit. The ESP32 is programmed to read sensor data and control the motor based on temperature, humidity, and soil moisture levels over time.
Component List
ESP32 (30 pin)
- Description: A powerful microcontroller with built-in WiFi and Bluetooth capabilities.
- Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
DHT22
- Description: A digital temperature and humidity sensor.
- Pins: +, Out, -
Ultrasonic Sensor
- Description: A sensor used to measure distance by using ultrasonic waves.
- Pins: +VCC, Trigger, Echo, GND
5V Relay
- Description: An electromechanical switch used to control high voltage devices.
- Pins: Normally Open, Common terminal, Normally Closed, In, GND, VCC
Soil Moisture Module
- Description: A module used to measure the moisture content in the soil.
- Pins: positive, negative, Analog, Digital, Ground, VCC
SparkFun Soil Moisture Sensor
- Description: A sensor used to measure the moisture content in the soil.
- Pins: VCC, GND, SIG
AC-DC PSU board 220V-5V&12V
- Description: A power supply unit that converts 220V AC to 5V and 12V DC.
- Pins: AC-N, AC-L, +5V, GND, +12V
Buzzer
- Description: An audio signaling device.
- Pins: PIN, GND
Wiring Details
ESP32 (30 pin)
- D34 connected to Soil Moisture Module Analog
- GND connected to AC-DC PSU board GND, Buzzer GND, DHT22 -, Ultrasonic Sensor GND, Soil Moisture Module Ground, 5V Relay GND
- D22 connected to Buzzer PIN
- D18 connected to Ultrasonic Sensor Echo
- D5 connected to Ultrasonic Sensor Trigger
- D4 connected to DHT22 Out
- D15 connected to 5V Relay In
- 3V3 connected to DHT22 +, Soil Moisture Module VCC
DHT22
- + connected to ESP32 3V3
- Out connected to ESP32 D4
- - connected to ESP32 GND
Ultrasonic Sensor
- +VCC connected to AC-DC PSU board +5V
- Trigger connected to ESP32 D5
- Echo connected to ESP32 D18
- GND connected to ESP32 GND
5V Relay
- In connected to ESP32 D15
- GND connected to ESP32 GND
- VCC connected to AC-DC PSU board +5V
Soil Moisture Module
- Analog connected to ESP32 D34
- Ground connected to ESP32 GND
- VCC connected to ESP32 3V3
- positive connected to SparkFun Soil Moisture Sensor VCC
- negative connected to SparkFun Soil Moisture Sensor GND
SparkFun Soil Moisture Sensor
- VCC connected to Soil Moisture Module positive
- GND connected to Soil Moisture Module negative
AC-DC PSU board 220V-5V&12V
- GND connected to ESP32 GND
- +5V connected to Ultrasonic Sensor +VCC, 5V Relay VCC
Buzzer
- PIN connected to ESP32 D22
- GND connected to ESP32 GND
Code Documentation
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Sharath Teja";
const char* password = "SHARATH R";
unsigned long startTime;
const unsigned long dayMillis = 86400000; // Milliseconds in a day
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
// Set motor pin as output
pinMode(motorPin, OUTPUT);
startTime = millis();
}
void loop() {
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - startTime;
unsigned int days = elapsedTime / dayMillis;
// Check the number of days and control motor accordingly
if (days < 14) {
if(temperature>30 && humidity<70 && soilmoisture<20){
digitalWrite(motorPin, HIGH); // Turn motor ON
}
else {
digitalWrite(motorPin, LOW); // Turn motor OFF
}
}
else if (days >= 14 && days < 28) {
if(temperature>25 && humidity<60 && soilmoisture<40){
digitalWrite(motorPin, HIGH); // Turn motor ON
}
else {
digitalWrite(motorPin, LOW); // Turn motor OFF
}
}
else if (days >= 28 && days < 42) {
if(temperature>30 && humidity<50 && soilmoisture<60){
digitalWrite(motorPin, HIGH); // Turn motor ON
}
else {
digitalWrite(motorPin, LOW); // Turn motor OFF
}
}
else if (days >= 42 && days < 56) {
if(temperature>30 && humidity<40 && soilmoisture<80){
digitalWrite(motorPin, HIGH); // Turn motor ON
}
else {
digitalWrite(motorPin, LOW); // Turn motor OFF
}
}
else if (days >= 56 && days < 70) {
if(temperature>30 && humidity<40 && soilmoisture<60){
digitalWrite(motorPin, HIGH); // Turn motor ON
}
else {
digitalWrite(motorPin, LOW); // Turn motor OFF
}
}
delay(6000); // Update every 60 seconds
}
This code is designed to connect the ESP32 to a WiFi network and control a motor based on temperature, humidity, and soil moisture readings. The motor control logic changes based on the number of days elapsed since the start of the program.