top of page
Writer's pictureRamesh G

IoT Smart Irrigation Monitoring and Control System

Updated: Jul 2, 2021



The Smart irrigation System has wide scope to automate the complete irrigation system. Here we are building a IoT based Irrigation System using ESP8266 NodeMCU Module and DHT11 Sensor. It will not only automatically irrigate the water based on the moisture level in the soil but also send the Data to ThingSpeak Server to keep track of the land condition. The System will consist a water pump which will be used to sprinkle water on the land depending upon the land environmental condition such as Moisture, Temperature and Humidity.


Before starting, it is important to note that the different crops require different Soil Moisture, Temperature and Humidity Condition. So in this tutorial we are using such a crop which will require a soil moisture of about 50-55%. So when the soil loses its moisture to less than 50% then Motor pump will turn on automatically to sprinkle the water and it will continue to sprinkle the water until the moisture goes upto 55% and after that the pump will be turned off. The sensor data will be sent to ThingSpeak Server in defined interval of time so that it can be monitored from anywhere in the world.



Components Required

  • NodeMCU ESP8266

  • Soil Moisture Sensor Module

  • Water Pump Module

  • Relay Module

  • DHT11

  • LCD20X4

  • Connecting Wires



Circuit Diagram


DHT11

The DHT11 is a commonly used Temperature and humidity sensor. The sensor comes with a dedicated NTC to measure temperature and an 8-bit microcontroller to output the values of temperature and humidity as serial data. The sensor is also factory calibrated and hence easy to interface with other microcontrollers.

The sensor can measure temperature from 0°C to 50°C and humidity from 20% to 90% with an accuracy of ±1°C and ±1%. So if you are looking to measure in this range then this sensor might be the right choice for you.



Specifications

  • Operating Voltage: 3.5V to 5.5V

  • Operating current: 0.3mA (measuring) 60uA (standby)

  • Output: Serial data

  • Temperature Range: 0°C to 50°C

  • Humidity Range: 20% to 90%

  • Resolution: Temperature and Humidity both are 16-bit

  • Accuracy: ±1°C and ±1%


Pump Motor

Micro DC 3-6V Micro Submersible Pump Mini water pump For Fountain Garden Mini water circulation System DIY project. This is a low cost, small size Submersible Pump Motor which can be operated from a 3 ~ 6V power supply. It can take up to 120 liters per hour with very low current consumption of 220mA. Just connect tube pipe to the motor outlet, submerge it in water and power it. Make sure that the water level is always higher than the motor. Dry run may damage the motor due to heating and it will also produce noise.



Specifications

  • Operating Voltage : 3 ~ 6V

  • Operating Current : 130 ~ 220mA

  • Flow Rate : 80 ~ 120 L/H

  • Maximum Lift : 40 ~ 110 mm

  • Continuous Working Life : 500 hours

  • Driving Mode : DC, Magnetic Driving

  • Material : Engineering Plastic

  • Outlet Outside Diameter : 7.5 mm

  • Outlet Inside Diameter : 5 mm


Relay

This 1-channel 5V control Single-Pole Double-Throw (SPDT) High-level trigger AC power relay board can be controlled directly via a microcontroller and switch up to 10A at 250 VAC. The inputs of 1 Channel 5V Relay Module are isolated to protect any delicate control circuitry.



Specifications

  • Trigger Voltage: 5 VDC

  • Trigger Current : 20 mA

  • Maximum Switching Voltage: 250VAC@10A; 30VDC @10A

  • Single Pole Double Throw (SPDT) Configuration

  • Power supply indicator lamp



Soil Moisture

This soil moisture sensor module is used to detect the moisture of the soil. It measures the volumetric content of water inside the soil and gives us the moisture level as output. The module has both digital and analog outputs and a potentiometer to adjust the threshold level.



Moisture Sensor Module Features & Specifications

  • Operating Voltage: 3.3V to 5V DC

  • Operating Current: 15mA

  • Output Digital - 0V to 5V, Adjustable trigger level from preset

  • Output Analog - 0V to 5V based on infrared radiation from fire flame falling on the sensor

  • LEDs indicating output and power

  • PCB Size: 3.2cm x 1.4cm

  • LM393 based design

  • Easy to use with Microcontrollers or even with normal Digital/Analog IC

  • Small, cheap and easily available

20x4 LCD

A 20x4 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on.

A 20x4 LCD means it can display 20 characters per line and there are 4 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data. This is standard HD44780 controller LCD.


There is no change code for interfacing standard 16x2 or 20x4 LCD.

  • 20 Characters x 4 Lines

  • Built-in HD44780 Equivalent LCD Controller

  • Works directly with ATMEGA, ARDUINO, PIC amd many other microcontroller/kits.

  • 4 or 8 bit data I/O interface

  • Low power consumption


