First of all, thanks for the great job you are doing!
Now, i wanted to comment two issues i am having.
First one is the "0" thing. I still get it too often, but i have found some "logic" sequence on it.
Here are some results:
210 210
211 211
210 210
211 211
0 211
0 211 211
0 0
210 211
210 210
211 210
210 210
210 210
0 210
0 210 210
0 0
210 0
210 0 210
210 210
210 210
210 211
0 211
0 211 211
0 0
209 0
209 0 209
209 209
210 211
210 210
210 210
0 210
0 210 210
0 0
210 211
210 210
210 0
210 0 210
211 210
0 211
0 211 211
0 0
210 213
210 210
211 210
210 210
211 211
0 210
0 210 210
188 0
188 0 188
210 0
210 0 210
210 210
210 210
210 209
209 210
0 210
0 210 210
0 0
210 0
210 0 210
210 209
210 210
210 211
0 210
0 210 210
0 0
209 211
210 210
210 210
210 210
210 211
0 210
0 210 210
0 0
First and second colums are read values, and third is just the difference between first and second, so can be ignored. There seems to be an issue that affects after X cycles and makes it return value "0".
Here is the code that i am running:
#include <NewPing.h>
NewPing sonar1(2, 3, 400); // Sensor 1: trigger pin, echo pin, maximum distance in cm
#define pingSpeed 35 // Ping frequency (in milliseconds), fastest we should ping is about 35ms per sensor, 100ms is default
void setup() {
Serial.begin(115200);
}
void loop() {
unsigned int current_distance1 = sonar1.convert_cm(sonar1.ping());
delay(100);
unsigned int current_distance2 = sonar1.convert_cm(sonar1.ping());
Serial.print(current_distance1);
Serial.print(" ");
Serial.println(current_distance2);
if (current_distance1 > current_distance2) {
unsigned int result = (current_distance1 - current_distance2);
if (result > 10){
Serial.print(current_distance1);
Serial.print(" ");
Serial.print(current_distance2);
Serial.print(" ");
Serial.println(result);
}
}
if (current_distance1 < current_distance2) {
unsigned int result = (current_distance2 - current_distance1);
if (result > 10){
Serial.print(current_distance1);
Serial.print(" ");
Serial.print(current_distance2);
Serial.print(" ");
Serial.println(result);
}
}
delay(29);
}
Maybe it helps you solve this issue.
Second thing, is that after a determined number of cycles, the board stops working. I mean, it just freezes. It might take something like 4 minutes or so. Im not too sure about what the reason is, but just wanted to comment it.
This code is being run on an UNO with an SRF05.
BR