Automated Gardening With Blynk IOT

Measurement of Soil Moisture Levels with an automatic Irrigation System integrated in Blynk IOT

projectImage

Things used in this project

 

Hardware components

HARDWARE LIST
1 DFRobot Gravity: Analog Capacitive Soil Moisture Sensor- Corrosion Resistant
1 Breadboard (generic)
1 NodeMCU ESP8266 Breakout Board
1 DHT11 Temperature & Humidity Sensor (3 pins)
1 Jumper wires (generic)
1 9V battery (generic)
1 Relay (generic)

Software apps and online services

 

Blynk

Story

 

We all love a little green in our lives, and have some plants in our balconies or tabletops, don't we? Plants are alive like us and require their food for survival, fortunately they only ask a little bit of water everyday from us. But, in your busy lives we can't always tend to our plants, be it work pressure, appointments with someone or even during a vacation, we can't water them during these situations. In order to solve this problem, in this project, we are making an Automatic Irrigation System with an ESP8266 which will irrigate your plants automatically and keep them healthy even when you are out of the town for weeks or months. In this project, a Moisture sensor will be used to maintain the optimum level of moisture for your plants, a DHT11 sensor is used to monitor temperature and humidity and a pump is used to provide water for the plants. This system can be implemented, both for your garden or for your Indoor plants thus taking care of your leafy pals when you are away.

Here, a soil moisture sensor is connected to the A0 pin of the ESP8266 board, which gives the analog input of soil moisture levels. That level is then mapped to a value between 0 and 100 to give an output in a percentage rather than random numbers that the user won’t be able to perceive. The sensor is set to run at an interval of 4 hours by default to avoid corrosion of the sensor. All values are synced to Blynk IOT platform for ease of use of user as well as accessibility. The DHT11 sensor is connected to the D4 pin of the board. Now, based on the percentage given out by the soil moisture sensor, a relay is run, which is connected to the D7 pin of the board, which is further connected to a mini pump to water the plants. The relay is trigger at 30% moisture level and continues to water the plants until 70% moisture level is reached, thus the plants always stay in a kind of goldilocks zone of neither too dry nor too wet. All this info is presented to the user on the blynk IOT dashboard via the internet, so it doesn’t matter how far away you are, your plants always stay healthy. The user is free to tinker with the time interval on the dashboard to suit their needs. Lastly, all of the components are powered by the 3.3V pins of the microcontroller. The code used in this project excluding header files for Blynk is given below:-

Code

 

Automated Irrigation System

Arduino

This project uses Blynk Edgent example file for getting set up. I have only given the code to be installed in the esp8266 board, you will have to go to Blynk IOT webpage and set up your own variables first and then the dashboard for this to work. It isn't hard, as I have named the variables here similarly, just create integer virtual pins with the same numbers as given here, or you can tinker with it yourself to suit your need. The code used in this project excluding header files for Blynk is given below:-

CODE
// Blynk IOT Macros
#define BLYNK_TEMPLATE_ID "TMPL6eWqbpU3"
#define BLYNK_DEVICE_NAME "Moisture Sensor"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#include "BlynkEdgent.h"
#include "DHT.h"
#define DHTTYPE DHT11
DHT dht(2,DHT11);

// Global Variables
int sensorValue;    
int limit = 300;
int time_interval;
int senseNow;
int warning;
int autoMode;
int hour = 3600000;
unsigned long time_now;
unsigned long time_duration = 0;
unsigned long time_active = 0;
// Syncing variables between Blynk and Device
BLYNK_WRITE(V1)
{
  time_interval = param.asInt();
  Serial.print("interval = ");
  Serial.println(time_interval);
}
BLYNK_WRITE(V2)
{
  senseNow = param.asInt();
  Serial.print("senseNow = ");
  Serial.println(senseNow);
}
BLYNK_WRITE(V3)
{
  autoMode = param.asInt();
  Serial.print("autoMode = ");
  Serial.println(autoMode);
}
// Setup
void setup()
{
  Serial.begin(115200);
  delay(100);
  pinMode(13,OUTPUT);
  dht.begin();
  BlynkEdgent.begin();
  time_interval=4;
  senseNow=0;
  warning=0;
  autoMode=0;
}
// Loop
void loop() 
{ 
  time_now = millis();
  BlynkEdgent.run();
  if(time_now-time_active>=2000)
  {
    time_active = time_now;
    if(senseNow||warning) readSensor();
  }
  if(time_now-time_duration>=hour*time_interval)
  {
    time_duration = time_now;
    readSensor();
  }
}
// Main Function
void readSensor()
{
  sensorValue=analogRead(A0);
  Blynk.virtualWrite(V5,dht.readTemperature());
  Blynk.virtualWrite(V6,dht.readHumidity());
  int i=map(sensorValue,limit,650,100,0); // Mapping analog values to a percentage
  if(i<0) i=0;
  else if(i>100) i=100;
  Serial.println(i);
  Blynk.virtualWrite(V0,i); // Syncing variables between Device and Blynk
  if(autoMode)
  {
    if(i<30)
    {
      Blynk.logEvent("low_moisture"); // Warning
      warning=1;
    }
    if(warning) pump(i);
  }
}

void pump(int x)
{
  if(x>70)
  {
    digitalWrite(13,LOW);
    warning=0;
  }
  else
  {
    digitalWrite(13,HIGH);
  }
}

The article was first published in hackster, July 5, 2022

cr: https://www.hackster.io/nishasi/automated-gardening-with-blynk-iot-86da0d

author: nishasi

License
All Rights
Reserved
licensBg
0