banner
News center
Integrated corporation

Programmable IR Proximity Sensor

Oct 25, 2023

Ido Gendel’s client had a specific IR proximity sensor module, which shines an IR LED constantly and picks up an object’s reflection via a phototransistor. This device reached its end-of-life, so a drop-in replacement was needed. Rather than making something that worked like the last unit, he made one with a programmable sensitivity while keeping BOM costs low.

The easy way to do this would be to use a trim potentiometer for analog adjustment with a screwdriver. However, setting things up this way isn't easy to reproduce, and would mean manual adjustment of every single sensor implemented.

What was needed is a way to program each one electronically. Rather than adding extra interface components, Gendel’s new enhanced sensor leverages the IR emitter/detector for double duty: detecting objects plus receiving and transmitting data.

The new device employs an inexpensive OPB732 reflective switch as the IR unit and an ATtiny212 for control. The ATtiny212 uses its DAC, along with a BJT transistor to modify the IR output intensity. Reflections are read via an ADC for object presence detection, while at the same time fed into an analog comparator peripheral. The comparator output is sent via physical GPIO pins to the USART RX input, allowing it to sense programming signals if they are present.

TX from the sensor unit is bit-banged through the DAC output, sending minimum and maximum LED intensities at 1200 baud. Along with the sensor itself, Gendel built a programming unit, which translates USB-to-UART signalling into pulses of IR light. While there are a few caveats listed to this design, most messages reportedly arrive correctly, and the protocol it uses filters out those that don’t.