Table of Contents

CROP HEALTH ADVISER

To develop a Crop Health Advisor system that monitors critical soil and environmental parameters using various sensors and transmits the data wirelessly to a cloud platform for analysis and advisory. This system aims to help farmers maintain optimal conditions for crop growth.

Agriculture is a critical sector that requires constant monitoring and management to ensure optimal crop health and yield. Traditional methods of monitoring crop conditions are labor-intensive and often lack real-time data, leading to inefficiencies and potential crop loss. This project, the Crop Health Advisor Project, leverages modern technology to automate the monitoring process and provide real-time data to farmers, thereby enhancing agricultural productivity and sustainability.

Component Required:

  • NodeMCU (ESP8266): Microcontroller for processing and wireless communication.
  • pH Sensor: For measuring soil pH levels.
  • Soil Moisture Sensor: For detecting soil moisture content.
  • Rainfall Sensor: For detecting rainfall presence.
  • DHT22: For measuring environmental humidity and temperature.
  • LDR: For measuring light intensity.
  • Breadboard and Connecting Wires: For prototyping and connections.
  • Power Supply: Batteries and solar panels for sustainable power.

Components and Functionality:

pH Sensor
  • Purpose: Measures the pH value of the soil to determine its acidity or alkalinity.
  • Operation: The pH sensor provides real-time data on the soil’s pH level.
Soil Moisture Sensor
  • Purpose: Measures the moisture content of the soil.
  • Operation: The sensor detects the water content in the soil, ensuring optimal watering.
Rainfall Sensor
  • Purpose: Detects the presence and intensity of rainfall.
  • Operation: Indicates whether it is raining, helping in irrigation planning.
Humidity and Temperature Sensor (DHT22)
  • Purpose: Measures environmental humidity and temperature.
  • Operation: Provides real-time data on air humidity and temperature, crucial for crop health.
Light Dependent Resistor (LDR)
  • Purpose: Measures the light intensity.
  • Operation: Helps determine the amount of light available to the crops.
NodeMCU ESP32
  • Purpose: Collects data from all sensors and transmits it to a cloud platform.
  • Operation: Handles data acquisition and wireless communication.

Circuit Diagram is given below:

Implementation Notes

  • WiFi Connection: Ensure your WiFi credentials are correct and that the NodeMCU is within range of the WiFi network.
  • Sensor Calibration: Calibrate the sensors according to the manufacturer’s instructions to get accurate readings.
  • Server Setup: Replace http://your-server.com/update with the actual URL of your server or cloud platform where the data will be sent.
  • Power Supply: Ensure that the NodeMCU and sensors are supplied with appropriate power, typically 3.3V for the NodeMCU and most sensors.

The code is given below:

#include <ESP8266WiFi.h>
#include <DHT.h>
#include <Wire.h>
#include <ESP8266HTTPClient.h>

// WiFi credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

// DHT22 settings
#define DHTPIN D4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

// Pin definitions
#define PH_PIN ADC2_4
#define SOIL_MOISTURE_PIN ADC2_5
#define RAIN_SENSOR_PIN D1
#define LDR_PIN ADC2_3

// Server URL (replace with your server URL)
const char* serverUrl = "http://your-server.com/update";

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
  
  dht.begin();
}

void loop() {
  // Read pH value
  int phValue = analogRead(PH_PIN);
  
  // Read soil moisture value
  int soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);
  
  // Read rain sensor value
  int rainValue = digitalRead(RAIN_SENSOR_PIN);
  
  // Read humidity and temperature values
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();
  
  // Read light intensity value
  int ldrValue = analogRead(LDR_PIN);
  
  // Print sensor values to Serial Monitor
  Serial.print("pH Value: "); Serial.println(phValue);
  Serial.print("Soil Moisture Value: "); Serial.println(soilMoistureValue);
  Serial.print("Rain: "); Serial.println(rainValue);
  Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %");
  Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" *C");
  Serial.print("Light Intensity: "); Serial.println(ldrValue);

  // Prepare data for sending
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String postData = "ph=" + String(phValue) +
                      "&soilMoisture=" + String(soilMoistureValue) +
                      "&rain=" + String(rainValue) +
                      "&humidity=" + String(humidity) +
                      "&temperature=" + String(temperature) +
                      "&light=" + String(ldrValue);
    
    http.begin(serverUrl);
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    int httpResponseCode = http.POST(postData);
    if (httpResponseCode > 0) {
      String response = http.getString();
      Serial.println(httpResponseCode);
      Serial.println(response);
    } else {
      Serial.print("Error on sending POST: ");
      Serial.println(httpResponseCode);
    }
    http.end();
  }

  delay(60000); // Wait for a minute before the next reading
}

Application:

Real-time Monitoring: Provides real-time data on critical environmental and soil conditions.

Data Analysis: Enables data collection for trend analysis and informed decision-making.

Resource Optimization: Helps optimize water and nutrient usage based on soil and weather conditions.

Increased Crop Yield: Maintains optimal growing conditions, leading to healthier crops and potentially higher yields.

Scroll to Top