int Trig_pin =5;
int Echo_pin =18;
long duration;
float Speed_of_sound =0.034;
float dist_in_cm;
void setup() {
Serial.begin(115200);
pinMode(Trig_pin, OUTPUT);
pinMode(Echo_pin,INPUT);
}
void loop() {
digitalWrite(Trig_pin, LOW);
delayMicroseconds(2);
digitalWrite(Trig_pin, HIGH);
delayMicroseconds(10);
digitalWrite(Trig_pin,LOW);
duration =pulseIn(Echo_pin,HIGH);
dist_in_cm=duration*Speed_of_sound/2;
Serial.print("distance in cm :");
Serial.println(dist_in_cm);
delay(1000);
}