Connecting an IR Distance Detector to an OOPic.
This Application Note demonstrates how to connect and use the Sharp GP2D12 IR Distance Detector
Introduction:
  The Sharp GP2D12 IR Distance Detector is a small device that measures 1 and 3/4 inches by 1/2 inch with a 1/4 inch connector on one side. It is capable of measuring the distance between itself and an object that is within a distance range of 10cm (~4") to 80cm (~30"). 

This sensor takes a continuous distance reading and reports the distance as an analog voltage which can be read from its connector, which has 3 pins; power, ground and the output voltage.

  This sensor uses triangulation to detect the distance. A small linear CCD array detector is positioned 3/4 of an inch away from an IR emitter and is used to compute the distance and/or presence of the IR reflection in the field of view. 

If the IR light reflects off an object, it returns to the detector and creates a triangle between the point of reflection, the emitter, and the detector. The angles in this triangle vary based on the distance to the object, and from those angles, the distance to the object can be calculated. 

This method of ranging is almost immune to interference from ambient light and offers amazing indifference to the color of object being detected.

  When reading the output voltage of the sensor, two things are noticed;

1: As shown on the graph on the right, the output voltage that is generated from the sensor represents a value of a trigonometric function, because of this, the output of these sensors is non-linear with respect to the distance being measured.

2: As shown on the Oscilloscope reading on the left, the output is not a constant voltage. It has pulses that are as much as 0.01 volts. While this may not sound like a lot, when reading the sensor with an 8-bit Analog to Digital converter, these pulses can change the 8-bit value as much as 2.

I/O connections:
  To connect the Sharp GP2D12 to the OOPic, one Analog to Digital I/O Line is used. The OOPic's +5-Volt power can be used for one GP2D12, but two or more will put a strain on the OOPic's voltage regulator. You can upgrade the OOPic's voltage regulator by following these instructions

A capacitor in the value of 4.7uF is placed between the sensor's output voltage and the ground. This limits the output voltage from changing very fast and thereby smoothes out the 0.01 voltage pulses.

  To connect the Sharp GP2D12 to the OOPic, 1 Hardware Object must be created.
Dim IR As New oA2D 'Initializes a new object called IR as 



                   '  a Analog to Digital converter

This hardware object will be set up in the following manner.

IR.IOLine = 1       'Which I/O line to use for the sensor.



IR.Operate = cvTrue 'Turn the Analog To Digital Object on.
The Program:
Dim IR As New oA2D 'Initializes a new object called IR as 



                   '  a Digital to Analog converter.







Sub main()



  'Start of main program



  IR.IOLine = 1       'Which I/O line to use for the sensor.



  IR.Operate = cvTrue 'Turn the Analog To Digital Object on.  do



  ' At this point, any time that IR.Value is read, 



  '  it will be the current distance measurement.



End Sub 'End of main program

    Send mail and comments to: Savage Innovations.