Author Topic: Linearized Equation for Sharp GP2Y0A02?  (Read 4827 times)

0 Members and 1 Guest are viewing this topic.

Offline killstoTopic starter

  • Jr. Member
  • **
  • Posts: 7
  • Helpful? 0
Linearized Equation for Sharp GP2Y0A02?
« on: November 21, 2008, 10:30:11 PM »
I can't figure this out. I'm looking for an equation to get centimeters from the range finder. I'm using an Arduino.

So far I:
A)Can get analog values from the rangefinder
B)Can print on the screen
C)Don't know the equation to convert the cm.

Also the values that come in seem to shift even when there is only slight movement (shaking), should I take an average?

Here is the datasheet with the graph:

Offline ArcMan

  • Supreme Robot
  • *****
  • Posts: 519
  • Helpful? 4
  • Mmmm... Plasma
Re: Linearized Equation for Sharp GP2Y0A02?
« Reply #1 on: November 22, 2008, 06:59:53 PM »
This sensor isn't perfectly linear, but you can get close.  The key is in the second graph.  You can see that there is an almost linear relationship between 80cm and 7cm.

V = 20(1/d) + 0.2 (from reading the graph - you can probably get a bit more accurate than this)
(1/d) = (V-0.2) / 20
d = 20 / (V-0.2)

This won't hold closer than 7cm because it's not linear anymore.


  • Guest
Re: Linearized Equation for Sharp GP2Y0A02?
« Reply #2 on: November 22, 2008, 07:17:53 PM »
Yes Definately take an average.

Try to make a system that takes say 5 readings. Then analyze the readings and throw any away that are obviously bad. e.g.

 take 5 readings:


Reading 3 is obviously a false reading caused by a spike or interference or something so throw this one away then average the other 4.

doing this the average reading is 61cm
without the false reading filter the average would be 66.6cm This is quite a difference and these false reading do occur quite a lot with these sensors. You can use a capacitor to try and average them out but a capacitor is likely to produce something like average WITH the false reading as well as slowing down reaction times.