IoT Based Smart Irrigation System Using NodeMCU ESP8266 & Adafruit IO

by Asis Gotam in Circuits > Sensors

11365 Views, 62 Favorites, 0 Comments

IoT Based Smart Irrigation System Using NodeMCU ESP8266 & Adafruit IO

Irrigation-System.jpg

Farmers across the world face a lot of difficulties in growing crops because of unpredictable weather conditions and shortage of water. The traditional irrigation system uses a large amount of water and supplies uneven water to corps. This affects the quality of crops.

Many farmers already start using the Greenhouse farming and Smart Irrigation System. Emerging IoT technologies and sensors are used to develop the irrigation system that can automatically supply water according to climate conditions like moisture value, temperature, etc.


In this project, we are building an IoT based smart irrigation System using NodeMCU, Moisture sensor, and LDR. It will automatically sprinkle the water to plants when the moisture value goes below a particular value. It will also send the moisture data to Adafruit IO Server to keep track of the land condition. Adafruit IO dashboard will also have some buttons to manually turn on/off the solenoid valve and lights. This project uses a solenoid valve to supply the water to the plants. You can change the moisture value at which the solenoid valve should turn on according to your plant's requirement. Here we are using NodeMCU ESP8666 which is a very popular Wi-Fi module for IoT-based Projects.

Components Required

Hardware


Online Services

Circuit Diagram for Smart Irrigation System Using IoT

Smart-Irrigation-System-Circuit-Diagram.png

In this circuit, the Soil sensor is connected to the A0 pin of NodeMCU. LDR sensor is connected to the D1 pin, and the Relay module is connected to the D0 pin of NodeMCU. Solenoid Valve is connected to the relay module, so whenever NodeMCU generates a trigger, it will sprinkle water.

Adafruit IO Setup for Smart Irrigation System

feed.PNG
toggle.PNG
com dash.PNG
Dashboard.PNG
data.PNG

Adafruit IO is an open data platform that allows you to aggregate, visualize, and analyze live data on the cloud. Using Adafruit IO, you can upload, display, and monitor your data over the internet, and make your project IoT enabled. You can control motors, read sensor data, and make cool IoT applications over the internet using Adafruit IO. For test and try, with some limitation, Adafruit IO is free to use. We have also used Adafruit IO with Raspberry Pi previously.


1. To use Adafruit IO, first, you have to create an account on Adafruit IO. To do this, go to the Adafruit IO website and click on ‘Get started for Free’ on the top right of the screen.

2. After finishing the account creation process, log in to your account and click on ‘AIO Key’ on the top right corner to get your account username and AIO key.

When you click on ‘AIO Key,’ a window will pop up with your Adafruit IO AIO Key and username. Copy this key and username, it will be needed later in the code.


3. Now, after this, you need to create a feed. To create a feed, click on ‘Feed.’ Then click on ‘Actions,’ and then on ‘Create a New Feed’ as shown in the image below.

4. After this, a new window will open to enter the Name and Description of the feed. The writing description is optional.

5. Click on ‘Create,’ after this; you will be redirected to your newly created feed.


For this project, we created a total of three feeds- for solenoid valve, moisture data, and LED. After creating feeds, now create an Adafruit IO dashboard to show all of these feeds on a single page.

To create a dashboard, click on the Dashboard option and then click on the ‘Action,’ and after this, click on ‘Create a New Dashboard.’ In the next window, enter the name for your dashboard and click on ‘Create.’


6. As the dashboard is created now, we will add our feeds to the dashboard. To add a feed, click on the ‘+’ in the top right corner.

First, we will add two toggle buttons blocks to control the LED and solenoid valves. And then one Graph block for Moisture Data.

To add a button on the dashboard, click on the Toggle block.

In the next window, it will ask you to choose the feed, so click on LED feed.

After this, follow the same procedure to create another Toggle button block for the solenoid valve.

7. Now to add the Graph on your dashboard, follow the same procedure, but instead of creating a RESET block, create a Line Chart block for graph view. After creating all the blocks, my dashboard looks like this: You can edit your dashboard by clicking on the settings buttons.

Programming NodeMCU for Smart Irrigation System

Complete source code for Smart Irrigation System is available in the attachment.

Here we are explaining the program step by step so that you can easily understand the working of this code. Start your code by including all the required libraries.

To program the NodeMCU for Smart Irrigation System, plug the NodeMCU into your laptop with a Micro USB Cable and open Arduino IDE. In this program, only the Adafruit MQTT library is used as an external library. You can download the library from here:

Adafruit_MQTT.h

To program NodeMCU with Arduino IDE go to File–>Perferences–>Settings.


Enter https:// arduino.esp8266.com/stable/package_esp82... into the ‘Additional Board Manager URL’ field and click ‘Ok’.

Now go to Tools > Board > Boards Manager.


In Boards Manager window, Type esp in the search box, esp8266 will be listed there below. Now select the latest version of the board and click on install.

After installation is complete, go to Tools >Board >and select NodeMCU 1.0(ESP-12E Module). Now you can program NodeMCU with Arduino IDE.

Then include the WiFi and Adafruit IO credentials that you copied from the Adafruit IO server. These will include the MQTT server, Port No, User Name, and AIO Key

Set up the feed you're publishing to. Here AgricultureData is the feed name.

Set up the feeds you're subscribing to. Here ‘LED’ and ‘Pump’ are the feed names.

Read the LDR reading from the A0 pin and compare the reading. If the reading is less than 200, then turn on the LED else turn off the led.

Read the moisture reading from the sensor and compare the readings with the required value. If it is less than the required value then turn on the water pump else turn it off.

Publish the moisture data to Adafruit IO feed every 5 seconds.

Read the subscribed feeds. If the string is ‘OFF’ is then turn on the LED/Water pump and if the string is ‘ON,’ then turn off the LED/water pump.

Downloads

How NodeMCU Based Smart Irrigation System Works

Smart Irrigation System using IoT

This is how NodeMCU based Smart Irrigation System using IoT works. You can expand this project by using more sensors to measures the other parameters like humidity, pressure, temperature, etc. We have previously built an ESP8266 based weather station to read all these values.

Comment below if you have any doubts regarding this project and check the demonstration video.

Also, Follow us on Instructables for more such interesting projects.