Part of - InfraRed LED Flasher for Optical Switch
The infra red diode D2 detector gets the reflected light from LED and some ambient light, The forward voltage drop of D2 will vary with the amount of light falling on it. Ambient light causes a DC component and the pulsing light from D1 causes an AC component.
The capacitor C6 blocks DC and only transfers AC pulses if any to opamp amplifier U3A whose gain is set by R18, D9 rectifies the pulses to DC and this DC voltage is used by opamp comparator U3B which drives Q1 through Q2 for an open collector output for relays. LED D7 turns on when relay Output is high.
R14 and R13 can be replaced with potentiometer for threshold adjustment if required.
Connect 12v DC supply to +V and GND Ports, Connect a relay coil Between OUT and GND Ports, you can use the relay contacts as you require to turn on a lamp, heater, fan or motor.
If all connections are ok and ICs are working you should see a +5V at U3 pin8 VCC and around -4 to -5 at U3 pin4 VDD.
The Optic switch can be used for both reflecting detection (retro reflective) or obstacle detection. The mechanical construction will decide this, for obstacle detection the diodes D1 and D2 could be put in two different tubes and can be kept far apart 2mts+ and both should be exactly opposite each other, any obstacle like a passing person will be detected. To make a retro reflective proximity switch this circuit is ideal, it can be housed in a cylindrical 30mm by 70mm metal unit with m30 threads and nuts for mounting, both D1 and D2 have to be fitted in the front of this tube on a plastic plug optically insulated from each other yet beside each other.
See also - Mixed and Interface Circuits