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

Arduino UNO Smart Waste Management System with Ultrasonic Sensors and RGB LED Indicators

View and Edit Project In Cirkit DesignerImage of Arduino UNO Smart Waste Management System with Ultrasonic Sensors and RGB LED Indicators

Circuit Documentation

Summary

This circuit is designed to monitor the fullness of a bin and detect garbage using ultrasonic sensors. It also measures soil moisture levels to differentiate between wet and dry waste. The system uses an RGB LED to indicate the bin's status and a servo motor to sort the waste based on moisture levels. The entire system is controlled by an Arduino UNO microcontroller.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. HC-SR04 Ultrasonic Sensor

    • Description: An ultrasonic distance sensor used for measuring distance.
    • Pins: VCC, TRIG, ECHO, GND
  3. HC-SR04 Ultrasonic Sensor

    • Description: An ultrasonic distance sensor used for measuring distance.
    • Pins: VCC, TRIG, ECHO, GND
  4. Servo

    • Description: A servo motor used for mechanical movement.
    • Pins: GND, VCC, PWM
  5. RGB LED (Wokwi compatible)

    • Description: An RGB LED used for indicating status with different colors.
    • Pins: R, COM, G, B
  6. Soil Moisture Module

    • Description: A sensor module used to measure soil moisture levels.
    • Pins: positive, negative, Analog, Digital, Ground, VCC
  7. Water Sensor

    • Description: A sensor used to detect the presence of water.
    • Pins: -, +

Wiring Details

Arduino UNO

HC-SR04 Ultrasonic Sensor

HC-SR04 Ultrasonic Sensor

Servo

RGB LED (Wokwi compatible)

Soil Moisture Module

Water Sensor

Documented Code

#include <Servo.h>

#define SOIL_MOISTURE_PIN A0
#define DRY_THRESHOLD 1000
#define GARBAGE_TRIG_PIN 10     
#define GARBAGE_ECHO_PIN 11     
#define FULLNESS_TRIG_PIN 12     
#define FULLNESS_ECHO_PIN 13    
#define SERVOPIN 9              
#define RED_PIN 3
#define GREEN_PIN 4            
#define BLUE_PIN 5              

Servo myServo;

void setup() {
  Serial.begin(9600);          // Initialize serial communication
  myServo.attach(SERVOPIN);    
  myServo.write(95);           
  pinMode(GARBAGE_TRIG_PIN, OUTPUT);
  pinMode(GARBAGE_ECHO_PIN, INPUT);
  pinMode(FULLNESS_TRIG_PIN, OUTPUT);
  pinMode(FULLNESS_ECHO_PIN, INPUT);
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}

long measureDistance(int trigPin, int echoPin) {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  return pulseIn(echoPin, HIGH) * 0.034 / 2;  // Convert time to distance
}

void setRGBColor(bool red, bool green, bool blue) {
  digitalWrite(RED_PIN, red ? HIGH : LOW);
  digitalWrite(GREEN_PIN, green ? HIGH : LOW);
  digitalWrite(BLUE_PIN, blue ? HIGH : LOW);
}

void loop() {
  // TODO Measure distance for garbage detection
  long garbageDistance = measureDistance(GARBAGE_TRIG_PIN, GARBAGE_ECHO_PIN);
  // Serial.print("Garbage Detection Distance: ");
  // Serial.print(garbageDistance);
  // Serial.println(" cm");

  // TODO Measure distance for fullness detection
  long fullnessDistance = measureDistance(FULLNESS_TRIG_PIN, FULLNESS_ECHO_PIN);
  Serial.print("Bin Fullness Distance: ");
  Serial.print(fullnessDistance);
  Serial.println(" cm");

  // TODO RGB LED based on fullness distance and print status
  if (fullnessDistance <= 5) {
    setRGBColor(true, false, false);     // Red - Full
    Serial.println("RGB Status: Red - Bin is Full");
  } else if (fullnessDistance <= 10) {
    setRGBColor(false, false, true);     // Blue - Almost Full
    Serial.println("RGB Status: Blue - Bin is Almost Full");
  } else {
    setRGBColor(false, true, false);     // Green - Space Available
    Serial.println("RGB Status: Green - Bin has Space");
  }

  // TODO Check if garbage is detected
  if (garbageDistance <= 20) {
    Serial.println("Garbage detected. Checking moisture level...");

    delay(2000);  // Wait 1 second for stability

    // TODO Read the soil moisture level
    int soilMoistureValue = analogRead(SOIL_MOISTURE_PIN);
    Serial.print("Soil Moisture Level: ");
    Serial.println(soilMoistureValue);

    // Control the servo based on moisture level and print servo action
    if (soilMoistureValue > DRY_THRESHOLD) {
      myServo.write(140);
      Serial.println("Dry waste detected. Servo turned to 50 degrees (right).");
    } else {
      myServo.write(20);
      Serial.println("Wet waste detected. Servo turned to 70 degrees (left).");
    }

    delay(2000);

    myServo.write(98);
    Serial.println("Servo returned to the original position (90 degrees).");
  }

  Serial.println("---------------------------------------------------");
  delay(1500);  // NEXT READING WAIT TIME
}

This code initializes the necessary components and continuously measures distances using the ultrasonic sensors. Based on the measured distances, it controls the RGB LED to indicate the bin's status and uses the servo motor to sort the waste based on the soil moisture level.