The Sharp GP2D12 IR ranger sensor takes continuous measurements and gives the distance as
an analog voltage. the sensor is easy to interface to a microcontroller.
Use a 5V supply (5V regulator from comtroller is OK, uses very little
current). The output goes to an ADC input. when ever the sensor is to be
read, the digital value is pulled off of the ADC result. The IR emmitted
from the sensor is returned to the detector where calulations take place
that determine the distance from the angle of reflection.
This is a sample interface using visual basic and the OOPIC controller.
this program will turn an LED on if an object gets too close to the Ranger.
the OOPIC is object oriented. we will use the oA2D (adc) and the oDio1
which is a single pin object.
dim LED as new oDio1 'assign LED as the name of the object
dim adc1 as new oA2D 'assign adc1 as the name of the oA2D object
sub main()
LED.Ioline = 9 'assign line 9 to LED
LED.Direction = cvOutput 'line 9 to be an output
LED.value = 0 'initialize LED to off
adc1.ioline=1 'adc1 assigned to adc line 1
adc1.ExtVRef=0 'specifies 5V reference voltage
adc1.operate=cvtrue 'this turns the ADC on
do 'program loop
if adc1.value > 100 then 'if object is this close then:
LED.value=1 'turn LED on
else 'if not close enough
LED.value=0 'turn LED off
end if
loop
end sub
This program will continuously "watch" the ranger for an object that comes
too close, once an object is determined as too close, the LED comes on.
this sensor is easy to incorporate to any micro controller. wall hugging
behaviors are easy to accomplish with these sensors. ranges are set up to
tell the robot where it is and where it wants to be. there would be a set
range for "too close", "too far" and "just right". too close would
result in the robot moving away from the wall, too far would result in the
robot moving a little closer to the wall. just right would be the target
distance you want the robot to stay to the wall. |