#define BLYNK_TEMPLATE_ID "TMPL6MKMYPxyg"
#define BLYNK_TEMPLATE_NAME "led"
#define BLYNK_AUTH_TOKEN "i21OUVnCG8U48_fFIOTz83AinMLxG-XD"
// Include the Blynk ESP32 library
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
Servo s;
int degree =0;
// Blynk authorization token
char auth[] = BLYNK_AUTH_TOKEN;
// WiFi credentials
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// Create a Blynk timer object
BlynkTimer timer;
// This function will be called every time a widget
// in the Blynk app writes to Virtual Pin 0
BLYNK_WRITE(V0)
{
// Get the state of the button from the Blynk app
int buttonState = param.asInt();
// If the button is pressed (value is 1)
if (buttonState == 1) {
// Rotate the servo clockwise
s.write(180); // Set the servo position to the desired angle (e.g., 90 degrees)
Serial.println("Servo is working");
} else {
// Stop the servo when the button is released
s.write(0); // Set the servo position to the stop position (e.g., 0 degrees)
}
}
void setup() {
// Begin serial communication at a baud rate of 115200
Serial.begin(115200);
Serial.println("Connecting to Blynk...");
Blynk.begin(auth, ssid, pass);
if (Blynk.connected()) {
Serial.println("Connected to Blynk!");
} else {
Serial.println("Failed to connect to Blynk.");
}
s.attach(13); // Attach the servo to pin 2
}
void loop() {
// Main code to run repeatedly
delay(5); // This delay speeds up the simulation
Blynk.run();
timer.run();
}