Command pulseIn(echo, HIGH); dont work?

Hello, had anyone tested the command pulseIn(echo, HIGH);

It worked not for me with an ultrasonic sensor on GPIO2

#define trigger GPIO3 // CubeCell Pin an HC-SR04 Trig
#define echo GPIO2 // CubeCell Pin an HC-SR04 Echo
int entfernung;
// Aufruf über distance = getEntfernung();
int getEntfernung()
{
long entfernung=0;
long zeit=0;

digitalWrite(trigger, LOW);
delayMicroseconds(3);
noInterrupts();
digitalWrite(trigger, HIGH); //Trigger Impuls 10 us
delayMicroseconds(10);
digitalWrite(trigger, LOW);
zeit = pulseIn(echo, HIGH); // Echo-Zeit messen
Serial.println(zeit);
interrupts();
zeit = (zeit/2); // Zeit halbieren
entfernung = zeit / 29.1; // Zeit in Zentimeter umrechnen
return(entfernung);
}

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
Serial.begin(9600);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
}

// the loop function runs over and over again forever
void loop() {
entfernung= getEntfernung();
Serial.println(entfernung);
delay(1000);
}

(yellow signal) on GPIO2

Greetings

E_T

hi,

maybe you can refer this code:

Thank you jasonXu,

but we need a solution, that workes together with loRaWAN. The example you explained, doesnt work together with LoRaWAN!

Greetings
E_T

hi,

We have updated the code about High precision for HC-SR04:

Thank you!

I will test it!

E_T