#define BLYNK_TEMPLATE_ID "TMPL34OEu1JDR"
#define BLYNK_TEMPLATE_NAME "smart traffic diversion system"
#define BLYNK_AUTH_TOKEN "_wQ1VNR218QJbby4xbpZQUF-HImus-iU"
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "_wQ1VNR218QJbby4xbpZQUF-HImus-iU";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// LED pins
const int redLED = 16;
const int yellowLED = 17;
const int greenLED = 18;
BlynkTimer timer;
void setup() {
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
pinMode(redLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(greenLED, OUTPUT);
// Set up a timer to check for LED state changes every second
timer.setInterval(1000L, updateLEDs);
}
void loop() {
Blynk.run();
timer.run();
}
void updateLEDs() {
// Simulate traffic light sequence
digitalWrite(redLED, HIGH);
delay(11000);
digitalWrite(redLED, LOW);
digitalWrite(yellowLED, HIGH);
delay(3000);
digitalWrite(yellowLED, LOW);
digitalWrite(greenLED, HIGH);
delay(7000);
digitalWrite(greenLED, LOW);
delay(1000);
}
BLYNK_WRITE(V1) {
// This function gets called when the RED LED virtual pin changes state
int redLEDState = param.asInt(); // Read the value sent from the app
digitalWrite(redLED, redLEDState);
}
BLYNK_WRITE(V2) {
// This function gets called when the YELLOW LED virtual pin changes state
int yellowLEDState = param.asInt(); // Read the value sent from the app
digitalWrite(yellowLED, yellowLEDState);
}
BLYNK_WRITE(V3) {
// This function gets called when the GREEN LED virtual pin changes state
int greenLEDState = param.asInt(); // Read the value sent from the app
digitalWrite(greenLED, greenLEDState);
}