Generaed image for IoT Smart irrigation
Imagine having a farm that waters itself automatically and even alerts you when erosion starts washing your soil away. That’s exactly what this IoT Smart Irrigation with Soil Erosion Monitoring project does. Using NodeMCU (ESP8266), Blynk IoT dashboard, and a few smart sensors, this project combines automation, sustainability, and innovation into one system.
Whether you’re a student, maker, or agricultural enthusiast, this project will help you understand how IoT can revolutionize farming — especially when soil erosion and moisture management are involved.
Let’s dive into how the IoT irrigation with soil moisture and erosion detection system works, the components used, and how it was built.
An IoT Smart Irrigation System automates the watering of plants based on real-time soil and environmental data. It uses sensors to detect moisture, temperature, and humidity, sending this data to an online platform like Blynk for monitoring and control.
Instead of manually checking the soil or turning on pumps, the system decides when to water the plants. It ensures water efficiency and promotes healthier plant growth — perfect for modern smart farming.
You may also want to read: How Smart Weather Stations Revolutionize Farming
While most smart irrigation systems focus only on water control, this project adds a twist — soil erosion monitoring.
Soil erosion affects fertility and can destroy the root zone of plants. By detecting erosion levels in real time, you can take preventive actions before the soil degrades further.
In this project, IoT irrigation with soil moisture and erosion detection, laser and LDR pairs are used to sense soil displacement at different levels — top, middle, and bottom — simulating how much soil has been washed away.
This is the brain of the system. It’s WiFi-enabled, Arduino-compatible, and powerful enough to handle multiple sensors. It connects the hardware setup to the Blynk IoT dashboard, allowing you to monitor and control irrigation remotely.
You may also want to read: DIY IoT Hydroponic & Aquaculture Monitor with Arduino Nano, ESP-01, and Blynk
This sensor determines how wet or dry the soil is. When the soil gets too dry, it triggers the system to turn on the DC water pumps for irrigation.
This measures the soil temperature. High temperatures usually lead to dryness, and this helps the system balance when and how much water is needed.
Used to measure the ambient humidity around the plants. It helps in adjusting irrigation frequency depending on environmental conditions.
Three laser–LDR pairs are positioned vertically: top, middle, and bottom.
These pumps automatically irrigate the soil when dryness is detected. Controlled via a 5V relay, they are powered by the NodeMCU’s control logic.
This relay acts as a switch that the NodeMCU controls. It isolates high-current loads (the pumps) from the low-voltage logic of the NodeMCU.
A stable 5V DC supply powers the entire system. JST connectors make wiring modular and easy for maintenance or replacement.
The hardware is neatly enclosed in this box for safety, durability, and aesthetics.
When the soil moisture sensor detects that the soil is dry beyond a set threshold, the NodeMCU activates the relay, turning on the water pumps. As water soaks into the soil, the sensor detects the change and automatically switches the pumps off when enough moisture is reached.
Simultaneously, the DS18B20 and DHT11 sensors collect environmental data like soil temperature and humidity.
The laser-LDR system continuously monitors soil erosion. If one of the LDRs detects its laser beam, it means that level of soil has been eroded, and the data is logged to Blynk for real-time observation. It also uses the laser-LDR system to calibrate or measure the soil levels in percentage. If the top LDR detects its own laser, this means the soil has been washed off by 27%, and if the middle LDR detects on own laser, this also means, the soil has been washed away by 54% and so on.
Everything happens seamlessly through the Blynk IoT app, where you can monitor sensor values, receive alerts, and manually control the pumps if needed by using the app’s onboard online button.
The NodeMCU (ESP8266-12E) is ideal because:
Since Blynk works perfectly with NodeMCU, it makes cloud-based monitoring easy and visual.
Here’s a brief overview of the connections:
From the above breadboard view schematic diagram done with Fritzing;
The voltage divider network of resistors formed our method of reading the states of the LDRs when light was present and when it was absent. We could read a HIGH when there was light shining on them and a LOW when there were no laser lights on them.
We used the transistors to form a common-emitter follower circuit which we used to drive the 5V DC pumps. Since the NPN transistors used were the TIP41C transistors, this was quite possible.
You can program the NodeMCU using Arduino IDE.
#define BLYNK_TEMPLATE_ID "TMPL254hf7xAQ"
#define BLYNK_TEMPLATE_NAME "IoT Soil Moisture Monitoring"
#define BLYNK_AUTH_TOKEN "LR52s6CJD8hLxLOlhOcWZERp7bJEW7AJ"
//include the dht11 lib
#include "DHT.h"
/* Comment this out to disable prints and save space */#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Digital pin connected to the DHT sensor
#define DHTPIN D3
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Galaxy A51 917E";
char pass[] = "tosin@345";
BlynkTimer timer;
#include <OneWire.h>
#include <DallasTemperature.h>
// GPIO where the DS18B20 is connected to
const int pumpPin = D4;
const int oneWireBus = D5;
const int ldrOne = D6;
const int ldrTwo = D7;
const int ldrThree = D8;
//define user safe zone
int minSafeZone = 30;
int maxSafeZone = 80;
//create a variable to keep track of state
int laserStatus;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
float tempCelsius(){
//calculate for temperature
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
float temperatureF = sensors.getTempFByIndex(0);
Serial.print("Temp in Degree Celsius: ");
Serial.print(temperatureC);
Serial.print("ºC ");
Serial.print(" Temp in Degree Fahreneit: ");
Serial.print(temperatureF);
Serial.println("ºF");
return temperatureC;
}
int soilMoisture(){
int soilWater = analogRead (A0);
soilWater = map(soilWater, 1024, 400, 0, 1000);
soilWater = constrain(soilWater, 0, 1000);
//use conditional statements to automatically control soil irrigation
if(soilWater <= 100){
digitalWrite(pumpPin, HIGH);
Serial.println("Pump Irrigating model now!!!");
}
else if(soilWater >= 890){
digitalWrite(pumpPin, LOW);
Serial.println("Pump Irrigation Turned off!!!");
}
else{
Serial.println("User can control pump now!!!");
}
//print out the soil moisture level
Serial.print("Soil Moisture: ");
Serial.print(soilWater);
Serial.println("L/m3");
return soilWater;
}
int erosionSensor(){
//read the input ldr
int readLDROne = digitalRead(ldrOne);
int readLDRTwo = digitalRead(ldrTwo);
int readLDRThree = digitalRead(ldrThree);
//use conditional statement
if ((readLDROne == 0) && (readLDRTwo == 0) && (readLDRThree == 0)) {
laserStatus = 0; //return one
Serial.println("No Soil exposes. NO EROSION");
}
//check if only 1 laser can pass through
if ((readLDROne == 1) && (readLDRTwo == 0) && (readLDRThree == 0)) {
laserStatus = 1; //return one
Serial.println("Minimum Soil exposes. Min EROSION");
}
//check if only 2 lasers can pass through
if ((readLDROne == 1) && (readLDRTwo == 1) && (readLDRThree == 0)) {
laserStatus = 2; //return two
Serial.println("Moderate Soil exposes. MODERATE EROSION");
}
//check if all lasers can pass through
if ((readLDROne == 1) && (readLDRTwo == 1) && (readLDRThree == 1)) {
laserStatus = 3;
Serial.println("All Soil exposes. MAX EROSION");
}
Serial.println(String("LDR 1: ") + readLDROne + String(" LDR 2: ")+ readLDRTwo + String(" LDR 3: ") + readLDRThree + String(" laser status: ") + laserStatus);
//Serial.println(laserStatus);
return laserStatus; //return the variable used to keep track
}
float humiditySensor(){
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return 0.00;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% "));
Serial.print(F(" Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
return h;
}
//use this fxn to turn on or off the DC pump from the IoT dashboard
BLYNK_WRITE(V3) {
soilMoisture();
int buttonWidget = param.asInt();
Serial.print("Dashboard button: ");
Serial.println(buttonWidget);
//use conditional statement
if((soilMoisture() >= 101 ) && (soilMoisture() <= 850)){
if(buttonWidget == 1 ){
digitalWrite(pumpPin, HIGH);
Serial.println("DC pumps ON");
}
else{
digitalWrite(pumpPin, LOW);
Serial.println("DC pumps OFF");
}
}
}
void myTimerEvent(){
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V0, tempCelsius());
Blynk.virtualWrite(V1, soilMoisture());
Blynk.virtualWrite(V2, erosionSensor());
Blynk.virtualWrite(V4, humiditySensor());
//laserStatus = 0;
}
void setup() {
// Start the Serial Monitor and temp sensor
Serial.begin(115200);
sensors.begin(); //begin the ds18b20 temp sensor
dht.begin(); //begin the dht11 sensor
//declare where the inputs are connected
pinMode(ldrOne, INPUT);
pinMode(ldrTwo, INPUT);
pinMode(ldrThree, INPUT);
pinMode(pumpPin, OUTPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// Setup a function to be called every second
timer.setInterval(2000L, myTimerEvent);
}
void loop() {
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
The above Arduino code is designed for a soil moisture monitoring system that utilizes Blynk for IoT connectivity. It integrates multiple sensors, including a DHT11 temperature and humidity sensor, a DS18B20 temperature sensor, and Light Dependent Resistors (LDRs) to assess erosion. The code enables real-time monitoring and control of irrigation through a connected pump, allowing users to manage soil moisture effectively via a mobile app.
In the beginning, before the setup() function, the code defines necessary libraries and configurations for Blynk, including the template ID, template name, and authentication token. By including libraries such as ESP8266WiFi, BlynkSimpleEsp8266, DHT, OneWire, and DallasTemperature, it sets up the environment for managing sensors and handling Wi-Fi communication. The DHT11 type is specified for the humidity and temperature readings, and the relevant Wi-Fi credentials are defined for network access.
The main functionality is implemented through various functions that handle specific tasks. The tempCelsius() function retrieves temperature readings from the Dallas temperature sensor, while soilMoisture() reads moisture levels from an analog sensor. Based on the moisture readings, it controls a pump’s operation: turning it on when the soil moisture is low and turning it off when the moisture level is high. The erosionSensor() function uses three LDRs to determine soil exposure, indicating potential erosion risks based on light detection.
Another key function is humiditySensor(), which retrieves and computes humidity and heat index values from the DHT sensor. If the reading fails, it gracefully handles the error. Additionally, the BLYNK_WRITE(V3) function allows for manual control of the pump through the Blynk dashboard. The app can turn the pump on or off based on user interactions, further enhancing the system’s automation.
Finally, the setup() function initializes all the necessary sensors and connection to Blynk while defining input and output pin modes. It also sets a timer to send sensor readings to the Blynk server every two seconds using the myTimerEvent() function. The loop() function maintains the Blynk connection and runs the timer, ensuring continuous operation and real-time data updates. This system exemplifies a practical IoT application, providing remote monitoring and control of soil health and irrigation needs.
On the Blynk app (mobile or web):
The beauty of this setup is in automation. You don’t need to manually control anything — the system makes smart decisions based on real-time data.
You can also log data over time on Blynk Cloud or export it for analysis — to understand how soil, weather, and erosion interact.
All modules run on 5V DC. A regulated adapter or battery pack works fine. The pattress box ensures everything remains tidy and protected from moisture or dust.
When we modelled the project design, we considered how to present the project workings. We used the setup pictured above. The reservoirs that housed the two DC pumped were filled with water to that their hoses can sprinkle water to the surface of the soil during irrigation process. Either when it is user enabled or automated by the system design.
This project beautifully merges IoT, automation, and environmental conservation. With just a NodeMCU board, some basic sensors, and a bit of creativity, you can build a system that not only irrigates intelligently but also keeps track of soil erosion — one of the most underrated agricultural challenges.
It’s an ideal project for students, IoT hobbyists, and innovators passionate about sustainable farming.
1. What is soil erosion monitoring in IoT?
It’s a method of detecting changes in soil levels using sensors like LDRs and lasers to determine how much soil has been washed away.
2. Why use Blynk for IoT irrigation projects?
Blynk provides an easy-to-use interface for remote monitoring and automation without complex coding.
3. Can this system work without internet?
Yes, you can run it offline for automation only, but Blynk monitoring requires an internet connection.
4. How does the system decide when to water the plants?
It uses the soil moisture sensor’s readings. When the soil gets dry below a threshold, the relay turns on the pumps automatically.
5. How accurate is the erosion detection system?
In this model, it’s a simulated version — but with proper calibration, similar designs can be used for real agricultural applications.
ChatGPT Image Nov 7, 2025, 04_33_52 PM Ever wondered how bats navigate in total darkness?…
Introduction Have you ever wished your system could tell you when the utility supply comes…
Introduction IoT soil salinity detection in soil salinity is a silent yet formidable enemy of…
The Internet of Things (IoT) has revolutionized countless industries, and hydroponics is no exception. By…
The Future of Homes Is Smart https://youtu.be/dxeC41gVSQ4 Imagine walking into your house, saying “lights on”,…
Weather plays a pivotal role in farming, influencing everything from planting schedules to irrigation needs.…
This website uses cookies.