Sumit Kumar
Published © GPL3+

Crop production booster with farm safety

Get real-time crop rates, smart monitoring of your farm using Particle Integrations. Boost your crop production with full control.

IntermediateFull instructions provided23 hours203
Crop production booster with farm safety

Things used in this project

Hardware components

I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
I2C_LCD is an easy-to-use display module, It can make display easier. Using it can reduce the difficulty of make, so that makers can focus on the core of the work.
×1
Argon
Particle Argon
The Argon is a powerful Wi-Fi enabled development board that can act as either a standalone Wi-Fi endpoint or Wi-Fi enabled gateway for Particle Mesh networks. It is based on the Nordic nRF52840 and has built-in battery charging circuitry so it’s easy to connect a Li-Po and deploy your local network in minutes. The Argon is great for connecting existing projects to the Particle Device Cloud or as a gateway to connect an entire group of local endpoints.
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed). Its fairly simple to use, but requires careful timing to grab data.
×1
Flame Sensor
A flame sensor "senses" a weak DC signal from the AC power sent to the ignitor which via the phenomenon of flame rectification in which the polarity of power sent through a flame is rectified to DC, flame is a poor conductor so the signal is mere micro amps .3 to .5.
×1
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
The soil moisture sensor consists of two probes which are used to measure the volumetric content of water. The two probes allow the current to pass through the soil and then it gets the resistance value to measure the moisture value. When there is more water, the soil will conduct more electricity which means that there will be less resistance. Therefore, the moisture level will be higher. Dry soil conducts electricity poorly, so when there will be less water, then the soil will conduct less electricity which means that there will be more resistance. Therefore, the moisture level will be lower.
×1
Battery, 3.7 V
Battery, 3.7 V
×1
Photodiode, 45 °
Photodiode, 45 °
×1
Rocker Switch, VISI-ROCKER
Rocker Switch, VISI-ROCKER
×1
Solar cell
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Desktop IDE (Dev) Particle Dev is a desktop application that allows you to work with local copies of your firmware files. However, internet access is required as the files are pushed to the Particle Device Cloud for compilation and returns a binary.
Thunkable
It uses a graphical user interface (GUI) very similar to the programming languages Scratch and the StarLogo TNG user interface, which allows users to drag and drop visual objects to create an application that can run on mobile devices.
Firebase
Google Firebase
Firebase Realtime database is a cloud hosted database that supports multiple platforms Android, iOS and Web. All the data is stored in JSON format and any changes in data, reflects immediately by performing sync across all the platforms & devices. This allows us to build more flexible realtime apps easily with minimal effort.
Google Sheets
Google Sheets
Google Sheets is a spreadsheet program included as part of a free, web-based software office suite offered by Google within its Google Drive service. The app allows users to create and edit files online while collaborating with other users in real-time.
ThingSpeak API
ThingSpeak API
ThingSpeak is an open-source Internet of Things application and API to store and retrieve data from things using the HTTP protocol over the Internet or via a Local Area Network.

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)
Plier, Long Nose
Plier, Long Nose
Tape, Double Sided
Tape, Double Sided
Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter

Story

Read more

Schematics

Data flow chart

Wirings

Solar cell circuit

Code

Smart Farm With Farmers health monitor and instant notification

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal_I2C_Spark.h>
#include <SparkJson.h>
#include <ThingSpeak.h>
#include "Adafruit_DHT.h"
#include "Particle.h"

#define DHTPIN 2            // what pin we're connected to
#define DHTTYPE DHT11		// DHT 11 
#define MOISTURE_PIN A2
#define FIRE_PIN D5
#define LDR_PIN A4

LiquidCrystal_I2C *lcd;

DHT dht(DHTPIN, DHTTYPE);
TCPClient client;

// forward declarations
void publishData();
void read_Fire();
void getDataHandler(const char *topic, const char *data);
void myGoogleSheetsHandler(const char *event, const char *data);

const unsigned long myChannelNumber = 824757 ;
const char *myWriteAPIKey = "4TIQ6CSI2RODFI1C";
const char *PUBLISH_EVENT_NAME = "Firebase_put";
const char *CHECK_EVENT_NAME = "Firebase_Read";

