#define BLYNK_TEMPLATE_ID "TMPL3G3SA0Wv2"
#define BLYNK_TEMPLATE_NAME "Public Transport"
#define BLYNK_AUTH_TOKEN "rKVxg64sD0M4Rrk35cw_K_TZam47baQW"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define t 12
#define e 14
BlynkTimer timer;
int d=0;
int c=0;
int a1=0;
int a2=0;
int a3=0;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; // your network SSID (name)
char pass[] = "";
#define BLYNK_PRINT Serial
void setup() {
Serial.begin(115200);
pinMode(t, OUTPUT);
pinMode(e, INPUT);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 8080);
}
void loop() {
/*int t1 = digitalRead(t);
int e1 = digitalRead(e);*/
digitalWrite(t, HIGH);
delayMicroseconds(10);
digitalWrite(t, LOW);
// Read the result:
d = pulseIn(e, HIGH);
d = d / 58;
if (d >= 100) {
c=c+1;
} else if (c != 0){
c=c-1;
} else{
c=0;
}
Serial.print("\n\n=============================");
Serial.print("\nNo of vehicles Passed\t");
Serial.println(c);
//predicting the traffic of next junction
//with number of current junction vehicles
if (c<10){
Serial.print("Happy Journey");
a1=0;
a2=1;
Blynk.virtualWrite(V0, c);
Blynk.virtualWrite(V1, a1);
Blynk.virtualWrite(V2, a2);
}
if (c>=10){
Serial.print("Chance of increase in traffic");
a1=1;
a2=0;
Blynk.virtualWrite(V0, c);
Blynk.virtualWrite(V1, a1);
Blynk.virtualWrite(V2, a2);
}
delay(1000);
Blynk.run();
}