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 DHT11 Feedback

View and Edit Project In Cirkit DesignerImage of ESP8266 NodeMCU Controlled Smart Irrigation System with Soil Moisture Sensing and DHT11 Feedback

Circuit Documentation

Summary

This circuit 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 processes the data and controls a relay that switches a 5V mini water pump on or off. The system also includes a 16x2 I2C LCD display to show the moisture, temperature, and humidity readings. The circuit is powered by a 3.3V supply from the ESP8266 NodeMCU, and the relay is driven by an NPN transistor and a diode for protection.

Component List

Wiring Details

Diode

Relay

Capacitive Soil Moisture Sensor V1.2

ESP8266 NodeMCU

DHT11

NPN Transistor

5V Mini Water Pump

Terminal PCB 2 Pin

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 connected sensors and LCD, reads the soil moisture, temperature, and humidity, and displays the values on the LCD. It also sends the data to the Blynk IoT platform. If the soil moisture is below 40%, it activates the water pump by setting the MOTOR_PIN high.