Kronos Robotics and Electronics
Site Map
 
Home Zeus Projects App Notes Downloads Dios Athena Forums
 

AAN120

Interfacing a Sharp GP2D120 or GP2D12 Distance Sensors

  By Michael Simpson

I have been playing around with the various sharp IR distance sensors.  The only real difference between the GP2D120 and GP2D12 is the range of coverage.

GP2D120 4-30 Centimeters. 

GP2D12 10-80 Centimeters.

The sensors outputs approximately .4 to 3 volts depending on the distance to the item in front of the detector.  The closer it gets to an object the higher the voltage.  You can check out all the technical data by viewing the data sheet found here.

Since the Athena has built-in analog to digital port (4-bit) using this sensor is quite easy.

Hookup

The first challenge was interfacing to the connector on the sensor.  The connector on the sensor is a 2mm header.  Several companies sell headers for this connector.  I made a small extender by taking a 3 pin female connector and soldering it to a 3 pin header.

While you could just as easily solder three wires to the connector or the back of the PCB I  decided to just replace the connector.  I like using .1mil headers so it will mate with most US headers and bread boards.  I removed the old one and inserted a slightly modified 3 pin right angle header.

 

Schematic 1

In schematic 1 I show the connection to the Athena.  For the AthenaHS just connect the Resonator to pins 15 and 16.

We are going to use the miniad command to read the voltage from the Athena. 

Program download it here

'GP2D120 Demo
'Place Sensor output on port 0

dim range


loop:
   miniad 0,range
   if range > 1 then
      print "In Range :",range
   else
      print "---"
endif

goto loop


Now we are going to add a second sensor.  With a second sensor we can collect more information and possibly determine the direction the object we are sensing is moving.  We can also determine if we are centered on the object.

 

Schematic 2

 

Program 2 download it here

'GP2D120 Demo 2

   dim range,Lrange,Rrange,lastrange
   clearall

   output 2
   output 3
   output 4
   low 2
   low 3
   low 4


loop:
   gosub getrange
   branch range,r0,r1,r2,r3
   goto loop

r0:
   low 2
   low 3
   low 4
   goto loop

r1:
   high 2
   low 3
   low 4
   goto loop

r2:
   low 2
   low 3
   high 4
   goto loop

r3:
   low 2
   high 3
   low 4
   goto loop


'----------------------------------------
getrange:
   miniad 0,Rrange
   miniad 1,Lrange

   if Rrange > 2 then
      Rrange = 1
   else
      Rrange = 0
   endif
   if Lrange > 2 then
      Lrange = 1
   else
      Lrange = 0
   endif
   lastrange = range

   bitsetvalue Lrange,range,0
   bitsetvalue Rrange,range,1
   return

 

This program takes the readings from the two sensors and sets a variable range based on the readings.  The variable Range will contain the values 0-3.

  • 0: Nothing in range

  • 1:Left Sensor has reading Right does not

  • 2:Right Sensor has reading Left does not

  • 3:Both Sensors have reading.

With the above readings we can light three LED's.  The center LED will only light when both sensors have something in range.  This program could be made more sophisticated by actually comparing the various values from the sensors.

 

Parts

Easy RS232 Driver  

Athena

 

Copyright © 2001 - 2007 Kronos Robotics