Skip to content

Conversation

macuser47
Copy link

These changes make the distance calculation for the Sharp GP2Y0A21YK IR Sensor more accurate, particularly in the 30-80cm range.

I extracted the points shown in the chart for distance vs voltage in the GP2Y0A21YK datasheet with WebPlotDigitizer and plotted them in desmos. This showed that the current formula for computing distance isn't very good, so I adjusted the constants for a better fit and tried them out on my sensor. You can see the plots here: https://www.desmos.com/calculator/fivql4vfdm

Here are the results I collected, using a dollar bill for measuring out lengths and comparing measured results for a piece of white paper at the given distance:

Actual Value Value Measured with Old Constants Value Measured with New Constants
15.5956 15.1 14.14
31.1912 36.23 32.03
46.7868 56.92 48.52
62.3824 76.5 64.22
77.978 95.44 83.76
93.5736 108.7 96.8

So it seems like these improvements manifest in real-world results with the sensor.

This commit changes the conversion constants for the Sharp GP2Y0A21YK
example based on data points extracted from the datasheet. A graph
detailing the accuracy of the new approximation can be found at
https://www.desmos.com/calculator/fivql4vfdm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant