#define BLYNK_TEMPLATE_ID "TMPL3QEj38B_E"
#define BLYNK_TEMPLATE_NAME "quadcopter"
#define BLYNK_AUTH_TOKEN "IMUQaPtzRiEhR81ErhGe7E7ZP-GJN5el"
#include <ESP32Servo.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
Servo servoMotor;
int servoPin = 4;
int currentAngle = 0;
int targetAngle = 0;
int step = 1;
int delayTime = 10;
BLYNK_WRITE(V4) {
targetAngle = param.asInt();
void setup() {
Blynk.begin(auth, ssid, pass);
servoMotor.attach(servoPin);
}
void loop() {
Blynk.run();
// Gradually move the servo motor to the target angle
if (currentAngle < targetAngle) {
currentAngle += step;
if (currentAngle > 180) {
currentAngle = 180;
}
servoMotor.write(currentAngle);
delay(delayTime);
} else if (currentAngle > targetAngle) {
currentAngle -= step;
if (currentAngle < 0) {
currentAngle = 0;
}
servoMotor.write(currentAngle);
delay(delayTime);
}
}