Fully Automated Farm Management System
764 1
Muthu Arun

Fully Automated Farm Management System

I have used an ESP8266 and sensors like moisture and MQ2 gas sensor to automate a farm. Nowadays...

Description:-

I have used an ESP8266 and sensors like moisture and MQ2 gas sensor to automate a farm. Nowadays with the exponential growth of other industries the salary for labours have risen significantly. I built this system to be independantly monitor a farm register activities and admin/upload the collected data to the cloud and make decisions like turning on a pump to irrigate a certain field without any input from the user. The user can also manually control everything through a mobile app and view moisture level and air quality. It can reduce the dependance of the farmer on the labor. Every sector are having technological improvements so we need this improvement to happen in farming with this goal I have created my project. Many other features can be added by the user to further increase the productivity.

Project Used Hardware

Farm Management Hardware

ESP8266, MQ2 sensor, Buzzer, Leds, MOSFETs, Soil moisture sensor, Wires and breadboard.

Project Used Software

Arduino IDE, Blynk IOT platform.

Project Hardware Software Selection

I have used a ESP8266 because it have it built wifi and it have enough processing power for this project while maintaining low cost. The main motive of this hardware and software selection is to make the system more affordable. The software and cloud service used are not paid and its free so everyone can access it without paying extra. The sensors i have used are very reliable and power efficient. Arduino IDE is a user friendly programming software and has a huge varieties of libraries which make easy it easy to program microcontrollers.Blynk cloud platform is a popular free IOT based platform with easy to use libraries and example sketches which makes it the perfect choice.MOSFETs are the best coice for switching high power DC circuits.

Circuit Diagram

Farm Management Circuit Diagram

 

I have connected the D5 and D2 digitalpins to the gate of two MOSFETS. D5 is responsible for switching valve and D2 is for turning on and off the buzzer. The analogpin A0 reads the analog output of the soil moisture sensor.The D1 pin reads the digital output from the gas sensor. D0 pin is for led which indicates whether the ESP8266 board has connected to the cloud.

Code

   
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_DEVICE_NAME ""
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI
#include "BlynkEdgent.h"
int valve_state = 0;
int buzzer_state = 0;
int virtualpin = 0;
int moisture = 0;
int air_quality = 0;
int main_light_state = 0;
int moistpin = A0;
int gaspin = D1;
int buzzpin = D2;
int valvepin = D5;
int led_pin = D0;
int main_light = D6;
void setup()
{
  pinMode(moistpin,INPUT);
  pinMode(gaspin,INPUT);
  pinMode(valvepin,OUTPUT);
  pinMode(buzzpin,OUTPUT);
  pinMode(main_light,OUTPUT);
  pinMode(led_pin,OUTPUT);
  Serial.begin(9600);
  delay(100);
  BlynkEdgent.begin();
  digitalWrite(valvepin,LOW);
  digitalWrite(main_light,LOW);
  digitalWrite(buzzpin,LOW);  
}
BLYNK_WRITE(V5)
{
  main_light_state = param.asInt();
  digitalWrite(main_light,main_light_state);
}
BLYNK_WRITE(V0)
{
  valve_state = param.asInt()  
}
BLYNK_WRITE(V4)
{
  buzzer_state = param.asInt();
}
void loop() {
  digitalWrite(led_pin,LOW);
  delay(500);
  digitalWrite(led_pin,HIGH);
  delay(500);
  moisture = analogRead(moistpin);
  air_quality = digitalRead(gaspin);
  Blynk.virtualWrite(V1, moisture);
  Blynk.virtualWrite(V2, air_quality);
  if (moisture > 900 || valve_state == 1){
    digitalWrite(valvepin,HIGH);
    Blynk.virtualWrite(V0,1);    
    buzzer_state = 1;
  }
  else if (moisture < 900){
    digitalWrite(valvepin,LOW);
    Blynk.virtualWrite(V0,0);  
  }
  if( air_quality == 0)
  {
    buzzer_state = 1; 
  }
  else if (air_quality == 1 && moisture < 900)
  {
    buzzer_state = 0;
  }
  digitalWrite(buzzpin, buzzer_state);
  Blynk.virtualWrite(V4, buzzer_state);
  BlynkEdgent.run();
  delay(100);
}