#define BLYNK_TEMPLATE_ID "TMPL3ZO-d0NJd"
#define BLYNK_TEMPLATE_NAME "smart waste management system"
#define BLYNK_AUTH_TOKEN "F24Wqbgr3yFpcDQMSeS5Ae_FZlSVxblI"
#define TRIGGER_PIN_1 12
#define ECHO_PIN_1 14
#define TRIGGER_PIN_2 16
#define ECHO_PIN_2 17
#define LED_PIN_1_ON 2
#define LED_PIN_1_OFF 0
#define LED_PIN_2_ON 4
#define LED_PIN_2_OFF 5
#define BUZZER_PIN_1 32
#define BUZZER_PIN_2 33
#include <Ultrasonic.h>
#include <BlynkSimpleEsp32.h>
Ultrasonic ultrasonic1(TRIGGER_PIN_1, ECHO_PIN_1);
Ultrasonic ultrasonic2(TRIGGER_PIN_2, ECHO_PIN_2);
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
char auth[] = "F24Wqbgr3yFpcDQMSeS5Ae_FZlSVxblI";
void setup() {
Serial.begin(9600);
pinMode(LED_PIN_1_ON, OUTPUT);
pinMode(LED_PIN_1_OFF, OUTPUT);
pinMode(LED_PIN_2_ON, OUTPUT);
pinMode(LED_PIN_2_OFF, OUTPUT);
pinMode(BUZZER_PIN_1, OUTPUT);
pinMode(BUZZER_PIN_2, OUTPUT);
Blynk.begin(auth, ssid, pass);
}
void send_blynk(int distance1, int distance2) {
if (distance1 < 50) {
Blynk.logEvent("bin1_full", "Bin 1 is full! Please empty it.");
Blynk.virtualWrite(V1, 1);
} else {
Blynk.virtualWrite(V1, 0);
}
if (distance2 < 50) {
Blynk.logEvent("bin2_full", "Bin 2 is full! Please empty it.");
Blynk.virtualWrite(V2, 1);
} else {
Blynk.virtualWrite(V2, 0);
}
}
void loop() {
Blynk.run();
long distance1 = measureDistance(TRIGGER_PIN_1, ECHO_PIN_1);
long distance2 = measureDistance(TRIGGER_PIN_2, ECHO_PIN_2);
long fillLevel1 = 400 - distance1; // Assuming 400 cm as the max depth of the bin
long fillLevel2 = 400 - distance2; // Adjust this value according to your bin's height
Serial.print("Bin1 fill level: ");
Serial.print(fillLevel1);
Serial.print(" cm | Bin2 fill level: ");
Serial.print(fillLevel2);
Serial.println(" cm");
Blynk.virtualWrite(V1, fillLevel1); // Send fill level 1 to Blynk app
Blynk.virtualWrite(V2, fillLevel2); // Send fill level 2 to Blynk app
// Control LED 1 and buzzer 1 based on distance from sensor 1
if (distance1 < 50) {
Serial.println("Bin1 is full!!. Don't put waste on it!!");
digitalWrite(LED_PIN_1_ON, HIGH); // Turn on LED 1
digitalWrite(LED_PIN_1_OFF, LOW); // Turn off LED 1
tone(BUZZER_PIN_1, 1000); // Turn on buzzer 1
} else {
digitalWrite(LED_PIN_1_ON, LOW); // Turn off LED 1
digitalWrite(LED_PIN_1_OFF, HIGH); // Turn on LED 1
noTone(BUZZER_PIN_1); // Turn off buzzer 1
}
// Control LED 2 and buzzer 2 based on distance from sensor 2
if (distance2 < 50) {
Serial.println("Bin2 is full!!. Don't put waste on it!!");
digitalWrite(LED_PIN_2_ON, HIGH); // Turn on LED 2
digitalWrite(LED_PIN_2_OFF, LOW); // Turn off LED 2
tone(BUZZER_PIN_2, 1000); // Turn on buzzer 2
} else {
digitalWrite(LED_PIN_2_ON, LOW); // Turn off LED 2
digitalWrite(LED_PIN_2_OFF, HIGH); // Turn on LED 2
noTone(BUZZER_PIN_2); // Turn off buzzer 2
}
send_blynk(distance1, distance2);
delay(1000); // Delay for stability
}
long measureDistance(int tp, int ep) {
digitalWrite(tp, LOW);
delayMicroseconds(2);
digitalWrite(tp, HIGH);
delayMicroseconds(10);
digitalWrite(tp, LOW);
long duration = pulseIn(ep, HIGH);
long distance = duration * 0.034 / 2;
return distance;
}