Interfacing optoelectric proximity sensor with arduino

Looks to me like the sensor is probably outputting 24V which is then pulled down by LED1 and pin 3 protection diode in parallel to some unknown, unstable voltage. Until that is fixed your circuit is not going to work as you expect. also you need current limiting resistors (330 Ohm)on LED 2 & 3 and pulldown resistors (10k) on pins 5 & 6.