// Luqman Hakim 4312211044
#define BLYNK_TEMPLATE_ID "TMPL6MmyMnhi8"
#define BLYNK_TEMPLATE_NAME "ESP32 with LED and buzzer"
#define BLYNK_AUTH_TOKEN "nnxD8ph6ngiae3rj1VUm_YYRnhKHcSxT"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN; // BLYNK auth
char ssid[] = "Wokwi-GUEST"; // WiFi SSID
char pass[] = ""; // WiFi password
#define LED_PIN 22
#define BUZZER_PIN 23
bool buzz = false;
BLYNK_WRITE(V0) {
int button = param.asInt();
if(button == HIGH){
buzz = true;
}
else{
buzz = false;
}
}
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
Blynk.run();
if (buzz == true) {
// Blink the LED with a 30 second delay
digitalWrite(LED_PIN, HIGH);
tone(BUZZER_PIN, 1000);
delay(1000);
digitalWrite(LED_PIN, LOW);
noTone(BUZZER_PIN);
delay(1000);
}
else
{
digitalWrite(LED_PIN, LOW);
noTone(BUZZER_PIN);
}
}