Building an IoT Smart Water Irrigation Monitoring System with ESP8266 and Blynk | Free Codes | Blynk App

Copy and 1st Paste it to any notepad then paste in arduino IDE
Arduino IDE ESP8266 Code-

// Blynk ESP8266 IOT Smart Plant Water Monitoring System

#define Wifi_SSID "Prashant"
#define Wifi_Pass "12345679"
#define BLYNK_TEMPLATE_ID "TMPL3pj4Dp4x9"
#define BLYNK_TEMPLATE_NAME "IOT Agri Monitoring"
#define BLYNK_AUTH_TOKEN "C8X_SpX60GffMsai7I3Zij3PwueaIABA"
const int AirValue = 750;   //you need to replace this value with Value_1
const int WaterValue = 300;  //you need to replace this value with Value_2



#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>  // Including library for dht

char auth[] = BLYNK_AUTH_TOKEN;       //Authentication code sent by Blynk
char ssid[] = Wifi_SSID;                        //WiFi SSID
char pass[] = Wifi_Pass;                //WiFi Password

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define DHTPIN D4          //pin where the dht11 is connected
DHT dht(DHTPIN, DHT11);
#define ONE_WIRE_BUS D6
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

#define buzzer D5 //Buzzer Pin D5 
#define rainPin D7
int rainState = 0;
int lastRainState = 0;
const int SensorPin = A0;
int soilMoistureValue = 0;
int soilmoisturepercent = 0;
int relay = D0;


#define pirPin D3
int pirValue;
int pinValue;

//Read value from blynk
BLYNK_WRITE(V0)
{
  pinValue = param.asInt();
}



void setup()
{
  Serial.begin(115200);
  delay(100);
  Blynk.begin(auth, ssid, pass);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
  display.clearDisplay();
  pinMode(relay, OUTPUT);
  pinMode(buzzer, OUTPUT);
  sensors.begin(); // Dallas temperature
  dht.begin();
}

void getPirValue(void)        //Get PIR Data
{
  pirValue = digitalRead(pirPin);
  if (pirValue)
  {
    Serial.println("Motion detected");
    Blynk.logEvent("motion_alert","Motion detected in your farm");
    //Blynk.notify("Motion detected in your farm") ;
  }
}

void loop() {
  Blynk.run();
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  sensors.requestTemperatures();
  float temp = sensors.getTempCByIndex(0);

  Serial.print("Soil Temperature: ");
  Serial.println(temp);
  Serial.print("Temperature: ");
  Serial.println(t);
  Serial.print("Humidity: ");
  Serial.println(h);

  Blynk.virtualWrite(V3, t);  //V3 is for Temperature
  Blynk.virtualWrite(V4, h);  //V4 is for Humidity
  Blynk.virtualWrite(V2, temp); //Dallas Temperature

  soilMoistureValue = analogRead(SensorPin);  //put Sensor insert into soil
  Serial.print("Soil Moisture Value: ");
  Serial.println(soilMoistureValue);

  soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);

  Blynk.virtualWrite(V1, soilmoisturepercent); //Soil Moisture sensor

  if (soilmoisturepercent > 100)
  {
    Serial.println("100 %");
    delay(1500);
    display.clearDisplay();

    // display Soil temperature
    display.setTextColor(WHITE);
    display.setTextSize(1);
    display.setCursor(0, 5);
    display.print("RH of Soil: ");
    display.print("100");
    display.print(" %");

    // display Air temperature
    display.setCursor(0, 20);
    display.print("Soil Temp: ");
    display.print(temp);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Soil
    display.setCursor(0, 35);
    display.print("Air Temp: ");
    display.print(t);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Air
    display.setCursor(0, 50);
    display.print("RH of Air: ");
    display.print(h);
    display.print(" %");

    display.display();
    delay(1500);
  }
  else if (soilmoisturepercent < 0)
  {
    Serial.println("0 %");
    delay(1500);
    display.clearDisplay();

    // display Soil temperature
    display.setTextColor(WHITE);
    display.setTextSize(1);
    display.setCursor(0, 5);
    display.print("RH of Soil: ");
    display.print("0");
    display.print(" %");

    // display Air temperature
    display.setCursor(0, 20);
    display.print("Soil Temp: ");
    display.print(temp);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Soil
    display.setCursor(0, 35);
    display.print("Air Temp: ");
    display.print(t);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Air
    display.setCursor(0, 50);
    display.print("RH of Air: ");
    display.print(h);
    display.print(" %");

    display.display();
    delay(1500);
  }
  else if (soilmoisturepercent >= 0 && soilmoisturepercent <= 100)
  {
    Serial.print("Soil moisture percent: ");
    Serial.print(soilmoisturepercent);
    Serial.println("%");
    delay(1500);
    display.clearDisplay();

    // display Soil temperature
    display.setTextColor(WHITE);
    display.setTextSize(1);
    display.setCursor(0, 5);
    display.print("RH of Soil: ");
    display.print(soilmoisturepercent);
    display.print(" %");

    // display Air temperature
    display.setCursor(0, 20);
    display.print("Soil Temp: ");
    display.print(temp);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Soil
    display.setCursor(0, 35);
    display.print("Air Temp: ");
    display.print(t);
    display.print(" ");
    display.cp437(true);
    display.write(167);
    display.print("C");

    // display relative humidity of Air
    display.setCursor(0, 50);
    display.print("RH of Air: ");
    display.print(h);
    display.print(" %");

    display.display();
    delay(1500);
  }
  if (soilmoisturepercent >= 0 && soilmoisturepercent <= 30)
  {
    Serial.println("needs water, send notification");
    //send notification
    Blynk.notify("Plants need water... Pump is activated") ;
    digitalWrite(relay, LOW);
    digitalWrite(buzzer, HIGH);
    Serial.println("Motor is ON");
    WidgetLED PumpLed(V5);
    PumpLed.on();
    delay(1000);
  }
  else if (soilmoisturepercent > 30 && soilmoisturepercent <= 100)
  {
    Serial.println("Soil Moisture level looks good...");
    digitalWrite(relay, HIGH);
    digitalWrite(buzzer, LOW);
    Serial.println("Motor is OFF");
    WidgetLED PumpLed(V5);
    PumpLed.off();
    delay(1000);
  }

  rainState = digitalRead(rainPin);
  Serial.print("Rain State: ");
  Serial.println(!rainState);

  if (rainState == 0 && lastRainState == 0) {
    Serial.println("It's Raining outside!");
    //Blynk.notify("It's Raining outside!") ;
    Blynk.logEvent("rain_alert","Raining in farm");
    lastRainState = 1;
    delay(1000);
    //send notification

  }
  else if (rainState == 0 && lastRainState == 1) {
    delay(1000);
  }
  else {
    Serial.println("No Rains...");
    Serial.println("**********************************");
    Serial.println("");
    lastRainState = 0;
    delay(1000);
  }

  if (pinValue == HIGH)
  {
    getPirValue();
  }
  delay(100);
}










