Here is one I am using for a "Laser Fence". It will also work for IR.

And the simple code to go with it.
Code:
DEFINE OSC 4
Asm
ERRORLEVEL -306
Endasm
include "modedefs.bas"
ANSEL=%00000000
CMCON=7
PAUSE 2000
TRAIN VAR BYTE
TRAIN=$55
CNT VAR BYTE
LP VAR BYTE
START:
COUNT PORTC.1,100,LP
IF LP <> 1 THEN CHECK
HIGH PORTC.5
PAUSE 50
LOW PORTC.5
PAUSE 50
GOTO START
CHECK:
COUNT PORTC.1,100,LP
IF LP <> 1 THEN BREACH
GOTO START
BREACH:
FOR CNT = 1 TO 5
SEROUT PORTC.4,T2400,[TRAIN,TRAIN,TRAIN,TRAIN,TRAIN,9,3]
HIGH PORTC.5
PAUSE 100
NEXT
GOTO START
END
R2 will adjust the sensitivity of the Photo Diode. Ambient light does need to be shielded. Have used the same with IR but R2 was a fixed 10meg. (Total darkness for a parts counter on a conveyor)
Using 3 volts because of the radio transmitter.
Bookmarks