ESP8266 Nodemcu Controlled Smart Irrigation System with Soil Moisture Sensing and I2C LCD Display
View and Edit Project In Cirkit Designer
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
- Description: A semiconductor device that allows current to flow in one direction only.
- Purpose: Used for back EMF protection in the circuit.
Relay
- Description: An electrically operated switch that uses an electromagnet to mechanically operate a switch.
- Purpose: Controls the power to the 5V mini water pump.
DHT11
- Description: A basic, ultra-low-cost digital temperature and humidity sensor.
- Purpose: Measures the temperature and humidity of the environment.
NPN-Transistor
- Description: A type of bipolar junction transistor used as a switch or amplifier.
- Purpose: Drives the relay coil.
GND (Ground)
- Description: A reference point in an electrical circuit from which voltages are measured.
- Purpose: Common return path for electric current.
5V Mini Water Pump
- Description: A small pump that operates at 5 volts to move water.
- Purpose: Waters the soil when activated by the relay.
Terminal PCB 2 Pin
- Description: A two-pin terminal block for connecting wires to a PCB.
- Purpose: Connects the water pump to the relay.
Vcc (Voltage Common Collector)
- Description: The power supply pin that provides voltage to the circuit.
- Purpose: Supplies power to the components.
Capacitive Soil Moisture Sensor V1.2
- Description: A sensor that measures the moisture content in the soil using capacitive sensing.
- Purpose: Monitors the soil moisture level.
ESP8266 NodeMCU
- Description: A low-cost Wi-Fi microchip with full TCP/IP stack and microcontroller capability.
- Purpose: Acts as the central controller for reading sensors, driving the relay, and communicating with the Blynk platform.
16x2 I2C LCD
- Description: A liquid crystal display capable of displaying 16 characters per line on 2 lines, with an I2C interface.
- Purpose: Displays the temperature, humidity, and soil moisture readings.
Comments
- Description: Textual annotations in the circuit design.
- Purpose: Provide additional information or instructions about the circuit.
Wiring Details
Diode
- Cathode connected to the base of the NPN-Transistor.
- Anode connected to the coil pin of the Relay.
Relay
- Common 1 connected to Vcc.
- Coil connected to the collector of the NPN-Transistor and anode of the Diode.
- NO 1 connected to the positive pin of the 5V mini water pump and Pin A of the Terminal PCB 2 Pin.
DHT11
- DATA connected to D7 on the ESP8266 NodeMCU.
- GND connected to GND on the ESP8266 NodeMCU.
- VCC connected to CLK on the ESP8266 NodeMCU.
NPN-Transistor
- Emitter (E) connected to GND.
- Collector (C) connected to the coil pin of the Relay.
- Base (B) connected to the cathode of the Diode.
5V Mini Water Pump
- Positive pin connected to NO 1 on the Relay and Pin A of the Terminal PCB 2 Pin.
- Negative pin connected to GND.
Terminal PCB 2 Pin
- Pin A connected to NO 1 on the Relay and positive pin of the 5V mini water pump.
- Pin B connected to GND and negative pin of the 5V mini water pump.
Capacitive Soil Moisture Sensor V1.2
- GND connected to GND on the ESP8266 NodeMCU.
- VCC connected to 3V3 on the ESP8266 NodeMCU.
- AOUT connected to A0 on the ESP8266 NodeMCU.
ESP8266 NodeMCU
- GND connected to GND of the Capacitive Soil Moisture Sensor V1.2, DHT11, and 16x2 I2C LCD.
- 3V3 connected to VCC of the Capacitive Soil Moisture Sensor V1.2.
- A0 connected to AOUT of the Capacitive Soil Moisture Sensor V1.2.
- D7 connected to DATA of the DHT11.
- CLK connected to VCC of the DHT11.
- D1 connected to SCL of the 16x2 I2C LCD.
- D2 connected to SDA of the 16x2 I2C LCD.
- VIN connected to Vcc.
16x2 I2C LCD
- SCL connected to D1 on the ESP8266 NodeMCU.
- SDA connected to D2 on the ESP8266 NodeMCU.
- GND connected to GND.
- VCC connected to Vcc.
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.