Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Wi-Fi Controlled Smart Irrigation System with ESP32 and Multiple Sensors

View and Edit Project In Cirkit DesignerImage of Wi-Fi Controlled Smart Irrigation System with ESP32 and Multiple Sensors

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

  1. 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
  2. DHT22

    • Description: A digital temperature and humidity sensor.
    • Pins: +, Out, -
  3. Ultrasonic Sensor

    • Description: A sensor used to measure distance by using ultrasonic waves.
    • Pins: +VCC, Trigger, Echo, GND
  4. 5V Relay

    • Description: An electromechanical switch used to control high voltage devices.
    • Pins: Normally Open, Common terminal, Normally Closed, In, GND, VCC
  5. Soil Moisture Module

    • Description: A module used to measure the moisture content in the soil.
    • Pins: positive, negative, Analog, Digital, Ground, VCC
  6. SparkFun Soil Moisture Sensor

    • Description: A sensor used to measure the moisture content in the soil.
    • Pins: VCC, GND, SIG
  7. 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
  8. Buzzer

    • Description: An audio signaling device.
    • Pins: PIN, GND

Wiring Details

ESP32 (30 pin)

DHT22

Ultrasonic Sensor

5V Relay

Soil Moisture Module

SparkFun Soil Moisture Sensor

AC-DC PSU board 220V-5V&12V

Buzzer

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.