void setup() {
Serial.begin(9600);
pinMode(5, OUTPUT); // Defining pin 5 as OUTPUT
pinMode(6, INPUT); // Defining pin 6 as INPUT
}
void loop() {
digitalWrite(5, LOW);
delayMicroseconds(5);
digitalWrite(5, HIGH);
delayMicroseconds(15);
digitalWrite(5, LOW);
int a = pulseIn(6, HIGH); // Reading pulse duration
float d = a * 0.0343 / 2; // Converting duration to distance in cm
Serial.println(d); // Printing the distance
delay(100); // Small delay to make output more readable
}