In this video, we dive into the world of IoT and learn how to create a Smart Water Irrigation Monitoring System using the popular ESP8266 microcontroller and the versatile Blynk cloud platform. With this system, you'll be able to monitor and control your garden's irrigation remotely, ensuring optimal water usage and plant health.

We start by explaining the basic concepts of IoT and its applications in agriculture. Then, we walk you through the step-by-step process of setting up the hardware, including connecting the ESP8266 to sensors and actuators. Next, we guide you through the Blynk cloud platform setup, enabling seamless communication between the ESP8266 and your smartphone.

Once everything is connected and configured, we demonstrate how to use the Blynk app to remotely monitor the soil moisture levels, adjust watering schedules, and receive notifications on your smartphone. With the free code provided in the video, you can easily replicate this project and customize it to suit your specific needs.

Join us on this exciting journey of building an IoT Smart Water Irrigation Monitoring System and take control of your garden's watering with just a few taps on your smartphone!

Hashtags: #IoTProject #SmartWaterIrrigation #ESP8266 #BlynkCloudPlatform #BlynkApp #DIY #GardenAutomation #WaterConservation #RemoteMonitoring #SensorBasedIrrigation #HomeAutomation


Title: Building an IoT Smart Water Irrigation Monitoring System with ESP8266 and Blynk Introduction: In today's world, where smart technology is revolutionizing every aspect of our lives, it's no surprise that even traditional activities like gardening and agriculture are being enhanced by the Internet of Things (IoT). In this blog post, we will explore how to create a Smart Water Irrigation Monitoring System using the popular ESP8266 microcontroller and the versatile Blynk cloud platform. With this system, you'll be able to monitor and control your garden's irrigation remotely, optimizing water usage and ensuring healthier plants. Understanding IoT and Its Applications in Agriculture: Before diving into the details of the project, let's briefly understand what IoT is and how it can be beneficial in the field of agriculture. IoT refers to the network of physical devices, vehicles, appliances, and other objects embedded with sensors, software, and connectivity to exchange data over the internet. In agriculture, IoT has immense potential to improve productivity, reduce costs, and conserve resources. Components and Setup: To build our Smart Water Irrigation Monitoring System, we will be using the ESP8266 microcontroller, known for its low cost and Wi-Fi capabilities. Additionally, we will leverage the power of the Blynk cloud platform, which provides a user-friendly interface for remote control and monitoring of IoT devices. The hardware setup involves connecting sensors to measure soil moisture levels and actuator modules to control the irrigation system. We will guide you through the process of wiring the components and connecting them to the ESP8266. Configuring Blynk Cloud Platform: Once the hardware is set up, we will explore the Blynk cloud platform, which acts as a bridge between the ESP8266 and your smartphone. Blynk allows you to create a customized mobile app interface with widgets that can be used to monitor sensor readings, control the irrigation system, and receive notifications. We will explain the steps to create a Blynk account, set up a new project, and generate an authentication token necessary to establish communication between the ESP8266 and the Blynk app. Controlling and Monitoring the System: With the hardware and software components in place, we will demonstrate how to use the Blynk app to remotely monitor soil moisture levels in real-time. You'll be able to visualize the data using intuitive graphs and charts. Furthermore, we will show you how to configure the Blynk app to send notifications when the soil moisture drops below a certain threshold, ensuring timely intervention. Free Code and Customization: To help you get started, we provide the necessary code snippets in the blog post. The code will cover the basics of connecting the ESP8266 to Blynk, reading sensor data, and controlling the irrigation system. You can modify the code to suit your specific requirements and expand the functionality of the system. Conclusion: By building an IoT Smart Water Irrigation Monitoring System using ESP8266 and Blynk, you can take your gardening or agriculture practices to the next level. This project enables you to remotely monitor soil moisture levels, control irrigation, and receive notifications on your smartphone. With the power of IoT, you can achieve optimal water usage, conserve resources, and ensure the health of your plants. Start your journey into the world of IoT-enabled gardening today and experience the convenience and efficiency it brings! Hashtags: #IoT #SmartWaterIrrigation #ESP8266 #Blynk #Gardening #Agriculture #WaterConservation #RemoteMonitoring #SensorBasedIrrigation #DIY #HomeAutomation

Comments