#define BLYNK_TEMPLATE_ID "TMPL6WV-11OYr"
#define BLYNK_TEMPLATE_NAME "ESP32 with 2 LED"
#define BLYNK_AUTH_TOKEN "x3JKv75ml_9w9dB6iobW_hO9MeqPCjHu"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
// WiFi credentials
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// Pins for LEDs
const int redLedPin = 13;
const int blueLedPin = 12;
// Pin for servo
const int servoPin = 14; // You can choose any available GPIO pin
// Servo object
Servo myServo;
// Variables to store LED states
int redLedState = LOW;
int blueLedState = LOW;
// Variable to store servo button state
int servoButtonState = LOW;
void setup() {
pinMode(redLedPin, OUTPUT);
pinMode(blueLedPin, OUTPUT);
// Initialize servo
myServo.attach(servoPin);
// Initialize Blynk
Blynk.begin(auth, ssid, pass);
}
void loop() {
Blynk.run();
Blynk.syncVirtual(V2); // Request the latest value of the servo button
// Blink LEDs if servo button is pressed
if (servoButtonState == HIGH) {
blinkLeds();
moveServo();
}
}
// Function to make LEDs blink
void blinkLeds() {
digitalWrite(redLedPin, HIGH);
digitalWrite(blueLedPin, HIGH);
delay(30000);
digitalWrite(redLedPin, LOW);
digitalWrite(blueLedPin, LOW);
delay(30000);
}
// Function to move servo
void moveServo() {
myServo.write(180); // Move servo to 90 degrees
delay(30000); // You can adjust the delay as needed
myServo.write(0); // Move servo back to 0 degrees
delay(30000); // You can adjust the delay as needed
}
// Blynk virtual pin handler for servo button
BLYNK_WRITE(V2) {
servoButtonState = param.asInt();
}
// Blynk virtual pin handler for red LED button
BLYNK_WRITE(V0) {
redLedState = param.asInt();
digitalWrite(redLedPin, redLedState);
}
// Blynk virtual pin handler for blue LED button
BLYNK_WRITE(V1) {
blueLedState = param.asInt();
digitalWrite(blueLedPin, blueLedState);
}