Arduino UNO Smart Waste Management System with Ultrasonic Sensors and RGB LED Indicators
View and Edit Project In Cirkit Designer
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
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
HC-SR04 Ultrasonic Sensor
- Description: An ultrasonic distance sensor used for measuring distance.
- Pins: VCC, TRIG, ECHO, GND
HC-SR04 Ultrasonic Sensor
- Description: An ultrasonic distance sensor used for measuring distance.
- Pins: VCC, TRIG, ECHO, GND
Servo
- Description: A servo motor used for mechanical movement.
- Pins: GND, VCC, PWM
RGB LED (Wokwi compatible)
- Description: An RGB LED used for indicating status with different colors.
- Pins: R, COM, G, B
Soil Moisture Module
- Description: A sensor module used to measure soil moisture levels.
- Pins: positive, negative, Analog, Digital, Ground, VCC
Water Sensor
- Description: A sensor used to detect the presence of water.
- Pins: -, +
Wiring Details
Arduino UNO
5V connected to:
- VCC of HC-SR04 Ultrasonic Sensor
- VCC of Servo
- VCC of HC-SR04 Ultrasonic Sensor
- VCC of Soil Moisture Module
GND connected to:
- GND of HC-SR04 Ultrasonic Sensor
- COM of RGB LED (Wokwi compatible)
- GND of Servo
- GND of HC-SR04 Ultrasonic Sensor
- Ground of Soil Moisture Module
A0 connected to:
- Analog of Soil Moisture Module
D13 connected to:
- ECHO of HC-SR04 Ultrasonic Sensor
D12 connected to:
- TRIG of HC-SR04 Ultrasonic Sensor
D11 connected to:
- ECHO of HC-SR04 Ultrasonic Sensor
D10 connected to:
- TRIG of HC-SR04 Ultrasonic Sensor
D9 connected to:
- PWM of Servo
D5 connected to:
- B of RGB LED (Wokwi compatible)
D4 connected to:
- G of RGB LED (Wokwi compatible)
D3 connected to:
- R of RGB LED (Wokwi compatible)
HC-SR04 Ultrasonic Sensor
VCC connected to:
- 5V of Arduino UNO
GND connected to:
- GND of Arduino UNO
ECHO connected to:
- D13 of Arduino UNO
TRIG connected to:
- D12 of Arduino UNO
HC-SR04 Ultrasonic Sensor
VCC connected to:
- 5V of Arduino UNO
GND connected to:
- GND of Arduino UNO
ECHO connected to:
- D11 of Arduino UNO
TRIG connected to:
- D10 of Arduino UNO
Servo
VCC connected to:
- 5V of Arduino UNO
GND connected to:
- GND of Arduino UNO
PWM connected to:
- D9 of Arduino UNO
RGB LED (Wokwi compatible)
COM connected to:
- GND of Arduino UNO
B connected to:
- D5 of Arduino UNO
G connected to:
- D4 of Arduino UNO
R connected to:
- D3 of Arduino UNO
Soil Moisture Module
VCC connected to:
- 5V of Arduino UNO
Ground connected to:
- GND of Arduino UNO
Analog connected to:
- A0 of Arduino UNO
Water Sensor
+ connected to:
- positive of Soil Moisture Module
- connected to:
- negative of Soil Moisture Module
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.