Shop OBEX P1 Docs P2 Docs Learn Events
Sharp IR Distance Sensor Algorithms — Parallax Forums

Sharp IR Distance Sensor Algorithms

ercoerco Posts: 20,255
I love me some Sharp IR distance sensors, even if their analog output is non-linear. I suspect most of us use these either with lookup tables or in non-precision applications where rough ranges are used. But this morning I found some hardcore equations at and

Depending on your ADC resolution and other factors, you might not need floating-point accuracy to 6-7 sig figs. :)


  • That's good stuff!

    Thanks for sharing. Now....Bookmarked.
  • ercoerco Posts: 20,255
    There's an older Parallax PDF along these lines, using a Sharp sensor with an ADC0831. BS2 code within did an approximate curve fit, based on ranges. Perhaps not to 6 sigfigs though.

    I bet Jim has that PDF and will post it. Or will I find it first?
  • Sorry, was sidetracked with my new DJI Phantom 3 calibration.

    Have to see what the competition is doing. :)
  • Hello,
    Does anyone have some working code in C that works with the: GP2Y0A21YK0F?

    I have attempted to access it with the example codes in the PropC libraries but nothng gives me
    anything that is useable. Have used my Simpson and my O'scope to follow the voltage changes on
    two of the sensors. The meter and the scope show correct function of the unit but the code for it
    and the other example codes to not change values correctly and show an integer of 2 and a varing floating
    Thank you in advance.

Sign In or Register to comment.