bassmagnetic:
Brilliant, thanks Tim, just tried that and it works fine with 1 sensor, I am using HC-SR04's.... much better than buying more bits!!
Now I just need to figure out how to combine this code with the NewPing15sensor code to make it work with more sensors, any ideas, is it easy to do?
I am needing to increase the number of sensors as I want to make sure that proximately to the speakers does not trigger sounds (so no one goes deaf!)
I am making an installation as part of a final piece for an MA, i'd be happy to send details and photos when its all up and running...
thanks again
andre
Just take the 15 sensor sketch and for each sensor use the same trigger and echo pin. For example, the first part of your sketch would look something like this:
#include <NewPing.h>
#define SONAR_NUM 12 // Number or sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).
unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
unsigned int cm[SONAR_NUM]; // Where the ping distances are stored.
uint8_t currentSensor = 0; // Keeps track of which sensor is active.
NewPing sonar[SONAR_NUM] = { // Sensor object array.
NewPing(2, 2, MAX_DISTANCE), // Using same pin for trigger and echo.
NewPing(3, 3, MAX_DISTANCE),
NewPing(4, 4, MAX_DISTANCE),
NewPing(5, 5, MAX_DISTANCE),
NewPing(6, 6, MAX_DISTANCE),
NewPing(7, 7, MAX_DISTANCE),
NewPing(8, 8, MAX_DISTANCE),
NewPing(9, 9, MAX_DISTANCE),
NewPing(10, 10, MAX_DISTANCE),
NewPing(11, 11, MAX_DISTANCE),
NewPing(12, 12, MAX_DISTANCE),
NewPing(13, 13, MAX_DISTANCE)
};
Tim