My Ultra sonic sensor (HC-SR04) is returning these types of values when it has nothing in front:
Ping: 144cm
Ping: 0cm
Ping: 0cm
Ping: 0cm
Ping: 105cm
Ping: 105cm
Ping: 94cm
Ping: 0cm
Ping: 378cm
Ping: 0cm
Ping: 0cm
Ping: 0cm
Ping: 0cm
Ping: 0cm
Ping: 0cm
Ping: 106cm
Ping: 106cm
Ping: 0cm
Ping: 0cm
Ping: 0cm
Ping: 106cm
Ping: 250cm
Ping: 0cm
Ping: 108cm
Ping: 0cm
Ping: 108cm
Ping: 0cm
I am not able to understand why I am getting 0 cm. This value is critical in the program that I am using. Here is a test code which gives me these output:
#include <NewPing.h>
#define TRIGGER_PIN A5
#define ECHO_PIN A4
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN);
void setup() {
Serial.begin(115200);
}
void loop() {
delay(1000);
Serial.print("Ping: ");
Serial.print(sonar.ping_cm());
Serial.println("cm");
}
Because of these 0s my robot is making turns which are not expected.
Any idea why this might happen ?