#define echo 8
#define trig 9
long Duration;
int Distence;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(echo, INPUT);
pinMode(trig, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
Duration=pulseIn(echo, HIGH);
Distence = Duration * 0.0344 / 2;
Serial.print("Distence : ");
Serial.print(Duration);
Serial.println(" cm");
}