This is a design circuit that can be used to detect objects by reflected infrared light. It can be built into a cylindrical enclosure just like an inductive proximity switch. This is also useful as a level detector for colored liquids like oil. This has some immunity to ambient sunlight as it detects ac pulses. This is the figure of the circuit;
The proximity switch can work for a wide range of power, from 8v to 18v DC, D3 protects reverse power supply connections, and U1 regulates the supply to +5v , -5v is derived from U2 555 oscillator which serves dual purpose. IC 555 is used as an astable oscillator and it flashes the Infra red LED D1 at a high speed, The object close to this LED reflects the light along with the ambient light which may also be sunlight. 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.