Chopped InfraRed Block Detector
The circuit has a number of features:
- Fits on a 1.25″ square PCB;
- Adjustable sensitivity, setting stored in non-volatile memory;
- Adjustable delay on reset of output from 0.1 to >15 seconds;
- Output can be configured by the user for active high or active low;
- Uses IR light, chopped at a continuously-varying frequency near 1kHz (invisible);
- Virtually totally immune to ambient light, even sunlight;
- Standard, low-tolerance electronic components costing circa US$5.
How To Use It
When power is applied to the circuit the “signal” indicator LED flashes quickly for 1 second to indicate that the unit has started correctly. After 1 second, the flash rate slows down, and the indicator continues to flash for a period of time that indicates the sensitivity setting. The longer the slower flashing lasts, the less sensitive a setting has been put in the microcontroller’s memory. (You are setting the “detection threshold”.)
When an object such as a finger or a train approaches the IR sensor (QRB1114) light from the flashing LED is reflected from the object and is received by the microcontroller. The signal LED flickers when the amount of light exceeds the preset level. The sensitivity can be set to pick up a piece of white paper from as far as 20mm away, or as little as 3mm. The microcomputer ignores light that is not flashing at the correct frequency, so is not fooled by daylight or bright fluorescent lamps. The chop frequency is deliberately randomised, so that beats with mains-powered lights do not cause false triggers.
A filter function requires several sequential triggers in order to activate the “detect” output. This is why the signal LED can be seen to flicker before the output tiggers. This function prevents flashes or sharp shadows from causing false triggers.
When the device recognises a trigger, it asserts the output. This starts a delay, set by the position of the potentiometer. Further triggers reset the delay. Only when there have been no triggers for the preset delay does the output return to the non-assert state.
The screwdriver-adjustable potentiometer sets the delay. In conjunction with the push button, it can also be used to change the sensitivity, or to change the output from going high when a train is detected, to going low instead. When the button is pressed, the signal LED starts to flash slowly. When the button is released, the setting of the pot is recorded as the new sensitivity value. The LED flashes at a faster rate for a duration that reflects the sensitivity, or rather the intensity of a “sighting” that is required to trip the detector. A period of about 2 seconds represents mid-range sensitivity, perhaps 10mm (although this varies with many factors including the reflectivity at infrared of the target object). If the button is held for 5 seconds or more, the output polarity is inverted, so that if it previously went high, illuminating the “detect” LED, when a train was detected, it will now do the reverse.
Resetting the sensitivity goes like this: Insert a screwdriver, adjust the pot clockwise to the end of its travel for minimum sensitivity, anticlockwise for maximum sensitivity. Press and release the button, observe the duration of the fast-flashing burst and compare to the one at powerup to confirm the change. Sensitivity thresholds corresponding to less than 0.5 seconds of fast flashes are not recommended, as flashing lights or sharp shadows in sunlight can trigger the device, as can objects moving more than 1″ from the sensor. When satisfied with the setting, return the pot to the position required to set the delay you want.
If you want to change the output polarity as well, do as above but hold the button down for 5 seconds or more.
How It Works
A PCB layout for the circuit is shown at right.
The circuit is based around a PIC12F675 8-pin microcontroller. This provides non-volatile program and data memory, static RAM memory, timers, inputs and outputs and a 10-bit ADC function on an IC costing less than $2. This IC flashes the IR led, digitises the received signal from the IR phototransistor incorporated with the LED in the QRB1114 assembly, controls the signal LEDs and reads the potentiometer and pushbutton. A three-terminal low-power regulator provides a clean 5V supply.
The flash frequency is delibertely varied, and the received signal sensed synchronously. This gives astonishing immunity to false triggers. The uP’s 10-bit ADC gives very good sensitivity. As an indication of sensitivity, the circuit is capable of detecting the presence, in its view field, of the envelope of an illuminated fluourecent lamp.
The optional LED and resistor can provide a nonlinear load for the phototransistor. This will trade off sensitivity for immunity against bright ambient illumination (typically sunlight). This will not be required in the vast majority of applications, since even if a layout must operate in sunlight, the train to be detected will likely block the sunlight, so the device will not be dazzled into insensitivity at the moment it is needed. The circuit and software take less than 100 milliseconds to recover from being dazzled.
Of course, if you want to build one of these you will need either a pre-programmed ‘675, or a PIC development kit and the software. Please contact the author at the email given on the home page if you seek either.
A picture of a prototype appears at left.
Note the QRB1114 standing up at the rear of the PCB. There is a mounting bolt visible between the QRB1114 and the PIC12f675 which has been socketed.
The optional LED and resistor for high light level operation has not been fitted, but you can see the spaces for them to the rear of the PCB adjacent to the QRB1114.
Here is a picture of the unit installed under a section of N-scale Peco track. It is quite hard to see even if you know what you are looking for. It comfortably detects locos without adding any reflective strips of while paint on the undersides. The fact that it is sensitive enough to detect trains without adding any markings on the bottom is quite convenient!