Hello,
I am using HC-sr04 with Boron to measure distance between 6 cm to 14cm, it works but i get spikes as you can see from the attached picture , known that the object is not moving as i left it at night and this morning i found these spikes, any idea how to eliminate them? i have increased the trig pin microsounds to 10 trying to give more time for the echo not to confuse from previous reading but still i see these spikes.
i use this code:
void loop()
{
float duration, inches, cm;
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(10);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print("\t");
Serial.print(cm);
Serial.print("cm");
Serial.println();
}
float microsecondsToInches(float microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
return microseconds / 74.00 / 2.0;
}
float microsecondsToCentimeters(float microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29.00 / 2.0;
}
Thank you in advance for your help