#define BLYNK_TEMPLATE_ID "TMPL3v7LlK874"
#define BLYNK_TEMPLATE_NAME "smart campus waste management system with Blynk"
#include <LiquidCrystal.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Blynk authentication token
char auth[] = "ZhW0EitF223jx_np5bMUQKpmyU04uFi-";
// Wi-Fi credentials
char ssid[] = "YourNetworkSSID"; // Replace with your network SSID
char pass[] = "YourNetworkPassword"; // Replace with your network password
// LCD pin configuration
const int rs = 23, en = 22, d4 = 19, d5 = 18, d6 = 5, d7 = 4;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Ultrasonic sensor pins
const int trigPin1 = 5, echoPin1 = 18;
const int trigPin2 = 17, echoPin2 = 16;
const int trigPin3 = 4, echoPin3 = 2;
// Buzzer pin
const int buzzerPin = 21;
// Maximum distance in cm (adjust according to your bin height)
const long maxDistance = 400;
void setup() {
Serial.begin(9600);
// Connect to Wi-Fi and Blynk
Blynk.begin(auth, ssid, pass);
// Initialize the LCD
lcd.begin(16, 2);
// Initialize the buzzer
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW); // Ensure buzzer is off initially
// Initialize ultrasonic sensors
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
}
void loop() {
Blynk.run();
// Measure distance from each sensor
long distance1 = measureDistance(trigPin1, echoPin1);
long distance2 = measureDistance(trigPin2, echoPin2);
long distance3 = measureDistance(trigPin3, echoPin3);
// Calculate bin fill levels
long fillLevel1 = maxDistance - distance1;
long fillLevel2 = maxDistance - distance2;
long fillLevel3 = maxDistance - distance3;
// Display distances on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("B1:");
lcd.print(fillLevel1);
lcd.print("cm B2:");
lcd.print(fillLevel2);
lcd.print("cm");
lcd.setCursor(0, 1);
lcd.print("B3:");
lcd.print(fillLevel3);
lcd.print("cm");
// Send distances to Blynk
Blynk.virtualWrite(V1, fillLevel1); // Virtual pin V1 represents distance of Bin 1
Blynk.virtualWrite(V2, fillLevel2); // Virtual pin V2 represents distance of Bin 2
Blynk.virtualWrite(V3, fillLevel3); // Virtual pin V3 represents distance of Bin 3
// Check if any bin is full (e.g., distance < 10 cm)
if (fillLevel1 > 390 || fillLevel2 > 390 || fillLevel3 > 390) {
digitalWrite(buzzerPin, HIGH); // Activate buzzer
Blynk.notify("One or more bins are full!"); // Send notification to Blynk app
} else {
digitalWrite(buzzerPin, LOW); // Deactivate buzzer
}
delay(1000); // Wait for 1 second before the next measurement
}
long measureDistance(int trigPin, int echoPin) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH);
long distance = duration * 0.034 / 2;
return distance;
}