Let's Make Robots!

Accurate distance sensor


Total newbie with regards to robotos, but fascinated by the topic. I'm working on a hobby project, which is not really a robot, but I need "robot" components. I'm searching for an accurate distance sensor, capable of sensing distance between 0 and 5 cm (could also between 1 and 6, for instance), with accuracy around 0,1mm. I see some of you are using Sharp distance sensor GP2Y0A02YK0F and similar, but I have not found what is the accuracy of those sensors, so I don't know if it would be appropriate.

Any pointers on how to achieve that will be greatly appreciated. Also, I don't need fast measurments. Measurment every second or two seconds is enough.

Kind regards,


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

This came to my inbox today.  It will get you "sub-micron non-contact" accuracy if you can figure out how to use it.


Thanks! I'm looking into this...

I appreciate it.


There are optical sensors like normally used in robotics that are designed for much shorter range.  Here are 3 that are fairly cheap and easy to get



The first one looks pretty good. It measures up to 10 cm.  Doesn't say what kind of "accuracy" it has.  But is it really accuracy you need, or "precision".  They aren't the same.  Precision is repeatability.  If you don't have to know that it is exactly 45.2 mm, but that it is 4.7 mm different from the last one, precision is what you need.


Of course you will need some common reference point on all the cars to use as a measuring point, no matter what method you use: optical, mechanical, or something else.

I've found those sensors before and hence asked about their accuracy. Of course, I have obviously chosen wrong wording. It is precision that I'm after. That is, I can "calibrate" it to point 0. And then measure and see that it is 5.5mm from the last measurment.

Unfortunately, I have yet to find some data on how "accurate" or "precise" those measurments are. Perhaps I'll just order this sensor and see what I get from it.

Do those sensors work if they are behind plexi glass? (to protect them from dust/dirt, etc)

Thanks, Miha.

I didn't look closely enough at the datasheet for the one sensor I linked.  It simply gives an off/on response if something is there, not a measurement.  So don't buy that one.

This one, http://www.digikey.com/product-detail/en/GP2Y0A51SK0F/425-2854-ND/4103863, is analog output and measures from 2 to 15 cm.  It gives an analog voltage that varies from about 0.4 to 2.0 volts over that distance range.  With an arduino (10 bit ADC) measuring from 0 to 5V, that means the resolution of the ADC is 5V / 1024 steps or about 5mV per step.  The sensor gives 13 cm / 1.65V or about 7.88 cm/V or 78.8 mm/V which is about  0.39 mm / 5 mV or .39 mm / step.  That can be fixed by changing the reference of the ADC.  

Accuracy and precision are going to be VERY dependent on how stable and clean the power supply and ADC voltage reference (same thing in an arduino) are.  No matter what type of sensor you use.  I suspect the sensor will be considerably more accurate than your ADC unless you do some modifications.  The sensor, of course, will need a very clean power supply too.  The problems I've mentioned apply to any type of sensor.  They are not really all that difficult to work around, but may be more than you expected.

Can it work behind plexiglass?  Probably.  The datasheets even give a little information on "optics".  Two things that will cause problems are reflection and refraction.  At every surface some light will be reflected, so not all of it will go through.  The light has to go through 4 surfaces: two going out and two coming back.  That decreases it's brightness and "could" affect the sensor.  It is probably only about 4% per surface, depending on the material.  Biggest problem with that is it affects range, which shouldn't be a problem for you.  But refraction changes the path of the light.  Sense the distance is calculated based on the path of the light, that will change the distance measurements.  You can account for that in software, but you will have to find out exactly how it changes.  It could be done mathematically if you knew all the parameters ( refraction index and thickness of material and distance between transmitter and reciever on the sensor) but probably the best way is just to make some very careful measurements.

bdk6, thank you for your elaborate reply. I'm planning to use this with AVR and I understand the issues with stable voltage supply. Since the price of this sensor is not that high, I'll try to get it locally somewhere (I'm from Slovenia, EU) and see how it behaves -- shipping costs from Digikey are way too high ($44.00 - $56.00). I'll report my findings here. The good thing is, that between 2 and 5 cm, the response is almost linear. So that makes it much easier to calcualte it once it is calibrated.

I appreciate your help!


BTW, what do you think about this (those are availabele around here):

The sensor in the first link you posted only has a range between 4.5 and 6mm.  I don't think that is what you want.  The secone has a range of 4 to 30 cm.  That gets back to the resolution issue.  I don't think either is suitable.

As for what Maxhirez posted, if you are trying to measure the height of the upper side of the car from below, that won't work.  My understanding was that you were trying to measure to the underside from below (the ride height).

Analog is analog.  It inherently has accuracy issues.  That is one reason everything is going digital.  But keep in mind, even a "digital" sensor uses an analog sensor, it just converts to digital before it gives it to you.  Nonlinearity isn't a problem: it can be taken care of easily in software.  Measuring to 0.1 mm is going to be tough no matter how you do it.

I'll call around to see where can I get this around here, but Digikey is simply to expensive (shipping-wise). Looking at the datashett of suggested part GP2Y0A51SK0F, I see a response between 1.something cmd and 8 cm gives me apx. 1.4V difference. Given 10bit ADC, I "could" theoretically sense 5/1024 = 0.005 V difference, so that comes off to 1.4/0.005, 280 different readings. If I divide the distance (let's say 7cm) to those 280 readings, I get 0,025cm, which would be sufficient. But that's theory. I guess that in practice, I wouldn't be able to get such precise readings even with stabilized powered supply. I could aggregate readings and calculate averages though. And that would suffice.

Reading through the second suggestion (available here via Farnell, GP2Y0A41SK0F), I see in the datasheet that the response between 4cm and 10cm (6cm difference) yields voltage difference (~2.7-~1.3 = 1.4V), which is comparable to the upper one. I would need to mount it 4cm below the surface though.

You think my calculations are in the right "ballpark"? I could do with 0.5mm "precision".


I think maybe there is a fundamental problem in the way of what you're trying to do here.  I thought it was clear enough when I asked about it earlier, but maybe I missed what you're actually looking to do, so I did this very rough diagram:

From what I understand, you want to measure A and B from an acrylic base plane using a sensor located below or at the level of that plane.

I think maybe there's some confusion here about the definitions of "distance" and "height" or what a distance sensor is capable of.  However, I think this diagram maybe demonstrates my concern-any traditional "Distance" sensor is only going to measure C (which is intentionally exagerated for visual purposes here) in the diagram-which is to say the distance from the sensor to the first solid or light object in its sensing field.  In other words, the sensor can't see through the tire, wheel, floorboard, motor, etc. or the plexiglass for that matter to get to the "height" you're trying to measure (whether that height is the top of the car body or the top of the tyre.) 

To get around this, you could offset the sensor and put a plane of reflection on top of the vehicle or the tire to measure the reflectance distance, but at that point you could get a far more accurate read with a physical caliper than an open-field sensor.

Am I misreading the situation?