#define BLYNK_TEMPLATE_ID "TMPL3MG913jg-"
#define BLYNK_TEMPLATE_NAME "Visually impaired Navigation"
#include <BlynkSimpleEsp32.h>
#include <WiFi.h>
// WiFi credentials
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
// Blynk authentication token
char auth[] = "7_DXAOtUjVTC1WxKbKu0QrGd1wnOyQi1";
const int trigPin = 13;
const int echoPin = 5;
const int ledPin = 12;
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
// Connect to WiFi and Blynk
setupBlynk();
}
// Function to initialize WiFi and Blynk
void setupBlynk() {
Blynk.begin(auth, ssid, pass);
}
void loop() {
// Clear the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
// If distance is less than 20 cm, turn on the LED
if (distance < 20) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
// Run Blynk
Blynk.run();
delay(500);
}