float temperature = 0.0;
float humidity = 0.0;
float heat_Index = 0.0;
float dew_Point = 0.0;
float light = 0.0;
float moisture = 0.0;
float voltage = 0.0;
float moisture_threshold = 0;
float light_threshold = 0;
String message="";
int messageCode = 0;
int alert=0;

unsigned long interval = 60000;
unsigned long previousMillis = 0;
unsigned long previousMillis2 = 0;
volatile int state = 0 ;

void setup() 
{
	Serial.begin(9600);

    lcd = new LiquidCrystal_I2C(0x27, 16, 2);
    lcd->init();
    lcd->backlight();
    lcd->clear();
    lcd->print("*** Welcome ***");
  	Particle.subscribe("hook-response/Firebase_Read", getDataHandler, MY_DEVICES);
  	Particle.subscribe("hook-response/CropRates", myGoogleSheetsHandler, MY_DEVICES);
	Serial.println("DHT11 test!");
    ThingSpeak.begin(client);
	dht.begin();
	
    pinMode(MOISTURE_PIN, INPUT);
    pinMode(D7,OUTPUT);
    pinMode(FIRE_PIN, INPUT);
    pinMode(LDR_PIN, INPUT);
    
    attachInterrupt(FIRE_PIN, read_Fire, CHANGE);        // an interrupt to trigger fire state change 
    
    readDht();                                       
    read_Moisture();
    read_Light();
    checkCritical();
    previousMillis = millis();
    previousMillis2 = millis();
   
}

void loop() 
{
    Serial.println("Not the time yet"); //
 
    if(millis() - previousMillis >= interval)        // we do not want climate data every second, I am updating values after every minute
    {
        Serial.println("This is the time");
        writeThingSpeak();
        publishData();
        readDht();                                       
       read_Moisture();
       read_Light();
       previousMillis = millis();
    }
    if (millis() - previousMillis2 >= 600000) //updating values every hour
    {
    lcd->clear();
		previousMillis2 = millis();
		Particle.publish(CHECK_EVENT_NAME, "", PRIVATE);
		Particle.publish("CropRates","", PRIVATE);
		checkCritical();
		lcd->setCursor(0,0);
		lcd->print(message);
    }
}

void getDataHandler(const char *topic, const char *data) 
{
	StaticJsonBuffer<255> jsonBuffer;
	char *mutableCopy = strdup(data);
	JsonObject& root = jsonBuffer.parseObject(mutableCopy);
	free(mutableCopy);
	// Because of the way the webhooks work, all data, including numbers, are represented as
	// strings, so we need to convert them back to their native data type here
	 moisture_threshold = atof(root["lightTh"]);
	 light_threshold = atof(root["waterTh"]);
	 alert= atoi(root["alert"]); //check whether there is an alert from mobile app or not 1 if true else 0
	Serial.printlnf("light=%.2f water=%.2f alert=%d", light_threshold,moisture_threshold, alert);
}

void writeThingSpeak()
{
    int volt_percent=map((int)voltage,0,5,0,100);
    
    ThingSpeak.setField(1, (float)temperature);
    ThingSpeak.setField(2, (float)humidity);
    ThingSpeak.setField(3, (float)dew_Point);
    ThingSpeak.setField(4, (float)heat_Index);
    ThingSpeak.setField(5, (float)light);
    ThingSpeak.setField(6, (float)moisture);
    ThingSpeak.setField(7, (float)volt_percent);
    
    // Write the fields that you've set all at once.
    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    Serial.println("Thingspeak");
    // Give time for the message to reach ThingSpeak
    delay(3000);
}


