Sharp Infrared Proximity Sensor 80 cm Python Code

Hi there, can anyone can help me out how to get the sensor to output the distance in cm?
I found a piece of python code here but that is only outputting detecting/not detecting: Grove - 80cm Infrared Proximity Sensor | Seeed Studio Wiki

Raspberry Pi 4b
Sensor: Sharp Infrared Proximity Sensor 80 cm


anyone has a clue how to run this one?


The Grove Pi has some configuable digital / analog “Grove” ports. That sensor will use three of the four Grove port connections: Power, Ground, and analog voltage input.

Your program will need to configure the port you choose, for analog voltage in called ADC - Analog to Digital Conversion.

Then you need a loop to read the voltage, and write a function which converts the voltage to distance either by a polynomial approximation of the graphed response, or use numpy interpolation for a set of reading:distance pairs you pull off the graph into two matching lists.

1 Like