teckel
May 12, 2014, 4:56pm
468
teckel:
I've never tried using the same trigger pin for multiple sensors nor is the library designed to work this way. What NewPing would do would be to actually try to initiate a ping three times each sensor. The sensor would probably ignore this, but there's no guarantee. Also, I would be concerned with the higher likelihood of echos giving bad results or the pulsing from multiple sensors confusing the sensors.
It would be better (avoiding echos and cross-talk issues) and use fewer pins to just wire a single pin to each sensor's trigger and echo pin. In other words, you would use 3 pins, each pin going to each sensor's trigger and echo pins. This would use 3 pins instead of (I assume) the 4 pins you're currently using. Yes, you would need to ping each sensor individually, but using the non-blocking ping_timer() method your microcontroller could be doing other things while the ping sound is traveling. I would consider this a more "sound" way to implement 3 sensors.
May I ask, why do you want to ping all three at the same time? Would it really matter if each ping was 30ms apart? You could still ping 3 sensors 10 times a second while still "multi-tasking" and doing other processes in your sketch. Insight on your project and the reasoning would be helpful.
Tim
Thank you for the very quick response Tim,
The primary reason is the limitation of available pins on the Pro-Mini. I have each sensor angled outside of each others echo zone. so there is little or no interferences that I can detect at this point. I may have to upgrade to a Arduino mega before this project is finish.
How many pins are you using? 4? One pin for triggers on all sensors and 3 pins to get the results from each sensor? If so, you could just use 3 pins by using the method I describe.
Tim