#define BLYNK_TEMPLATE_ID "TMPL3g-C2Rb1s"
#define BLYNK_TEMPLATE_NAME "SMART CAMPUS waste management system"
#define BLYNK_AUTH_TOKEN "3yKGFQ8KT-iOA8vI81tKuUwCuykEZlCv"
#define TRIGGER_PIN_1 12 // GPIO pin connected to the trigger pin of the first ultrasonic sensor
#define ECHO_PIN_1 14 // GPIO pin connected to the echo pin of the first ultrasonic sensor
#define TRIGGER_PIN_2 16 // GPIO pin connected to the trigger pin of the second ultrasonic sensor
#define ECHO_PIN_2 17 // GPIO pin connected to the echo pin of the second ultrasonic sensor
#define LED_PIN_1_ON 2 // GPIO pin connected to the first LED ON pin
#define LED_PIN_1_OFF 0 // GPIO pin connected to the first LED OFF pin
#define LED_PIN_2_ON 4 // GPIO pin connected to the second LED ON pin
#define LED_PIN_2_OFF 5 // GPIO pin connected to the second LED OFF pin
#define BUZZER_PIN_1 32 // GPIO pin connected to the first buzzer
#define BUZZER_PIN_2 33 // GPIO pin connected to the second buzzer
#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[] = "3yKGFQ8KT-iOA8vI81tKuUwCuykEZlCv";
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(LED_PIN_1_ON, OUTPUT); // Set LED 1 ON pin as an output
pinMode(LED_PIN_1_OFF, OUTPUT); // Set LED 1 OFF pin as an output
pinMode(LED_PIN_2_ON, OUTPUT); // Set LED 2 ON pin as an output
pinMode(LED_PIN_2_OFF, OUTPUT); // Set LED 2 OFF pin as an output
pinMode(BUZZER_PIN_1, OUTPUT); // Set buzzer 1 pin as an output
pinMode(BUZZER_PIN_2, OUTPUT); // Set buzzer 2 pin as an output
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
long distance1 = measureDistance(TRIGGER_PIN_1, ECHO_PIN_1);
long distance2 = measureDistance(TRIGGER_PIN_2, ECHO_PIN_2);
long a = 399 - distance1;
long b = 399 - distance2; // Read distance from the second ultrasonic sensor
Serial.print("Bin1 fill level: ");
Serial.print(a);
Serial.print(" cm | Bin2 fill level: ");
Serial.print(b);
Serial.println(" cm");
Blynk.virtualWrite(V1, a ); // Send distance 1 to Blynk app
Blynk.virtualWrite(V2, b);
// 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
digitalWrite(BUZZER_PIN_1, HIGH);
tone(BUZZER_PIN_1, 100);
} else {
digitalWrite(LED_PIN_1_ON, LOW); // Turn off LED 1
digitalWrite(LED_PIN_1_OFF, HIGH); // Turn on LED 1
digitalWrite(BUZZER_PIN_1, LOW); // 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
digitalWrite(BUZZER_PIN_2, HIGH); // Turn on buzzer 2
tone(BUZZER_PIN_2, 100);
} else {
digitalWrite(LED_PIN_2_ON, LOW); // Turn off LED 2
digitalWrite(LED_PIN_2_OFF, HIGH); // Turn on LED 2
digitalWrite(BUZZER_PIN_2, LOW); // Turn off buzzer 2
}
delay(1000); // Delay for stability
}
long measureDistance(int tp, int ep)
{
digitalWrite(tp, LOW);
delay(2);
digitalWrite(tp, HIGH);
delay(10);
digitalWrite(tp, LOW);
long duration = pulseIn(ep, HIGH);
long distance = duration * 0.034 / 2 ;
return distance;
}