Installing DHT Sensor Library


To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries.

Dht11: you need to Download and install the DHT11 library.

LCD: Download

Subscribe and Download code.


ESP8266 Code


#include <DHT.h>

#include <ESP8266WiFi.h>

String apiKey = "WH8PYV2IJPA4BVRT"; // Enter your Write API key here

const char* server = "api.thingspeak.com";

const char* ssid = "TP-Link_3200"; // your SSID

const char* password = "9500112137"; //your WIFI Password


#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display



#define DHTPIN D3 // GPIO Pin where the dht11 is connected

DHT dht(DHTPIN, DHT11);

WiFiClient client;


const int moisturePin = A0; // moisteure sensor pin

const int motorPin = D0;

unsigned long interval = 10000;

unsigned long previousMillis = 0;

unsigned long interval1 = 1000;

unsigned long previousMillis1 = 0;

float moisturePercentage; //moisture reading

float H; // humidity reading

float T; //temperature reading


void setup()

{

Serial.begin(115200);

delay(10);

lcd.init(); // initialize the lcd

// Print a message to the LCD.

lcd.backlight();

pinMode(motorPin, OUTPUT);

digitalWrite(motorPin, HIGH); // keep motor off initally

dht.begin();

Serial.println("Connecting to ");

Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED)

{

delay(500);

Serial.print("."); // print ... till not connected

}

Serial.println("");

Serial.println("WiFi connected");

}


void loop()

{

// Serial.print(digitalRead(motorPin));

unsigned long currentMillis = millis(); // grab current time


H = dht.readHumidity(); // read humiduty

T = dht.readTemperature(); // read temperature


if (isnan(H) || isnan(T))

{

Serial.println("Failed to read from DHT sensor!");

return;

}


moisturePercentage = ( 100.00 - ( (analogRead(moisturePin) / 1023.00) * 100.00 ) );


if ((unsigned long)(currentMillis - previousMillis1) >= interval1) {

Serial.print("Soil Moisture is = ");

Serial.print(moisturePercentage);

Serial.println("%");

previousMillis1 = millis();

}


if (moisturePercentage < 50) {

digitalWrite(motorPin, LOW); // tun on motor

lcd.setCursor(0,3);

lcd.print("Pump Status: Running");

}

if (moisturePercentage > 50 && moisturePercentage < 59) {

digitalWrite(motorPin, LOW); //turn on motor pump

lcd.setCursor(0,3);

lcd.print("Pump Status: Running");

}

if (moisturePercentage > 60) {

digitalWrite(motorPin, HIGH); // turn off mottor

lcd.setCursor(0,3);

lcd.print("Pump Status: OFF ");

}


if ((unsigned long)(currentMillis - previousMillis) >= interval) {


sendThingspeak(); //send data to thing speak

previousMillis = millis();

client.stop();

}

lcd.setCursor(0,0);

lcd.print("Moisture % :");

lcd.setCursor(13,0);

lcd.print(moisturePercentage);

lcd.setCursor(0,1);

lcd.print("Temp");

lcd.setCursor(8,1);

lcd.print((char)223);

lcd.setCursor(9,1);

lcd.print("C :");

lcd.setCursor(13,1);

lcd.print(T);

lcd.setCursor(0,2);

lcd.print("Humidity % :");

lcd.setCursor(13,2);

lcd.print(H);

delay(1000);


}


void sendThingspeak() {

if (client.connect(server, 80))

{

String postStr = apiKey; // add api key in the postStr string

postStr += "&field1=";

postStr += String(moisturePercentage); // add mositure readin

postStr += "&field2=";

postStr += String(T); // add tempr readin

postStr += "&field3=";

postStr += String(H); // add humidity readin

postStr += String(T); // add tempr readin

postStr += "&field4=";

postStr += String(digitalRead(motorPin)); // add humidity readin

postStr += "\r\n\r\n";


client.print("POST /update HTTP/1.1\n");

client.print("Host: api.thingspeak.com\n");

client.print("Connection: close\n");

client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");

client.print("Content-Type: application/x-www-form-urlencoded\n");

client.print("Content-Length: ");

client.print(postStr.length()); //send lenght of the string

client.print("\n\n");

client.print(postStr); // send complete string

Serial.print("Moisture Percentage: ");

Serial.print(moisturePercentage);

Serial.print("%. Temperature: ");

Serial.print(T);

Serial.print(" C, Humidity: ");

Serial.print(H);

Serial.println("%. Sent to Thingspeak.");

}

}



Finally the data is sent to ThingSpeak server using client.print() function which contains API key, server address and the string which is prepared in previous step.


Finally this is how the data looks on ThingSpeak Dashboard


537 views0 comments

Comments


bottom of page