UltraPing - Makes Ultrasonic sensor see beyond the first echo

Hi!
I spent the weekend to make my HC-SR04 to see multiple echos, not just the first one. :slight_smile:
Since the sensor stops listen for incoming echos after the first one, I trigger a second ping with proper timing to get secondary echos from the first burst.
Seems to be working fairly well. (Specially if the first echo isn’t to close.)

Thought I share it with you if someone is interested.

Usage: (There are examples in the library)

ping_multi:
This code populate the array hit with the 3 first echos.

UltraPing up(12, 12);
unsigned int hit[] = {0,0,0};
int hits = up.ping_multi(hit, 3);
for(int i = 0; i < hits; i++) {
  //Do somethig with hit[i]
}

ping_threshold:
This code finds the first echo beyond 25 cm:

UltraPing up(12, 12);
int distance = up.convert_length(up.ping_threshold(25));

This is a fork of Tim Eckel’s excellent NewPing.
(I’m of course open to include my code in his project if he is interested. Tho I have messed around a bit with all functions, to make it fit my needs, so maybe it isn’t that easy, because it will break some backward compatibility.)

You can find it here: https://bitbucket.org/Tvartom/ultraping

Tell me if it’s useful!