#define BLYNK_TEMPLATE_ID "TMPL3OGv5r1fI"
#define BLYNK_TEMPLATE_NAME "SWCMS""
#define TRIG_PIN 9
#define ECHO_PIN 10
#define LED_PIN 13
#define BUZZER_PIN 11 // Define the buzzer pin
#define BIN_FULL_LEVEL 50 // Set bin full level in centimeters
#define BLYNK_TEMPLATE_ID "TMPL3OGv5r1fI"
#define BLYNK_TEMPLATE_NAME "SWCMS"
#define BLYNK_AUTH_TOKEN "pSz5ILNaFCNBSkKjLukjy5wYhLvjZuA2"
void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW); // Turn off the LED initially
digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer initially
}
void loop() {
long duration, level, distance;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH);
distance = (duration * 0.034) / 2; // Convert to cm
level = BIN_FULL_LEVEL - distance - 1;
if (distance > BIN_FULL_LEVEL) {
tone(BUZZER_PIN, 500);
delay(1000);
noTone(BUZZER_PIN);
Serial.println("Bin is Full");
digitalWrite(LED_PIN, HIGH); // Turn on the LED
digitalWrite(BUZZER_PIN, HIGH); // Turn on the buzzer
} else {
Serial.print("Bin Level: ");
Serial.print(level);
Serial.println(" cm");
digitalWrite(LED_PIN, LOW); // Turn off the LED
digitalWrite(BUZZER_PIN, LOW); // Turn off the buzzer
}
delay(1000); // Wait for 1 second before next reading
}