#define BLYNK_TEMPLATE_ID "TMPL3iiBvCoH8"
#define BLYNK_TEMPLATE_NAME "Blynk Smart Dustbins"
#define BLYNK_AUTH_TOKEN "j39sWLDZbLeIl4nmIPb7RcIXxczl1EYr"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
#define echoPin 32
#define trigPin 33
long duration;
int distance;
void ultrasonic()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2; // formula to calculate the distance for ultrasonic sensor
Blynk.virtualWrite(V0, distance);
}
void setup()
{
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Blynk.begin(auth, ssid, pass);
delay(2000);
timer.setInterval(1000L, ultrasonic);
}
void loop()
{
Blynk.run();
timer.run();
}