float duration, distance, velocity;
const int trigPin=13;
const int echoPin=2;
void setup(){
pinMode (echoPin, OUTPUT) ;
pinMode (trigPin, INPUT) ;
}
void loop()
{
//float duration, distance, velocity;
//const int trigPin=13;
//const int echoPin=2;
digitalWrite(trigPin,LOW);//set digital pin(the number represents pin number) on "high"
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); //set digital pin off "low"
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
velocity= 340;
distance=velocity*duration;
if (distance<0 || distance >5){
Serial.print("the distance you entered is out of range ");
}
else
{
Serial.print("distance = ");
Serial.print(distance);
Serial.println("m");
delay(500);
}
delay(500);
} //digital functions are usually the ones used to control components connected to the digital pins in the arduino
// put your main code here, to run repeatedly: