Sensing Distance (SHARP GP2Y0A21YK)
The Pieces
IR Distance Sensor
(Sharp GP2Y0A21Y)
The Theory & Code
Infra Red Distance Sensor An analog IR distance sensor is a really neat component. Simply connect +5v and ground and a voltage proportional to the distance between the sensor and an object in front of it will be returned (ranging from 0.4 volts at 80 cm to 3 volts at 10 cm). It really couldn't be simpler to use. Converting to Distance The voltage returned is not linear (see graph), however it can be converted to a distance using some simple maths. There will be some variation between models but here are a couple of equations that worked for us (results +-~5%)
x1
Cable
(JST 3 pole)
x1
The Schematic
+5 volts analog pin
source: GP2Y0A21YK Datasheet
signal
gnd +5v
Equations From 10 bit A/D Reading to centimeters (5v supply) distance = 12343.85 * (10bit reading)^-1.15 From Voltage Reading to Centimeters distance = 27.86 (voltage reading)^-1.15 Arduino Code (5v) float distance = 12343.85 * pow(analogRead(sensorPin),-1.15)
gnd (ground) (-)
Technical Details .: Full Datasheet: [Link] :.
The Circuit
The Layout Sheet
A B C D E 1 2 3 4 5 F G H I J 1 2 3 4 5
signal
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
+5v
gnd
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
to pin 21 analog 0
22 23 24 25 26 27 28 29 30 A B C D E F G H I J
CIRC-20 27
(Sharp29 GP2Y0A21YK)
30
to 5v to Gnd
Distance 28
.: Instructions: print out, cut out, get making :. .: for more details visit: [Link] :.