#define BLYNK_TEMPLATE_ID "TMPL3FZ76ufVR"
#define BLYNK_TEMPLATE_NAME "BUZZER CONTROL"
#define BLYNK_AUTH_TOKEN "z06CSSuY_wQgBc7DkHTT0O9aFdh1AxqV"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Define Blynk variables
char auth[] = BLYNK_AUTH_TOKEN;// Blynk authentication token
char ssid[] = "Wokwi-GUEST"; // Wi-Fi network name
char pass[] = ""; // Wi-Fi network password
BlynkTimer timer;
#define buzzerPin 2
void setup() {
Serial.begin(9600);
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
Blynk.begin(auth, ssid, pass); // Initialize Blynk with the provided authentication token and Wi-Fi credentials
pinMode(buzzerPin, OUTPUT); // Set the buzzer pin as output
timer.setInterval(1000L, checkBlynkCommands);
}
void loop() {
Blynk.run(); // Keep Blynk connected and process incoming commands
}
void checkBlynkCommands() {
Blynk.syncVirtual(V0); // Request the value of param widget from Blynk server
}
// Function to handle incoming Blynk commands
BLYNK_WRITE(V0) {
int commandValue = param.asInt(); // Get the value of the param command
if (commandValue == 1) {
digitalWrite(buzzerPin, HIGH); // Turn the buzzer ON
} else {
digitalWrite(buzzerPin, LOW); // Turn the buzzer OFF
}
}