ESP32-Based Smart Waste Segregation System with Ultrasonic Sensing and Soil Moisture Detection
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to interface with various sensors and actuators using an ESP32 microcontroller. The primary components include an ESP32, a servomotor (SG90), an HC-SR04 ultrasonic sensor, a load cell, an HX711 weighing sensor module, a buzzer, a soil moisture module, and a YL-69 soil moisture probe. The ESP32 reads data from the sensors, controls the servomotor based on sensor inputs, and provides feedback through a buzzer. The circuit is likely used for applications such as automated plant watering systems, weight measurement, and distance sensing.
Component List
- ESP32 (30 pin): A microcontroller with WiFi and Bluetooth capabilities, featuring a variety of digital and analog pins for interfacing with sensors and actuators.
- Servomotor SG90: A small and lightweight servo motor used for precise control of mechanical movement.
- HC-SR04 Ultrasonic Sensor: A sensor that measures distance by emitting ultrasonic waves and measuring the time taken for the echo to return.
- Load Cell - Red/white/black/green: A transducer that converts force into an electrical signal, used for weight measurement.
- YL-69 Sonda: A soil moisture probe that measures the moisture content in the soil.
- HX711 Weighing Sensor Module: An ADC converter that allows the load cell to interface with the microcontroller, providing weight measurements.
- Buzzer: An electronic component that emits sound when an electrical signal is applied.
- Soil Moisture Module: A module that measures the moisture content in the soil, providing both analog and digital outputs.
Wiring Details
ESP32 (30 pin)
D34connected to Soil Moisture Module (Analog)D32connected to HX711 Weighing Sensor Module (DO/RX)D33connected to HX711 Weighing Sensor Module (CK/TX)D27connected to Buzzer (POSITIVE)D14connected to Servomotor SG90 (SIG)D12connected to HC-SR04 Ultrasonic Sensor (TRIG)D13connected to HC-SR04 Ultrasonic Sensor (ECHO)GNDconnected to Buzzer (NEGATIVE), Soil Moisture Module (Ground), HX711 Weighing Sensor Module (GND), HC-SR04 Ultrasonic Sensor (GND), Servomotor SG90 (GND)3V3connected to HC-SR04 Ultrasonic Sensor (VCC), Soil Moisture Module (VCC), Servomotor SG90 (VCC), HX711 Weighing Sensor Module (VCC)D2connected to Soil Moisture Module (Digital)
Servomotor SG90
SIGconnected to ESP32 (D14)VCCconnected to ESP32 (3V3)GNDconnected to ESP32 (GND)
HC-SR04 Ultrasonic Sensor
VCCconnected to ESP32 (3V3)TRIGconnected to ESP32 (D12)ECHOconnected to ESP32 (D13)GNDconnected to ESP32 (GND)
Load Cell - Red/white/black/green
E+connected to HX711 Weighing Sensor Module (E+)A-connected to HX711 Weighing Sensor Module (A-)E-connected to HX711 Weighing Sensor Module (E-)A+connected to HX711 Weighing Sensor Module (A+)
YL-69 Sonda
+connected to Soil Moisture Module (positive)-connected to Soil Moisture Module (negative)
HX711 Weighing Sensor Module
DO/RXconnected to ESP32 (D32)CK/TXconnected to ESP32 (D33)GNDconnected to ESP32 (GND)VCCconnected to ESP32 (3V3)E+,A-,E-,A+connected to Load Cell
Buzzer
POSITIVEconnected to ESP32 (D27)NEGATIVEconnected to ESP32 (GND)
Soil Moisture Module
Analogconnected to ESP32 (D34)Digitalconnected to ESP32 (D2)Groundconnected to ESP32 (GND)VCCconnected to ESP32 (3V3)positiveconnected to YL-69 Sonda (+)negativeconnected to YL-69 Sonda (-)
Documented Code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <HX711.h>
#include <Servo.h>
#define TRIG_PIN 12
#define ECHO_PIN 13
#define SOIL_MOISTURE_PIN 34
#define SERVO_PIN 14
#define LOADCELL1_DOUT_PIN 32
#define LOADCELL1_SCK_PIN 33
#define BUZZER_PIN 27
LiquidCrystal_I2C lcd(0x27, 16, 2); // Adjust address if needed
HX711 loadCell1;
Servo servo;
float wetWeight = 0;
float dryWeight = 0;
void setup() {
Serial.begin(115200);
lcd.begin();
lcd.backlight();
loadCell1.begin(LOADCELL1_DOUT_PIN, LOADCELL1_SCK_PIN);
loadCell1.set_scale();
loadCell1.tare();
servo.attach(SERVO_PIN);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(SOIL_MOISTURE_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT); // Set buzzer pin as output
}
void beep(int type)
{
if (type == 1)
{
digitalWrite(BUZZER_PIN, HIGH);
delay(250);
digitalWrite(BUZZER_PIN, LOW);
delay(250);
digitalWrite(BUZZER_PIN, HIGH);
delay(250);
digitalWrite(BUZZER_PIN, LOW);
delay(250);
}else if (type == 2)
{
digitalWrite(BUZZER_PIN, HIGH);
delay(500);
digitalWrite(BUZZER_PIN, LOW);
delay(500);
}
}
void loop() {
// Read ultrasonic sensor
long duration, distance;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH);
distance = (duration * 0.034) / 2;
// Read soil moisture sensor
int soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);
// Read load cells
wetWeight = loadCell1.get_units(10);
dryWeight = loadCell1.get_units(10);
// Display weights
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Wet: ");
lcd.print(wetWeight);
lcd.print(" g");
lcd.setCursor(0, 1);
lcd.print("Dry: ");
lcd.print(dryWeight);
lcd.print(" g");
// Waste segregation logic
if (soilMoistureValue < 500) { // Adjust threshold as needed
servo.write(0); // Open for dry waste
delay(1000);
beep(1);
servo.write(90); // Close
} else {
servo.write(90); // Open for wet waste
delay(1000);
beep(2);
servo.write(0); // Close
}
delay(2000); // Adjust as needed
}
This code is designed to run on the ESP32 microcontroller. It initializes the LCD display, load cell, servo, and sets up the pins for the ultrasonic sensor, soil moisture sensor, and buzzer. The loop function reads the distance from the ultrasonic sensor, the soil moisture level, and the weight from the load cell. Based on the soil moisture value, it controls the servomotor to segregate waste and provides an audible alert using the buzzer.