#include <Arduino.h>
#include <BlynkSimpleEsp8266.h> // Include the Blynk library for ESP8266
#define TRIG_PIN 12
#define ECHO_PIN 13
#define BUZZER_PIN 14
char auth[] = "YourAuthToken"; // Your Blynk authentication token
void setup() {
Serial.begin(115200);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
Blynk.begin(auth); // Connect to the Blynk server
}
void loop() {
Blynk.run(); // Allow Blynk to process incoming commands
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
long duration = pulseIn(ECHO_PIN, HIGH);
long distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (distance < 50) {
tone(BUZZER_PIN, 1000);
} else {
noTone(BUZZER_PIN);
}
delay(100);
}