Hullo well i have tried several ultrasonic code even using basic code of pulseln() function and even tried new Ping library but iam still getting erroneous distances readings.
whether i put an obstacle or not, i still get these sets of results. Iam desperate for advice or help about what might be the problem. is it with HC-SRO4 sensors or something confined in the room.
The results below are from using the new Ping library
https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home#!issue-tracking
Ping: 0cm
Ping: 129cm
Ping: 128cm
Ping: 127cm
Ping: 127cm
Ping: 129cm
Ping: 129cm
then when i was not using any library but the pulseln() function to calculate the duration before i calculate the distance of sound.
digitalWrite(trigPin, LOW); //clear the trigPin
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
digitalWrite(trigPin, LOW);
//Once received the Echo calculate the distance from the duration
duration = pulseIn(echoPin, HIGH);
distance = (duration/2)/29.1 ; //distance in inches..
//distance = duration/58.2; ////Calculate the distance (in cm) based on the speed of sound.
delay(300); //for stability but they used 300
these are the results.
Distance: 123
Distance: 123
Distance: 123
Distance: 122
Distance: 122
Distance: 124
Distance: 124