Errors in distance measurements with the LV-MaxSonar EZ serie

I am working with the LV-MaxSonar EZ2 and a Raspberry Pi 3 model B. As you know, The Raspberry Pi can not read analog input, that's why I used an ADC (analog to digital converter), an MCP3008 to convert the analog-volt to a digital input for the the raspberry. I followed this tutorial : [u]https://github.com/alx-s/RPi_tutorials/tree/master/Analog_inputs-MaxBotix[/u]

Except that I wired the VREF pin of the MCP3008 to the 3.3V pin of the raspberry (because I tried with the 5V pin, but it didn't work).

After running the script, I got a logical output. However, there was an error rate that grows with the distance between the sensor and the object. The following examples explain that :

An object that is 16 cm away from the sensor ----> the output is 21 cm
An object that is 17 cm away from the sensor ----> the output is 21 cm
An object that is 18 cm away from the sensor ----> the output is 21 cm
An object that is 19 cm away from the sensor ----> the output is 24 cm
An object that is 35 cm away from the sensor ----> the output is 42 cm
An object that is 56 cm away from the sensor ----> the output is 66 cm & 67cm
An object that is 70 cm away from the sensor ----> the output is 84 cm
An object that is 84 cm away from the sensor ----> the output is 96 cm

Since I got these errors, I decided to try Arduino.
At first, I used an Arduino Nano, and followed the tutorial in published by Maxbotix in their website , link : [u]https://www.maxbotix.com/Arduino-Ultrasonic-Sensors-085/[/u]

Since the Arduino Nano does not contain Pwm pins, I used the Analog-Volt code for a single sensor from the same website (Maxbotix website) and I followed the whole tutorial. The results that I got were closer than with the Raspberry Pi, but they were not precise:

An object that is 30 cm away from the sensors ----> the output is 27.84 cm
An object that is 25 cm away from the sensors ----> the output is 22.94 cm

Since the results were not precise, I decided to use an Arduino Uno this time. I used both the Pwm and the Analog-Volt and I got the same error rate as with the Arduino Nano.

I even tried different sensors, but I got the same errors.

So please, If you have any advices or recommendations about this problem, please mention them. Thank you.

Have you read the datasheet? Useful things them are.
e.g.

Sensor Operation from 6-inches to 20-inches
Because of acoustic phase effects in the near field, objects between 6-inches and 20-inches may experience acoustic phase cancellation of the returning waveform resulting in inaccuracies of up to 2-inches. These effects become less prevalent as the target distance increases, and has not been observed past 20-inches.

Pete

What sort of accuracy were you expecting with this? The datasheet specifies a resolution of one inch but I can't find anything about accuracy.

Pete

I checked the datasheet, according to what was written, there is no problem with the measurements taken with the Arduino. However the measurements taken by the Raspberry, are completely wrong.

Haven't you solved your own problem? Use a Nano or UNO.
If you want an explanation of the poor performance of the Rpi, you're more likely to get informed answers on an RPi forum.

Pete

The problem of the Arduino is solved. :grinning:
I only put the part that talks about the RPi to give more details, I was not expecting to get a solution about the problem related to the RPi here.
Thank you for your help :slight_smile: