Infrared Objector (Distance Sensor)


The Infrared Objector supplied with the kit will allow you to detect an object or wall once it is within it's limits (Mine tests out to approximately 5 inches). The RX (Reciever) input to the microcontroller just provides a digital input of 0 - objected detected within the limits or 1 - no object detected.

Since the design for the Drag Racer only requires me to use one of the sensors, the code for p1301 included in the kit has been modified for 1 sensor.

To Configure the base unit the RX lines need to be connected to RA5 while the TX lines (the light source) must be connected to RE0 for this code to work. If you need to use other ports then make the necessary corrections to the code.



Modified Code:


'*****************************************************************
'* Name : P1301.BAS *
'* Notes : Detect Wall Show Status ON LCD *
'*****************************************************************
@ DEVICE PIC16F877,HS_OSC ' Use PIC16F877
DEFINE OSC 20 ' Oscilator = 20 MHz
DEFINE LCD_DREG PORTD ' Set LCD data port
DEFINE LCD_DBIT 4 ' Set starting Data bit
DEFINE LCD_RSREG PORTC ' Set LCD register Select port
DEFINE LCD_RSBIT 0 ' Set LCD register Select bit
DEFINE LCD_EREG PORTC ' Set LCD enable port
DEFINE LCD_EBIT 5 ' Set LCD enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us
ADCON1 = $07 ' ALL PORTA & PORTE = Digital I/O
MAIN:HIGH PORTE.0 ' Infrared LED ON
IF (PORTA.5 = 0) THEN ' Check IR MOdule detection
LCDOUT $FE,$01,"DETECT WALL_L"
' If detect, show on LCD
ENDIF
PAUSE 100 ' Delay
LCDOUT $FE,$01
GOTO MAIN ' Check again