bassmagnetic:
Hi Tim,I want to use 12 sensors, which is obviously achievable with your code, I have got 6 working really well so far so thank you.... however there are only 12 pins on the arduino uno, so I can only use 6 sensors (obviously 2pins per sensor). I see you can buy a Mux shield to add more inputs. Would this shield work with your code? (I'm very new to code). Would I need to change the code much to make it work? or is there a better / easier option?
Thanks again
cyclegadget is quite right, I've written the NewPing library to work using only one one pin for both trigger and echo. So, with even the Uno you can connect 12 ping sensors using the NewPing library. Basically, the library sets the pin to output, initiates the ping, quickly switches the same pin to input, and waits for the ping echo. The syntax is just to specify the same pin for both trigger and echo. Below is an example sketch as well as a schematic of how you connect the sensor. You simply tie the pin to trigger and then jumper trigger to echo.
http://code.google.com/p/arduino-new-ping/wiki/NewPing_Single_Pin_Sketch
Before you rip your project apart and use the one pin method I would suggest doing just one sensor first. The reason is that for some sensors this one pin technique doesn't work. If you're using the HC-SR04, you should be good to go. Others may need a little capacitor instead of the jumper. I believe I docucmented in the release notes in NewPing.h exactly which sensors worked without the cap and those that needed the cap. Check the release notes in NewPing.h for details.
Also, I'm always interested to see what multi ping sensor projects people are using with NewPing. Once you get things working, post a pic.
Tim