Custom trigger duration for NewPing library

Hello all,

Recently I bought a new ultrasonic sensor and since the NewPing library has many features such as built-in digital filter method ping_median() for easy error correction and more.

How can I modify the trigger duration to more than 60 micro-seconds, preferably 100ms (according to sensor data sheet).

Is there a way to modify this? What is the default trigger duration?

Thanks

Why do you need such a long pulse?
100ms is the round-trip time for a distance of about 17metres.

well in the datasheet it is mentioned that the trigger duration should be more than 60ms. (please see attached image from the datasheet).

It is working fine with a trigger pulse (and then calculation using pulseIn()). But it always returns 0 when used with NewPing.

screenshot.png

Sorry, can't read Chinese that well. Maybe you can give us a translation of that text?

The minimal trigger pulse for the HC-SR04 is 10 us. As far as I'm aware there is no maximum duration, and the sensor triggers on the falling edge of the pulse. That implies the duration of the pulse is irrelevant as long as it's 10 us or longer.

I should try it out but this way it should work (I obviously left out bits):

void setup() (
  digitalWrite(trigPin, HIGH);
}

void loop() {
  // every now and then:
  distance = measureDistance();
}

float measureDistance() {
  digitalWrite(trigPin, LOW); // falling edge to trigger sensor.
  uint16_t pulse = pulseIn(echoPin, HIGH, 20000);
  float distance = (float)pulse / speed_of_sound;
  digitalWrite(trigPin, HIGH); // ready for next measurement.
  return distance;
}

You could even make this entirely non-blocking by connecting the echoPin to an interrupt...