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

ESP32-Based Smart Waste Segregation System with Ultrasonic Sensing and Soil Moisture Detection

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Waste Segregation System with Ultrasonic Sensing and Soil Moisture Detection

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

Wiring Details

ESP32 (30 pin)

Servomotor SG90

HC-SR04 Ultrasonic Sensor

Load Cell - Red/white/black/green

YL-69 Sonda

HX711 Weighing Sensor Module

Buzzer

Soil Moisture Module

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.