#include <ESP32Servo.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_TEMPLATE_ID "TMPL6QGtK9iM1"
#define BLYNK_TEMPLATE_NAME "REMOTE"
#define BLYNK_AUTH_TOKEN "B2LOY10O6BFtK92FOpNO3KMpt5imy2Ng"
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = ""; // Put your WiFi password here
Servo myservo;
int pos = 0;
void setup() {
myservo.attach(21); // attaches the servo on pin 21 to the servo object
pinMode(5,INPUT_PULLUP);
pinMode(18,INPUT_PULLUP);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass); // Connect to Blynk
}
void loop() {
Blynk.run(); // Run the Blynk app
if(digitalRead(5)==LOW)
{
pos++;
Serial.println(pos);
myservo.write(pos);
delay(15);
if(pos>=180)
pos=180;
}
if(digitalRead(18)==LOW)
{
pos--;
Serial.println(pos);
myservo.write(pos);
delay(15); // waits 15ms for the servo to reach the position
if(pos<=0)
pos=0;
}
}
BLYNK_WRITE(V1) // This function gets called whenever the slider widget in Blynk is changed
{
int value = param.asInt(); // Get the slider value from Blynk
myservo.write(value); // Set the servo position to the slider value
}