Problem with Ping))) sensor and Arduino accuracy.

Hi

Im new here at the forum so I hope i’m posting this at the right Place.

I bought myself an Arduino Mega 2560 and some Ping))) sensors and after some testing with the NewPing librarie which I found here I had them up and running sending me measurments in centimeters (I also wrote my own code which gives me the same result).

Then i Went ahead testing the accuracy and here is were the problem starts (You might find this a small problem but for my Project this is a big problem).

If the actual measurment is 20 cm arduino shows me 21, 30 shows 31, 40 shows 41.
50 shows 50, 60 shows 60 and so on up to 120 where sensor shows 121 again…

so between 50 and 110 cm all works great but below 50 and above 120 it ads a centimeter… has anyone else run into this problem or has any idea how i could solve this (I know I can do a if ping < 50 ping = ping - 1 but that’s plan B).

This is the sort of accuracy you can expect from an ultrasonic sensor.

average several readings?

Grumpy_Mike:
This is the sort of accuracy you can expect from an ultrasonic sensor.

I actually made a logfile a few days ago and there is some missfiring, 20 cm is reported as 19 those I can live with but when 2000 readings which should be reported back as 20 is reported as 21 and 2000 readings were the target is 50 cm away is mainly reported back as 50 I'm getting confused.
2000 readings with the target 120 cm away is reported mainly as 121 :frowning:

I know accuracy never will be 100% but I was hoping someone else had come across this issue.

You are confusing absoloute accuracy with repeatabilty. You are getting very repeatable results, that's all.
Work out your percentage accuracy it will change with distance. This sort of thing is normal all measurements work like this.

The speed of sound (used by ping) depends on temperature and humidity of the air. For room temperature this can cause noise in readings of max 1%.
Depending on the formula you use to convert duration to centimetres you can have an error of around several %.
The internal clock of micros() in Arduino has steps of 4 micro. In terms of distance that is approx 1 millimetre.
So a deviation in the internal clock (crystal vs resonator) gives deviations in distance.

The error you have is in the order of 0- 5%, given the above that is to be expected.

I discussed improvements of the formula/math recently here - http://forum.arduino.cc/index.php?topic=165860.0 -

I am very interested if proposed formulas help you to make the mapping more exact in practice.

Robbanz:
Hi

Im new here at the forum so I hope i’m posting this at the right Place.

I bought myself an Arduino Mega 2560 and some Ping))) sensors and after some testing with the NewPing librarie which I found here I had them up and running sending me measurments in centimeters (I also wrote my own code which gives me the same result).

Then i Went ahead testing the accuracy and here is were the problem starts (You might find this a small problem but for my Project this is a big problem).

If the actual measurment is 20 cm arduino shows me 21, 30 shows 31, 40 shows 41.
50 shows 50, 60 shows 60 and so on up to 120 where sensor shows 121 again…

so between 50 and 110 cm all works great but below 50 and above 120 it ads a centimeter… has anyone else run into this problem or has any idea how i could solve this (I know I can do a if ping < 50 ping = ping - 1 but that’s plan B).

My guess is that you don’t have ROUNDING_ENABLED set to true in the NewPing header file. Try that and see if your accuracy is better. It’s disabled by default because the level of accuracy you describe is PLENTY good for 99.9% of people. If not, try turning on the rounding and it should give better results.

But, if you have any issues with the distance calculation, simply use the ping() method instead of ping_cm() and apply your own conversion to distance. If the numbers are still not right, the fault is with the accuracy of the sensor, which is typically only good to about +/- 0.33 cm.

Tim

Hi

i will try both your suggestions tomorrow when i'm back at work.