Smart irrigation system using Nodemcu and Blynk

Smart irrigation system using Nodemcu and Blynk

Hello, welcome back. In this tutorial, we will learn how to make a smart irrigation system using the Nodemcu board and the Blynk app. This project is primarily based on IoT technology. We can monitor the soil moisture and activate the water pump through this project. For that, we can use the internet. Also, a soil moisture sensor and a relay module are used for this. We can use this irrigation system mainly for farms and greenhouses. If you want to make this project using Arduino, click this link.

How does the irrigation system work?

When power ON this system, the Nodemcu board connects to the Blynk app using the internet and Blynk cloud. Then, the soil moisture values are displayed on the Blynk app interface and the LCD. Also, with the button created in this Blynk app, we can turn the relay module ON and OFF. That is, if a water pump is connected to the relay module, it can be turned ON and OFF.

OK, let’s do this project step by step. The required components are given below.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect these components. To do this, use the circuit diagram below.

Smart irrigation system using Nodemcu and Blynk circuit diagram

Step 3

Thirdly, let’s set up the Blynk app step by step.

  • First, Download and install the Blynk app into your smartphone. After, sign up in this app using your Gmail. Then, run this app and click the New project button.
Smart irrigation system using Nodemcu and Blynk
  • Next, enter the project name and select the device and connection type. Then click the Confirm button.
Smart irrigation system using Nodemcu and Blynk
  • Now, you can see the project interface. Then click on the “+” icon in the top corner. After, add the Button Widgets and Gauge Widgets to the interface.
  • OK, now set up this widget. First, click the Button Widget. Then, name it as you like and select the pin as D4. Next, change the values from 1 to 0 and change the mode as the switch.
  • Now, click the Gauge widget and named it. Then, select the pin as V0 and change the input values from 0 to 100. Finally, customize these widgets as you like.

Okay, the Blink app is ready.

Step 4

OK, now let’s creates the program for this project. It is as follows.

/*Irrigation monitoring system with Nodemcu
 * http://srituhobby.com 
 */
 
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

char auth[] = "";//Enter your Auth token
char ssid[] = "";//Enter your WIFI name
char pass[] = "";//Enter your WIFI password

BlynkTimer timer;

void moisture() {
  int value = analogRead(A0);
  value = map(value, 0, 1023, 0, 100);
  Blynk.virtualWrite(V0, value);
  lcd.setCursor(0, 1);
  lcd.print("Moisture: ");
  lcd.print(value);
  lcd.print("  ");
  Serial.println(value);
}

void setup() {
  Serial.begin(9600);
  Wire.begin(D2, D1);
  lcd.init();
  lcd.backlight();
  pinMode(D4, OUTPUT);
  digitalWrite(D4, HIGH);
  lcd.setCursor(0, 0);
  lcd.print("IrrigationSystem");
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(100L, moisture);

}
void loop() {
  Blynk.run();
  timer.run();
}

Code Explanation

Firstly, libraries are included. Also, an object was created for the I2C library.

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

Secondly, includes the Blynk Auth token and the WIFI connection details.

char auth[] = "Ng0491DvMc6e1j81hCiHithkRE2ZVxNF";//Enter your Auth token
char ssid[] = "srituhobby";//Enter your WIFI name
char pass[] = "123456";//Enter your WIFI password

This is the main function of this program.

void moisture() {

//Gets the sensor values and puts them into the variable.
  int value = analogRead(A0);
//These values are converted from 0 to 100.
  value = map(value, 0, 1023, 0, 100);
//These values are sent to the Blynk app.
  Blynk.virtualWrite(V0, value);
// These values are printed on the LCD and the serial monitor.
  lcd.setCursor(0, 1);
  lcd.print("Moisture: ");
  lcd.print(value);
  lcd.print("  ");
  Serial.println(value);
}

In the setup function,

void setup() {

//The serial monitor and LCD begin.
  Serial.begin(9600);
  Wire.begin(D2, D1);
  lcd.init();
  lcd.backlight();
//The relay module pin set as an output pin. 
  pinMode(D4, OUTPUT);
  digitalWrite(D4, HIGH);
//Printed as "Irrigation System" on LCD.
  lcd.setCursor(0, 0);
  lcd.print("IrrigationSystem");
//The Blynk library is beginning 
  Blynk.begin(auth, ssid, pass);
//The main function is called in this code line.
  timer.setInterval(100L, moisture);
}

In the loop function, the Blynk library is run.

void loop() {
  Blynk.run();
  timer.run();
}

Step 5

Lastly, select board and port, After, upload this code to the Nodemcu board.

OK, now run the Blynk app interface and enjoy this project. The full video guide is given below. So, we will meet in the next tutorial.

Smart irrigation system using Nodemcu and Blynk

Smart irrigation system using Nodemcu and Blynk

Similar Posts

3 Comments

Leave a Reply

Your email address will not be published.