ESP32-Based Smart Lettuce Crop Yield Monitoring System with Multiple Sensors
View and Edit Project In Cirkit Designer
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
Modulo Sensor PH
- Pins: -, +, A, SON
- Description: Measures the pH level of the soil.
HC-SR04 Ultrasonic Distance Sensor (Wokwi Compatible)
- Pins: VCC, TRIG, ECHO, GND
- Description: Measures the distance to an object using ultrasonic waves.
NPK Soil Sensor (mini)
- Pins: VCC, GND, A, B
- Description: Measures the nitrogen, phosphorus, and potassium levels in the soil.
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.
DFRobot EC Sensor
- Pins: -, +, A
- Description: Measures the electrical conductivity of the soil.
DS18B20
- Pins: signal, GND, vcc
- Description: Measures the temperature of the soil.
1 Channel 5V Relay Module
- Pins: VCC+, VCC- (GND), IN, N.O., COM, N.C.
- Description: Controls the water pump and solenoid valve.
Plastic Solenoid Valve
- Pins: pin1, pin2
- Description: Controls the flow of water.
TIP120 Hi-Current Darlington Transistor
- Pins: BASE, COLLECTOR, EMITTER
- Description: Amplifies current to drive the solenoid valve.
Resistor
- Pins: pin1, pin2
- Description: Limits current in the circuit.
- Properties: 1000 Ohms
1N4007 Rectifier Diode
- Pins: Cathode, Anode
- Description: Protects the circuit from reverse voltage.
Carbon Dioxide Sensor
- Pins: A, VCC, GND
- Description: Measures the CO2 level in the environment.
boost converter MT3608
- Pins: OUTPUT +, OUTPUT -, INPUT +, INPUT -
- Description: Boosts the input voltage to a higher output voltage.
Water Pump
- Pins: VCC, GND
- Description: Pumps water to the plants.
DHT22
- Pins: GND, VCC, DAT
- Description: Measures temperature and humidity.
Wiring Details
Modulo Sensor PH
- A to ESP32 D25
- - to GND
- + to VCC
HC-SR04 Ultrasonic Distance Sensor (Wokwi Compatible)
- TRIG to ESP32 D14
- ECHO to ESP32 D12
- GND to GND
- VCC to VCC
NPK Soil Sensor (mini)
- A to ESP32 D13
- GND to GND
- VCC to VCC
ESP32 (30 pin)
- D34 to DHT22 DAT
- D35 to DS18B20 signal
- D32 to DFRobot EC Sensor A
- D33 to Carbon Dioxide Sensor A
- D25 to Modulo Sensor PH A
- D14 to HC-SR04 TRIG
- D12 to HC-SR04 ECHO
- D13 to NPK Soil Sensor A
- GND to GND
- Vin to VCC
- D2 to Resistor pin2
- D15 to Relay Module IN
DFRobot EC Sensor
- A to ESP32 D32
- - to GND
- + to VCC
DS18B20
- signal to ESP32 D35
- GND to GND
- vcc to VCC
1 Channel 5V Relay Module
- IN to ESP32 D15
- VCC- (GND) to GND
- VCC+ to VCC
- COM to Diode Cathode
- N.C. to Water Pump VCC
Plastic Solenoid Valve
- pin1 to Diode Anode
- pin2 to Diode Cathode
TIP120 Hi-Current Darlington Transistor
- BASE to Resistor pin1
- COLLECTOR to Diode Anode
- EMITTER to GND
Resistor
- pin1 to TIP120 BASE
- pin2 to ESP32 D2
1N4007 Rectifier Diode
- Cathode to Relay Module COM
- Anode to TIP120 COLLECTOR
Carbon Dioxide Sensor
- A to ESP32 D33
- GND to GND
- VCC to VCC
boost converter MT3608
- INPUT + to VCC
- INPUT - to GND
- OUTPUT + to Solenoid Valve pin2
- OUTPUT - to Solenoid Valve pin1
Water Pump
- VCC to Relay Module N.C.
- GND to TIP120 COLLECTOR
DHT22
- DAT to ESP32 D34
- GND to GND
- VCC to VCC
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