#define BLYNK_TEMPLATE_ID "TMPL3sGGPF469"
#define BLYNK_TEMPLATE_NAME "ultrasonic"
#define BLYNK_AUTH_TOKEN "S7QK5OSf_tOfHh09Xv7IXvNloIa9QCRt"
#define TRIG_PIN 4 // Connect to Trigger pin of HC-SR04
#define ECHO_PIN 5 // Connect to Echo pin of HC-SR04
void setup() {
Serial.begin(115200); // Start the serial communication at 115200 baud rate
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}
void loop() {
// Send a 10us HIGH pulse to the Trigger pin
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Read the time it takes for the echo to return
long duration = pulseIn(ECHO_PIN, HIGH);
// Calculate the distance in cm
float distance = 400 * 0.034 / 2;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500); // Wait for 500ms before taking another measurement
}