IOT Based Automated Irrigation system using ESP8266 NodeMcu

In the previous article, we’d gone through a simple soil moisture based smart irrigation system and at that time itself we’d thought of implementing and publishing the same system with IOT, an ?IOT based automated irrigation system. IOT is a term which is quite trending these days and so I hope everyone is familiar with that. Having said that, let’s get straight into our?project details.

In contrast to the last one, this system will let us monitor our smart farm via internet, cool huh? Corresponding to the previous one, this IOT based irrigation system will read the moisture content in the soil and switch on the water pump, but with a difference that it will be sending the moisture level and water pump status to the internet allowing us to see it through a webpage on our phone or PC. This is a cool project for engineering students, we hope to come up with more IOT based projects, so stay tuned.

IOT based automated irrigation system

How to setup Arduino IDE with ESP8266 Board

1. Download and install the latest Arduino IDE from Arduino website
2. Open Arduino IDE and click File→ Preferences. Paste the URL “” on the Additional Boards Manager URLs field and click OK
3. Open Tools→ Board→ Boards Manager. And then search ESP8266 and click install.
4. Open tools→ Board→ NodeMcu 1.0
5. Connect NodeMcu Board and open Tools→ Port→ COMxx, where xx is the corresponding port number

And so that’s it, now we’re ready to program.

IOT Based Automated Irrigation system

How to Deploy

? Connect NodeMcu ESP8266 to your PC.
? Upload the program
? Open tools→ Serial monitor→ Set baud rate to 9600
? Press the reset button
? Get the IP address displayed on the serial monitor and enter it to the browser of your PC or any other device
which is?connected to the same wifi network, for example http://192.168.xx.xx

iot irrigation system

Working of IOT Based Automated Irrigation system

Here NodeMcu works as server it will respond to the requests from the clients, now let’s see the program in detail.

Loading the required libraries for ESP8266

Declare three variables; where MOTOR_PIN = D3 is the pin to connect water pump, pump_status is the variable to store water pump status (to check if it’s running or not), and adc_value to store and process the ADC (Analog to Digital Converter) value, which is read from the moisture sensor

Storing the wifi SSID and Password to connect to the wifi network

Creates server object and the server starts on port 80, then the client connects to the server through IP and port 80 (192.168.100.xx:80)


This the function to call when a client request is received, it will return an html webpage, the contents of the page will change depending on the adc_value and the pump_status


The setup function does all the initialization steps, most of the lines above are commented to know what they are for

Above is the loop function

This reads the analog value from the pin “A0” and stores it to the integer variable adc_value, pin A0 is connected to moisture sensor, if water content in the soil is high, then correspondingly the ADC value is high.

Esp8266 has a 10bit ADC, hence the value can vary from 0 to 1023. We’ll map it into 0 to 100, our moisture sensor value varies from 500 to 1023, and so we map it from 500 to 1023.

Checks the adc_value, if the value is less than 5, then set pump_status to check status of motor, and set the pin that connected to water pump, thus switch on water pump, else switch off water pump and clear the pump_status variable.


Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *