NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7

alegiaco:
Thanks for your answer. Very clear. So, if I have 4 sensors the minum elapsed is 35 ms for the readings and Arduino time. I start reading the first sensor, the second, the third and the forth. If the distance is 20 cm it take 1.4ms x 4 = 5.6 ms. I have almost 30 ms for Arduino to do other things and after restart next reading. But in my experience a normal algo in Arduino, without too much serial monitor printing, take 10-15 ms. If you don't print in the serial monitor the time is always under 10 ms. So 15-20 ms are lost waiting for new sensor reading to avoid the echo.Shame.

With 4 sensors, you would ping each one with a minimum of 35ms between each ping. So, 35 x 4 = 140ms to ping 4 sensors. Therefore, you could ping all 4 sensors 7 times a second. As your maximum distance is only 20cm, and at that range the MAX it would wait is 1.4ms to get the ping results per sensor, the most processing time used to wait for pings would be around 40ms per second (1.4 x 4 x 7 = 39.2), with 960ms per second for other tasks. Basically, with a 20cm range, the ping process only uses a maximum of 4% of the Arduino's processing time. That's also the max, as if the sensor detects something closer, it will use even less. That's also assuming you ping every 35ms. If you don't need pings 7 times a second, it would be even less. Also keep in mind that this time is not lost to processing, but simply waiting for a pin to go high. It is a shame, but a good illustration of how fast the Arduino is and how slow the speed of sound is.

With that said, the NewPing library is much smarter and my example sketches are more event driven than the others out there. Looking at my examples, you can tell that I'm not much of a fan of sequential programming (where's the "delay" some would say looking at my code). The only sequential part of the NewPing library and my example sketches is the actual listening for the ping using pulseIn. That's something I'm working on, and will be more important with my future Ping3 library designed to ping 3 sensors.

Tim