
Most of the farmers use large portions of farming land, and it becomes very difficult to reach and track each corner of the large land. Sometimes there is a possibility of uneven water sprinkles. This results in the bad quality crops, which further leads to financial losses. In this scenario, the Smart Irrigation System using the Latest IoT technology is helpful and leads to ease of farming.
The Smart Irrigation System has a wide scope to automate the complete irrigation system. Here we are building an IoT based Irrigation System using ESP8266 NodeMCU Module and a 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 of a water pump, which will be used to sprinkle water on the land depending upon the land's environmental conditions, such as Moisture, Temperature and Humidity. This comprehensive guide demonstrates how to build an IoT based smart irrigation system using ESP8266 that automatically monitors soil conditions and controls water distribution. The smart irrigation system using IoT technology revolutionises farming by providing real-time monitoring capabilities through cloud connectivity
We previously built a similar Automatic Plant Irrigation System, which sends alerts on mobile but not on the IoT cloud. Apart from this, a Rain alarm and soil moisture detector circuit can also help build a Smart Irrigation system.
Also, we have built an Advanced IoT based Soil Moisture Monitoring Device. You can check out the demonstration video given below.
Before starting, it is important to note that the different crops require different Soil Moisture, Temperature and Humidity conditions. 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 the Motor pump will turn on automatically to sprinkle the water, and it will continue to sprinkle the water until the moisture goes up to 55% and after that, the pump will be turned off. The sensor data will be sent to the ThingSpeak Server at a defined interval of time so that it can be monitored from anywhere in the world.
Table of Contents
What is a Smart Irrigation System Using IoT?
A smart irrigation system using IoT project is an automated watering system that applies Internet of Things technology to monitor soil conditions and control irrigation based on real-time information. The use of a smart irrigation system substitutes manual systems and ensures the proper use of water, while also taking care of crop health.
Key Benefits of an IoT Based Smart Irrigation System
Feature | Traditional Irrigation | Smart IoT Irrigation |
Monitoring | Manual checking | Real-time automated |
Water Usage | Often excessive | Optimized consumption |
Crop Health | Inconsistent | Maintained automatically |
Labor Required | High | Minimal |
Data Analytics | None | Cloud-based insights |
Required Components for IoT Based Smart Irrigation System Using NodeMCU
- NodeMCU ESP8266
- Soil Moisture Sensor Module
- Water Pump Module
- Relay Module
- DHT11
- Connecting Wires
You can buy all the components required for this project.
Circuit Diagram
The circuit diagram for this IoT Smart Irrigation System is given below:
Programming ESP8266 NodeMCU for Smart Irrigation
For programming the ESP8266 NodeMCU module, only the DHT11 sensor library is used as an external library. The moisture sensor gives analog output, which can be read through the ESP8266 NodeMCU analog pin A0. Since the NodeMCU cannot give an output voltage greater than 3.3V from its GPIO, we are using a relay module to drive the 5V motor pump. Also, the Moisture sensor and DHT11 sensor are powered from an external 5V power supply.
Complete code with a working video is given at the end of this tutorial. Here, we are explaining the program to understand the working flow of the project.
Start by including the necessary library.
#include <DHT.h>
#include <ESP8266WiFi.h>
Since we are using the ThingSpeak Server, the API Key is necessary to communicate with the server. To know how we can get an API Key from ThingSpeak, you can visit the previous article on Live Temperature and Humidity Monitoring on ThingSpeak.
String apiKey = "X5AQ445IKMBYW31H
const char* server = "api.thingspeak.com";
The next Step is to write the Wi-Fi credentials, such as SSID and Password.
const char *ssid = "CircuitDigest";
const char *pass = "xxxxxxxxxxx";
Define the DHT Sensor Pin where the DHT is connected, and choose the DHT type.
#define DHTPIN D3
DHT dht(DHTPIN, DHT11);
The moisture sensor output is connected to Pin A0 of the ESP8266 NodeMCU. And the motor pin is connected to D0 of NodeMCU.
const int moisturePin = A0;
const int motorPin = D0;
We will be using the millis() function to send the data after every defined interval of time, here it is 10 seconds. The delay() is avoided since it stops the program for a defined delay, during which the microcontroller cannot do other tasks. Learn more about the difference between delay() and millis() here.
unsigned long interval = 10000;
unsigned long previousMillis = 0;
Set the motor pin as output, and turn off the motor initially. Start the DHT11 sensor reading.
pinMode(motorPin, OUTPUT);
digitalWrite(motorPin, LOW); // keep motor off initally
dht.begin();
Try to connect to Wi-Fi with the given SSID and Password and wait for the Wi-Fi to be connected. If connected, then go to the next steps.
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
Define the current time of starting the program and save it in a variable to compare it with the elapsed time.
unsigned long currentMillis = millis();
Read temperature and humidity data and save them into variables.
float h = dht.readHumidity();
float t = dht.readTemperature();
If DHT is connected and the ESP8266 NodeMCU can read the readings, then proceed to the next step or return from here to check again.
if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
Read the moisture reading from the sensor and print the reading.
moisturePercentage = ( 100.00 - ( (analogRead(moisturePin) / 1023.00) * 100.00 ) );
Serial.print("Soil Moisture is = ");
Serial.print(moisturePercentage);
Serial.println("%");
If the moisture reading is in between the required soil moisture range, then keep the pump off; if it goes beyond the required moisture, then turn the pump ON.
if (moisturePercentage < 50) {
digitalWrite(motorPin, HIGH);
}
if (moisturePercentage > 50 && moisturePercentage < 55) {
digitalWrite(motorPin, HIGH);
}
if (moisturePercentage > 56) {
digitalWrite(motorPin, LOW);
}
ThingSpeak Cloud Integration
Now, after every 10 seconds, call the sendThingspeak() function to send the moisture, temperature and humidity data to the ThingSpeak server.
if ((unsigned long)(currentMillis - previousMillis) >= interval) {
sendThingspeak();
previousMillis = millis();
client.stop();
}
In the sendThingspeak() function, we check if the system is connected to the server, and if yes, then we prepare a string where the moisture, temperature, and humidity reading is written, and this string will be sent to the ThingSpeak server along with the API key and server address.
if (client.connect(server, 80))
{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(moisturePercentage);
postStr += "&field2=";
postStr += String(t);
postStr += "&field3=";
postStr += String(h);
postStr += "\r\n\r\n";
Finally, the data is sent to the ThingSpeak server using the client.print() function which contains API key, server address and the string which is prepared in the previous step.
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());
client.print("\n\n");
client.print(postStr);
Finally, this is how the data looks on the ThingSpeak Dashboard
This last step finishes the complete tutorial on IoT based Smart Irrigation System. Note that it is important to switch off the motor when the soil moisture has reached the required level after sprinkling water. You can make a smarter system which can contain different controls for different crops.
Technical Summary and GitHub Repository
The Technical Summary outlines the project’s main concept, design approach, and operational details, whereas the GitHub Repository contains complete code, schematics, and reference materials for hands-on learning and replication.
Future Enhancements and Scalability
- Integration of machine learning: To offer predictive irrigation scheduling
- Development of a mobile application: Dedicated smartphone control application
- Integration of solar power: To provide sustainable energy solutions
- Multi-crop capabilities: To allow simultaneous water management of different crop types
- Integration of weather API: To stop watering in the event of rainfall
- Time-based controls: To enable watering only at the best times of the day
- Seasonal adjustments: To comply with seasonal weather patterns
- Multi-zone controls: To enable watering of different crop zones separately
- pH sensors: To record soil acidity
- Light sensors: To record sunlight exposure
- Weather sensors: To detect rain
- Nutrient sensors: To characterise soil fertility
Conclusion
This IoT based smart irrigation system using ESP8266 provides an efficient, cost-effective solution for modern agricultural challenges.
Key Takeaways
» Automation benefit: 80% less manual intervention
» Water efficiency: 30-50% savings in water used
» Scalability: Easy to expand to a larger agricultural system
» Cost-effectiveness: Low investment and payback period
» Educational benefit: Good project to learn about IoT and development
If you face any issues while doing this project, then comment below or reach out to our forum for more relevant questions and their answers.
Frequently Asked Questions on Smart Irrigation System using IOT
⇥ 1. How does an IoT-based smart irrigation system work?
The system is made up of soil moisture sensors arranged to an ESP8266 microcontroller that controls water pumps automatically based on current soil conditions, and allows the data to be sent to cloud-hosted platforms for remote access and monitoring.
⇥ 2. Is it possible to operate this system even if internet access is lost?
The simple pump controller will operate on the local hotspot. However, the remote monitoring and access would require a WiFi connection to the cloud. It is possible to operate the system in offline mode; however, those operations would be very limited.
⇥ 3. How accurate is the soil moisture sensor?
When properly set up, high-quality soil moisture sensors can typically achieve 85-95% accuracy. Calibration and maintenance of the soil moisture sensor will help ensure consistent and accurate moisture readings.
⇥ 4. What crops work best with this irrigation system?
This smart irrigation system will work with vegetables, fruits, herbs and small grains. The thresholds can be controlled to fit any crop moisture levels.
⇥ 5. How often does the system transmit data to the cloud?
The system transmits sensor data to ThingSpeak by default every 10 seconds. That default period can be adjusted to fit the user's needs and the limits of the data plan.
⇥ 6. What maintenance is required for the smart irrigation system?
Regular sensor cleaning, scheduled calibration, wire connections, and assurance that the power supply is consistent are the maintenance requirements which contribute to the best performance of the system.
⇥ 7. Can I incorporate forecast weather data?
Yes, advanced models can incorporate a weather API to prevent watering on forecasted rain, and adjust watering schedules to the weather and forecasted data.
Find the complete program and demonstration Video for this project below.
Applications Built with ESP8266
Several of our earlier projects were developed using the ESP8266; the related resources are listed below.
ESP8266 Interfacing with ARM7-LPC2148- Creating a Webserver to control an LED
In this tutorial, we will interface an ESP8266 Wi-Fi Module with the ARM7-LPC2148 microcontroller and create a web server to control the LED connected to the LPC2148.
How to Send Text Message (SMS) using ESP8266
This tutorial will help you send an SMS to any registered mobile number from ESP8266. The ESP8266 is a powerful Wifi module that has been dominating the world of IOT projects.
Interfacing ESP8266 with PIC16F877A Microcontroller
In this article, let us discuss how to interface the Wi-Fi module ESP8266 with a PIC microcontroller. So far, you might have been using the ESP8266 module as a standalone microcontroller or might have been using it with the Arduino library.
Complete Project Code
#include <DHT.h>
#include <ESP8266WiFi.h>
String apiKey = "X5AQ3EGIKMBYW31H"; // Enter your Write API key here
const char* server = "api.thingspeak.com";
const char *ssid = "CircuitLoop"; // Enter your WiFi Name
const char *pass = "circuitdigest101"; // Enter your WiFi Password
#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);
pinMode(motorPin, OUTPUT);
digitalWrite(motorPin, LOW); // keep motor off initally
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print("."); // print ... till not connected
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop()
{
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, HIGH); // tun on motor
}
if (moisturePercentage > 50 && moisturePercentage < 55) {
digitalWrite(motorPin, HIGH); //turn on motor pump
}
if (moisturePercentage > 56) {
digitalWrite(motorPin, LOW); // turn off mottor
}
if ((unsigned long)(currentMillis - previousMillis) >= interval) {
sendThingspeak(); //send data to thing speak
previousMillis = millis();
client.stop();
}
}
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 += "\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.");
}
}
Comments
The green thing is called "Breadboard Power supply". It suplies the electricity to the breadboard. And yes, the ESP is connected to the pc via usb. The main purpose of usb is "coding the Nodemcu".
plese provide full information and link for money payement also give.
can I buy this project??
please specify the price and time required for delivery
System not running
Hello! How can I purchase this project, and could you please provide me with the details?
You are powering the nodemcu with a usb and you have also used some green thing in the breadboard connceted to power pins, what is that green thing?How much power is it providing?Where can I buy it?What is the alternative for it?Plzzzzzz answer my queries as i am stuck in my project and it is very important to complete it. I will be very thankful to u if u answer my queries.