Simple IR Proximity Sensor

This post is about building a Simple IR Proximity Sensor based on PIC16F877a micro controller. Usually these simple circuits are built using discrete components and include an OP AMP for comparing the photo diode voltage to a preset value. Current implementation uses only a few parts. Instead of operational amplifier Analog to Digital Converter of PIC16F877 was used to convert a photo-diode voltage to a digital form and compare it with a threshold settings defined by sensorThreshold constant. See attach assembly source code at the bottom of the page. Few words about operation of the sensor. The IR LED constantly transmits a beam of IR light towards an obstacle. As soon as a non-transparent surface is present it will reflect the light to the photo diode causing it to generate a voltage proportional to the intensity of the reflected light. While working OK indoors you should be aware that a direct sunlight on the photo diode can lead to a false reading. Here is the schematic of this design.

Simple IR Proximity Sensor SchematicIn the next figure you can see a design prototype board. 20Mhz oscillator provides clock pulses to Pin 13 of the PIC (CLKIN).This circuits can detect an obstacle up to 10cm (depends on the IR LED current). Source code is available here and can be modified for smaller devices like PIC16F876 or PIC16F88 as long as it has internal ADC.

Simple IR Proximity Sensor Prototype Board