// Luqman Hakim 4312211044
#define BLYNK_TEMPLATE_ID "TMPL6tyoUDbBC"
#define BLYNK_TEMPLATE_NAME "ESP32 with LED and servo"
#define BLYNK_AUTH_TOKEN "p7tdr6bvZyR5BEZlVZwFSvnItp706sAG"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
Servo servo;
bool servoState = false;
char auth[] = BLYNK_AUTH_TOKEN; // BLYNK auth
char ssid[] = "Wokwi-GUEST"; // WiFi SSID
char pass[] = ""; // WiFi password
#define LED_PIN 22
#define SERVO_PIN 23
BLYNK_WRITE(V0) {
int buttonState = param.asInt();
if (buttonState == HIGH) {
servo.write(180); // Set the Motor Servo angle to 180 degrees
servoState = true;
} else {
servo.write(0); // Turn off the Motor Servo
servoState = false;
}
}
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(LED_PIN, OUTPUT);
servo.attach(SERVO_PIN);
}
void loop() {
Blynk.run();
if (servoState == true) {
// Blink the LED with a 30 second delay
digitalWrite(LED_PIN, HIGH);
delay(30000);
digitalWrite(LED_PIN, LOW);
delay(30000);
}
}