#define BLYNK_TEMPLATE_ID "TMPL33OV2i9Tm"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "psNTz7Ly3C8sLnYPKfpTiZj4ya22LyQ8"
/*
#define BLYNK_TEMPLATE_ID "TMPL33OV2i9Tm"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "7pPGMYyQK7jetjcu5hIrZbHsOXSRJ6a5"
*/
#include <ESP32Servo.h>
#define BLYNK_PRINT Serial
unsigned int value = 0;
int pos = 0;
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
const int servoPin = 18;
Servo servo;
BlynkTimer timer;
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V1)
{
// Set incoming value from pin V0 to a variable
//value = param.asInt();
Serial.println("Inside Blynk Write");
if(param.asInt() == 1)
{
Serial.println("Door Locked");
for (pos = 0; pos <= 90; pos += 1) {
servo.write(pos);
delay(15);
}
}
else
{
Serial.println("Door Unlocked");
for (pos = 180; pos >= 0; pos -= 1) {
servo.write(pos);
delay(15);
}
}
}
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
Blynk.syncVirtual(V1);
Serial.println("Inside Blynk Connected");
}
// This function sends Arduino's uptime every second to Virtual Pin 2.
void myTimerEvent()
{
Blynk.virtualWrite(V1, millis() / 1000);
}
void setup()
{
servo.attach(servoPin, 500, 2400);
// Debug console
Serial.begin(115200);
Serial.println("Serial Prints Starts...");
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
void loop()
{
Blynk.run();
timer.run();
}