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

ESP8266 Nodemcu Controlled Smart Irrigation System with Soil Moisture Sensing and I2C LCD Display

View and Edit Project In Cirkit DesignerImage of ESP8266 Nodemcu Controlled Smart Irrigation System with Soil Moisture Sensing and I2C LCD Display

Circuit Documentation

Summary

The circuit in question is designed to monitor soil moisture levels and control a water pump based on the moisture data. It uses an ESP8266 NodeMCU microcontroller to read data from a capacitive soil moisture sensor and a DHT11 temperature and humidity sensor. The microcontroller also controls a relay that switches a 5V mini water pump on or off. The system's status is displayed on a 16x2 I2C LCD. The circuit is powered by a 3.3V supply from the ESP8266 NodeMCU, and the relay is driven by an NPN transistor. A diode is used for back EMF protection. The system is capable of sending data to the Blynk IoT platform for remote monitoring.

Component List

Diode

Relay

DHT11

NPN-Transistor

GND (Ground)

5V Mini Water Pump

Terminal PCB 2 Pin

Vcc (Voltage Common Collector)

Capacitive Soil Moisture Sensor V1.2

ESP8266 NodeMCU

16x2 I2C LCD

Comments

Wiring Details

Diode

Relay

DHT11

NPN-Transistor

5V Mini Water Pump

Terminal PCB 2 Pin

Capacitive Soil Moisture Sensor V1.2

ESP8266 NodeMCU

16x2 I2C LCD

Documented Code

#define BLYNK_TEMPLATE_ID "TMPL36RX0P6rk"
#define BLYNK_TEMPLATE_NAME "PROJECT5"
#define BLYNK_AUTH_TOKEN "5YkIXWTwTpnhqS3O2XBt577msEFR1KU2"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <ESP8266WiFi.h> 
#include <BlynkSimpleEsp8266.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); 
char ssid[]="Redmi 9";
char password[]="11111111";
const float referenceResistor = 10000.0;
const float betaCoefficient = 3950.0;
const float nominalResistance = 10000.0;
const int adcMaxValue = 1023;
#define DHTPIN D7
#define soilpin A0
#define DHTTYPE DHT11
#define MOTOR_PIN D3

DHT dht(DHTPIN, DHTTYPE); 

void setup() {
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  dht.begin();
  pinMode(soilpin, INPUT);
  pinMode(MOTOR_PIN, OUTPUT);
  Blynk.begin(BLYNK_AUTH_TOKEN,ssid,password);
}

void loop() {

  int soilvalue = analogRead(soilpin);
  
  float persoilvalue = map(soilvalue, 0, 1023, 0, 100);
  
  float temval = dht.readTemperature();
  float humval = dht.readHumidity();

  if (isnan(temval) || isnan(humval)) {
    Serial.println("Failed to read from DHT sensor!");
    return; 
  }

  lcd.setCursor(0, 0);
  lcd.print("Moist: ");
  lcd.print(persoilvalue);
  lcd.print(" %");
  
  lcd.setCursor(0, 1);
  lcd.print("HUM: ");
  lcd.print(humval);
  lcd.print(" %");
  Blynk.virtualWrite(V4,humval);
  Blynk.virtualWrite(V1,temval);
  Blynk.virtualWrite(V3,persoilvalue);
  Blynk.run();

  Serial.print("Temp: ");
  Serial.println(temval);
  
  Serial.print("Humidity: ");
  Serial.println(humval);
  
  Serial.print("Soil Moisture: ");
  Serial.println(persoilvalue);

  if (persoilvalue < 40) {
    digitalWrite(MOTOR_PIN, HIGH);  
  } else {
    digitalWrite(MOTOR_PIN, LOW);  
  }

  delay(1000);
}

This code is designed to run on an ESP8266 NodeMCU microcontroller. It initializes the DHT11 sensor and the LCD display, reads the soil moisture level, temperature, and humidity, and displays the values on the LCD. It also sends the data to the Blynk platform. If the soil moisture level is below 40%, it activates the water pump by setting the MOTOR_PIN high.