Hi Tim
I have been trying out some HC-SR04's with your example codes that you have provided and everything is working quite well. I am however having trouble working out how to blend them together to achieve my goals.
My project basically has 3 sensors measuring height above ground, with one of them being a fixed reference sensor and the other 2 being separate variable height sensors.
I was trying to use the 3 sensor example and mix it with the event timer example and the timer median example to provide an average measurement for all 3 sensors 4 or 5 times a second.
Does this seem like a good idea, and do you have any suggestions about how to mix them together?
This is what i have tried so far without success
#include <NewPing.h>
#define SONAR_NUM 3
#define MAX_DISTANCE 200
#define PING_INTERVAL 33
NewPing sonar[SONAR_NUM]={
NewPing(7,7,MAX_DISTANCE),
NewPing(8,8,MAX_DISTANCE),
NewPing(9,9,MAX_DISTANCE)
};
unsigned int pingSpeed = 50;
unsigned long pingTimer;
void setup() {
Serial.begin(115200);
pingTimer = millis();
}
void loop() {
for (uint8_t i=0; i<SONAR_NUM; i++){
if (millis() >= pingTimer){
pingTimer += pingSpeed;
sonar.ping_timer(echoCheck);
}
}
}
void echoCheck() {
if (sonar.check_timer()){
Serial.print(sonar.ping_result/US_ROUNDTRIP_CM);
Serial.println("cm");
}
}
Thanks
Tony