Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Smart Lettuce Crop Yield Monitoring System with Multiple Sensors

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Lettuce Crop Yield Monitoring System with Multiple Sensors

Lettuce Crop Yield Monitoring System

Summary

This project involves an ESP32 microcontroller interfaced with various sensors and actuators to monitor and control the environment for lettuce crop yield. The system reads data from pH, EC, NPK, CO2, temperature, humidity, and ultrasonic distance sensors. Based on the sensor readings, it controls a water pump and a solenoid valve to maintain optimal conditions for lettuce growth.

Component List

  1. Modulo Sensor PH

    • Pins: -, +, A, SON
    • Description: Measures the pH level of the soil.
  2. HC-SR04 Ultrasonic Distance Sensor (Wokwi Compatible)

    • Pins: VCC, TRIG, ECHO, GND
    • Description: Measures the distance to an object using ultrasonic waves.
  3. NPK Soil Sensor (mini)

    • Pins: VCC, GND, A, B
    • Description: Measures the nitrogen, phosphorus, and potassium levels in the soil.
  4. ESP32 (30 pin)

    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
    • Description: Microcontroller used to read sensor data and control actuators.
  5. DFRobot EC Sensor

    • Pins: -, +, A
    • Description: Measures the electrical conductivity of the soil.
  6. DS18B20

    • Pins: signal, GND, vcc
    • Description: Measures the temperature of the soil.
  7. 1 Channel 5V Relay Module

    • Pins: VCC+, VCC- (GND), IN, N.O., COM, N.C.
    • Description: Controls the water pump and solenoid valve.
  8. Plastic Solenoid Valve

    • Pins: pin1, pin2
    • Description: Controls the flow of water.
  9. TIP120 Hi-Current Darlington Transistor

    • Pins: BASE, COLLECTOR, EMITTER
    • Description: Amplifies current to drive the solenoid valve.
  10. Resistor

    • Pins: pin1, pin2
    • Description: Limits current in the circuit.
    • Properties: 1000 Ohms
  11. 1N4007 Rectifier Diode

    • Pins: Cathode, Anode
    • Description: Protects the circuit from reverse voltage.
  12. Carbon Dioxide Sensor

    • Pins: A, VCC, GND
    • Description: Measures the CO2 level in the environment.
  13. boost converter MT3608

    • Pins: OUTPUT +, OUTPUT -, INPUT +, INPUT -
    • Description: Boosts the input voltage to a higher output voltage.
  14. Water Pump

    • Pins: VCC, GND
    • Description: Pumps water to the plants.
  15. DHT22

    • Pins: GND, VCC, DAT
    • Description: Measures temperature and humidity.

Wiring Details

Modulo Sensor PH

HC-SR04 Ultrasonic Distance Sensor (Wokwi Compatible)

NPK Soil Sensor (mini)

ESP32 (30 pin)

DFRobot EC Sensor

DS18B20

1 Channel 5V Relay Module

Plastic Solenoid Valve

TIP120 Hi-Current Darlington Transistor

Resistor

1N4007 Rectifier Diode

Carbon Dioxide Sensor

boost converter MT3608

Water Pump

DHT22

Code Documentation

/*
 * Lettuce Crop Yield Monitoring
 * This Arduino sketch reads data from various sensors connected to an ESP32
 * and controls a water pump and solenoid valve based on sensor readings.
 * Sensors: pH, EC, NPK, CO2, Temperature, Humidity, Ultrasonic Distance
 * Actuators: Water Pump, Solenoid Valve
 */

#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define DHTPIN 34
#define DHTTYPE DHT22
#define ONE_WIRE_BUS 35

DHT dht(DHTPIN, DHTTYPE);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

const int phPin = 25;
const int ecPin = 32;
const int npkPin = 13;
const int co2Pin = 33;
const int trigPin = 14;
const int echoPin = 12;
const int relayPin = 15;
const int pumpPin = 2;

void setup() {
  Serial.begin(115200);
  dht.begin();
  sensors.begin();
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(relayPin, OUTPUT);
  pinMode(pumpPin, OUTPUT);
}

void loop() {
  float phValue = analogRead(phPin) * (3.3 / 4095.0);
  float ecValue = analogRead(ecPin) * (3.3 / 4095.0);
  float npkValue = analogRead(npkPin) * (3.3 / 4095.0);
  float co2Value = analogRead(co2Pin) * (3.3 / 4095.0);

  float h = dht.readHumidity();
  float t = dht.readTemperature();
  sensors.requestTemperatures();
  float soilTemp = sensors.getTempCByIndex(0);

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  long duration = pulseIn(echoPin, HIGH);
  float distance = duration * 0.034 / 2;

  Serial.print("pH: "); Serial.println(phValue);
  Serial.print("EC: "); Serial.println(ecValue);
  Serial.print("NPK: "); Serial.println(npkValue);
  Serial.print("CO2: "); Serial.println(co2Value);
  Serial.print("Humidity: "); Serial.println(h);
  Serial.print("Temperature: "); Serial.println(t);
  Serial.print("Soil Temp: "); Serial.println(soilTemp);
  Serial.print("Distance: "); Serial.println(distance);

  if (distance < 10) {
    digitalWrite(relayPin, HIGH);
    digitalWrite(p