const int trigger_pin = 5;
const int echo_pin = 18;
long duration;
int distance;
void setup() {
pinMode(trigger_pin, OUTPUT);
pinMode(echo_pin, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigger_pin, LOW);
delayMicroseconds(2);
digitalWrite(trigger_pin, HIGH);
delayMicroseconds(10);
digitalWrite(trigger_pin, LOW);
duration = pulseIn(echo_pin, HIGH);
distance = duration * 0.034/2;
Serial.print("Distance = ");
Serial.println(distance);
delay(1000);
}