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

ESP8266 NodeMCU Controlled Smart Irrigation System with I2C LCD Display

View and Edit Project In Cirkit DesignerImage of ESP8266 NodeMCU Controlled Smart Irrigation System with I2C LCD Display

Smart Irrigation System Documentation

Summary

The Smart Irrigation System is designed to automate the watering process for precision farming. It utilizes an ESP8266 NodeMCU microcontroller to monitor soil moisture and ambient temperature/humidity levels. The system displays the sensor data on an I2C LCD screen and controls a water pump through a 1-Channel Relay based on the soil moisture readings. A tactile switch button is included for manual override of the pump. The system is powered by a 2x 18650 battery pack.

Component List

1-Channel Relay (5V 10A)

2x 18650 Battery Pack

I2C LCD 16x2 Screen

Tactile Switch Buttons - 12mm Square

Water Pump

DHT22

Capacitive Soil Moisture Sensor V1.2

ESP8266 NodeMCU

YF-S201 Water Flow Meter

Wiring Details

1-Channel Relay (5V 10A)

2x 18650 Battery Pack

I2C LCD 16x2 Screen

Tactile Switch Buttons - 12mm Square

Water Pump

DHT22

Capacitive Soil Moisture Sensor V1.2

ESP8266 NodeMCU

YF-S201 Water Flow Meter

Documented Code

/*
 * Smart Irrigation System for Precision Farming
 * This code controls a smart irrigation system using an ESP8266 NodeMCU.
 * It reads soil moisture and temperature/humidity data, displays information
 * on an I2C LCD, and controls a water pump via a relay based on sensor data.
 */

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>

// Pin definitions
#define DHTPIN D6
#define DHTTYPE DHT22
#define RELAY_PIN D3
#define BUTTON_PIN D7
#define SOIL_MOISTURE_PIN A0

// I2C LCD setup
LiquidCrystal_I2C lcd(0x27, 16, 2);

// DHT sensor setup
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  // Initialize serial communication
  Serial.begin(115200);

  // Initialize LCD
  lcd.begin();
  lcd.backlight();

  // Initialize DHT sensor
  dht.begin();

  // Initialize relay and button pins
  pinMode(RELAY_PIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT_PULLUP);

  // Initialize soil moisture sensor pin
  pinMode(SOIL_MOISTURE_PIN, INPUT);

  // Initial state of relay
  digitalWrite(RELAY_PIN, LOW);
}

void loop() {
  // Read soil moisture level
  int soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);
  float soilMoisturePercent = map(soilMoistureValue, 0, 1023, 100, 0);

  // Read temperature and humidity
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // Check if any reads failed
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Display data on LCD
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(t);
  lcd.print(" C");
  lcd.setCursor(0, 1);
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print(" %");

  // Print soil moisture to serial monitor
  Serial.print("Soil Moisture: ");
  Serial.print(soilMoisturePercent);
  Serial.println(" %");

  // Control relay based on soil moisture
  if (soilMoisturePercent < 30) {
    digitalWrite(RELAY_PIN, HIGH); // Turn on water pump
  } else {
    digitalWrite(RELAY_PIN, LOW); // Turn off water pump
  }

  // Check if button is pressed
  if (digitalRead(BUTTON_PIN) == LOW) {
    // Manual override to turn on water pump
    digitalWrite(RELAY_PIN, HIGH);
  }

  // Wait before next loop
  delay(2000);
}

This code is responsible for the operation of the Smart Irrigation System. It initializes the sensors and LCD, reads sensor data, displays the data, and controls the water pump based on soil moisture levels. It also provides a manual override function through a button press.