void readDht()
{
    // Wait a few seconds between measurements.
	delay(2000);
   // Reading temperature or humidity takes about 250 milliseconds!
   // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
	float h = dht.getHumidity();
    float t = dht.getTempCelcius();                                  // Read temperature as Celsius
	float f = dht.getTempFarenheit();                                // Read temperature as Farenheit
  
	if (isnan(h) || isnan(t) || isnan(f))                            // Check if any reads failed and exit early (to try again).
	{
		Serial.println("Failed to read from DHT sensor!");
		return;
	}

	float hi = dht.getHeatIndex();                                   // Compute heat index
	float dp = dht.getDewPoint();
	float k = dht.getTempKelvin();
	
	humidity = h;
	temperature = t;
	dew_Point = dp;
	heat_Index =hi;
// just to check values coming are correct or not
	Serial.print("Humid: "); 
	Serial.print(h);
	Serial.print("% - ");
	Serial.print("Temp: "); 
	Serial.print(t);
	Serial.print("*C ");
	Serial.print(f);
	Serial.print("*F ");
	Serial.print(k);
	Serial.print("*K - ");
	Serial.print("DewP: ");
	Serial.print(dp);
	Serial.print("*C - ");
	Serial.print("HeatI: ");
	Serial.print(hi);
	Serial.println("*C");
	Serial.println(Time.timeStr());

}

void read_Light()
{
    int lightTemp = analogRead(MOISTURE_PIN);
    Serial.println(lightTemp);
    light = (100 - ((lightTemp/4095)*100));
    Serial.print("light % ");
    Serial.print(light);
    delay(1000);
}

void read_Moisture()
{
  int moisture_analog = analogRead(MOISTURE_PIN); // read capacitive sensor
  Serial.println(moisture_analog);
  moisture = (100 - ( (moisture_analog/4095.00) * 100 ) );
    Serial.print("moisture % ");
    Serial.print(moisture);
    delay(1000);
}


void publishData() 
{
	char buf[256];
	snprintf(buf, sizeof(buf), "{\"temp\":%.2f,\"humid\":%.2f,\"dewpoint\":%.2f,\"heatindex\":%.2f,\"moist\":%.2f,\"volt\":%.2f,\"light\":%.2f,\"message\":%d}",
	temperature, humidity, dew_Point, heat_Index, moisture, voltage, light, messageCode);
	Serial.printlnf("publishing %s", buf);
	Particle.publish(PUBLISH_EVENT_NAME, buf, PRIVATE);
	delay(3000);
}

void read_Fire()
{
  state = digitalRead(FIRE_PIN);
  digitalWrite(D7, state);
}

void checkCritical()
{ // set your own custom message to keep a check on farmer's health owing to climatic conditions or track farm health.
    if(alert==1)
    message = "emergency";
    else if(light_threshold!=0&&moisture_threshold!=0)
    {
        if(light<light_threshold||moisture<moisture_threshold)
        {
             if(moisture<moisture_threshold)
             {
             message="Water LOW";
             messageCode=1;
             }
             else if(light<light_threshold)
             {
             message="Light LOW";
             messageCode=2;
             }
             else
             {
             message="Water Light LOW";
             messageCode=3;
             }
        }
       
    }
    else if(state==1 || state==HIGH)
    {
        message="Alert Fire";
        messageCode=4;
    }
    else if(heat_Index>27&&heat_Index<32)
    {
    message="! Heat Cramps";
    messageCode=5;
    }
    else if(heat_Index>32&&heat_Index<41)
    {
    message="! Heat Stroke";
    messageCode=6;
    }
    else if(heat_Index>41||heat_Index>54)
    {
    message="!Extreme danger";
    messageCode=7;
    }
    else if(dew_Point<10)
    {
    message="Skin irritation";
    messageCode=8;
    }
      else if(dew_Point>26)
   {
   message="deadly for asthma patients";
   messagCode=9;
   }
    else if(voltage<1)
    {
    message="battery low";
    messageCode=9;
    }
    else
    {
        message="Normal";
        messageCode=0;
    }
}
void myGoogleSheetsHandler(const char *event, const char *data) {
  // Handle the integration response and print the data to debug console 
   Serial.println( String(data) );
    StaticJsonBuffer<256> jsonBuffer;
	char *mutableCopy = strdup(data);
	JsonObject& root = jsonBuffer.parseObject(mutableCopy);
	free(mutableCopy);
	Serial.printlnf("data: %s", data);
}

void battery()
{
    voltage = analogRead(BATT) * 0.0011224;
    voltage = map(voltage,0.0,5.0,0.0,100.0);
}

Smart Farm App and codes

You can download the apk, stickers or code from here

Credits

Sumit Kumar

Sumit Kumar

32 projects • 97 followers
19 y/o. My daily routine involves dealing with electronics, code, distributed storage and cloud APIs.

Comments