Full Version : Simple 40Khz IR Proximity Detector (AVR BASIC)
avr >>VISION GUIDANCE & NAVIGATION >>Simple 40Khz IR Proximity Detector (AVR BASIC)


AVR_Admin- 05-08-2006
Simple 40 khz I/R Proximity detector

This unit uses two generic I/R LED's, some reasonable current limiting resistors and a Panasonic I/R remote control receiver. There is nothing special about the unit except that it was the cheapest thing I could get at Digikey. It's part number is PNA4602M-ND. Any Sharp or Panasonic unit, old style shielded, or newer plastic encapsulated should work. You might need to adjust the values of the load resistors to control sensitivity and range. You can also tweak the cycle time of the LED's to adjust sensitivity as the response of the detectors are tuned to a particular frequency. I used brass tubes to shield the detector from stray LED light. I also had to put a piece of tape over the back of the detector shield it from light leaking out the back of the tubes. These things are very sensitive.


I used the ISP programming header on the ARC as my connections for the I/R proximity detector. I used PORTB 5, 6 and 7 as my Left and Right LED drives and Detector inputs. I also pulled +5v and ground from the connector. I used a 10 conductor cable and a 10 pin IDC socket to make connections easy. Please refer to the ARC 1.0 schematic for connections if you wish to duplicate this exact arrangement. Naturally, any three spare I/O pins will work with the appropriate changes to the code, below.

Link to Site: http://www.barello.net/ARC/projects/Proximity/index.htm

CODE
'
' Function to pulse LED outputs and detect stuff
'
' Toggles left and right LED 10 cycles of 26us + 260us delay between
' for a total run time of 800us.
'
' Initialize Portb bits 5 & 6 as outputs, set high and
' portb bit 7 as input with pull-up enabled (1)
'
' to use, declare function at top of program, then call, assigning
' the return value to a variable for analysis.
'
' Returns 0,1,2 or 3 indicating nothing, left, right or both.
'
Function Doproximity() As Byte
   Local I As Byte
   Doproximity = 0
   For I = 1 To 20
       Toggle Portb.6
       Waitus 7
   Next I
   If Pinb.7 = 0 Then Doproximity = 1
   Waitus 255
   For I = 1 To 20
       Toggle Portb.5
       Waitus 7
   Next I
   If Pinb.7 = 0 Then Doproximity = Doproximity + 2
End Function



Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.