const int broche_trig=12;
const int broche_echo=13;
float distance_min=0.02;  //Distance minimale mesurable
float distance_max=4;   //Distance maximale mesurable

void setup() {
 pinMode(broche_trig,OUTPUT); 
 pinMode(broche_echo,INPUT); 
 Serial.begin (74800);
}

void loop() {
 digitalWrite(broche_trig, LOW); 
 delayMicroseconds(2); 
 digitalWrite(broche_trig, HIGH);
 delayMicroseconds(10); 
 digitalWrite(broche_trig, LOW);
 float Delta_t = pulseIn(broche_echo, HIGH); //Mesure en µs
 float distance = Delta_t/2.0*340/1000000.0;
 
 if (distance >= distance_max || distance <= distance_min){
   Serial.println("La distance mesurée est incorrecte");
 }else{
   Serial.print("La distance est de ");
   Serial.print(distance); 
   Serial.println(" m");
 }
 delay(1000); 
}

