Use level sensor HC-SR04 without delay

Hey. I have the HC-SR04 Level and I want to use it without the delays.
Can someone correct the code to a code without delay:

// Abstandsmessung wird mittels des 10us langen Triggersignals gestartet
digitalWrite(Trigger_AusgangsPin, HIGH);
delayMicroseconds(10);
digitalWrite(Trigger_AusgangsPin, LOW);

// Nun wird am Echo-Eingang gewartet, bis das Signal aktiviert wurde
// und danach die Zeit gemessen, wie lang es aktiviert bleibt
Dauer = pulseIn(Echo_EingangsPin, HIGH);

// Nun wird der Abstand mittels der aufgenommenen Zeit berechnet
Abstand = Dauer/58.2;
// Überprüfung ob gemessener Wert innerhalb der zulässingen Entfernung liegt
if (Abstand >= maximumRange || Abstand <= minimumRange) {
 // Falls nicht wird eine Fehlermeldung ausgegeben.
 Serial.println("Abstand ausserhalb des Messbereichs");
 Serial.println("-----------------------------------");
}

else {
 // Der berechnete Abstand wird in der seriellen Ausgabe ausgegeben
 Serial.print("Der Abstand betraegt:");
 Serial.print(Abstand);
 Serial.println("cm");
 Serial.println("-----------------------------------");
}
 // Pause zwischen den einzelnen Messungen
delay(500);

Just delete all the lines containing statements like delay(500);.

This one may be required, though:

delayMicroseconds(10);

Yes this has to be in. But is there an other option to make it without this delay? Because the delay is stopping the whole arduino for a short time. And I dont want it to stop it because it may have a influence to my code.

Oh. Sorry my bad.

To determine whether removing the delay() "influences" your code, remove or substantially shorten the delay and see what happens.

Yes I tried it before, but just used millis(). I have to use millis() for the interrupt till the next measure, and micros() to "delay" till the trigger is LOW again. With both millis() it didnt work.

No I tried it that method AFTER I upload my question. I saw the example right after my question.

No I already figured it out (see 3 Messages above).

Still thank you, for your help and sorry for the misunderstandings.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.