
RoboPi v1.00
User Manual v0.85
Copyright 2014 William Henning
How to Read Analog Distance Sensors
The Sharp GP2Y0A02YK0F is an excellent infrared distance sensor that uses a 5V supply and
typically draws only 33mA and can present a new reading every 50ms.
You can find the data sheet at:
http://www.sharpsma.com/webfm_send/1487
It has a very useful range of 20cm to 150cm, and is extremely easy to use. There are other sensors in
the same family covering 10cm-80cm, and even 100cm-500cm – but neither are as useful as the 20cm-
150cm GP2Y0A02YK0F.
Please note that the analog output of the sensor is unreliable at ranges shorter than 15cm
Unfortunately the output voltage is not linear with respect to the distance to the object, however it is
easy to construct a table of voltages corresponding to the distance to object in 10cm increments.
Finer distance measurement can be approximated by using linear interpolation as the line segments
between the 10cm data points can be reasonably approximated by straigt line segments.
Dist = analogRead(IR_Channel)
As analogRead returns 0 for 0V and 1023 for 5V, we can scale its output to 1/100th of a volt by
Dist = (500 * Dist)/1024
Giving us Dist as 0 for 0V, and 500 for 5V
Of course, you could do the reading & scaling in one step:
Dist = (500 * analogRead(IR_Channel))/1024
Please see page 5 of the data sheet for the graph of voltage vs. distance.
http://Mikronauts.com
26
2014-01-27