int trigpin = 4;
int echopin = 5;
float duration, distance;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trigpin, OUTPUT);
pinMode(echopin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// this speeds up the simulation
digitalWrite(trigpin, HIGH);
delayMicroseconds(10);
digitalWrite(trigpin, LOW);
duration = pulseIn(echopin, HIGH);
distance = 0.017 * duration;
Serial.print("Distance = ");
Serial.print(distance);
Serial.println("cm");
delay(1000);
}