sharing a NPN output sensor on 24V power

I am trying to log the output freq of a OC/NPN output proximity switch. by adding a pull up resistor, arduino is able to use the proximity switch directly without problem(reading looks OK). but this E2E Omron proximity switch is connected to a PLC on 24V power supply. When the PLC is connected, the singnal output has a dynamic voltage upto 24V. I tried connecting the same signal wire to input pin through a voltage divider which seems to work but the frequency arduino measured is always 10~20Hz higher than the PLC's , I also tried replace the divider with a 4.7v zener diode in parallel, which eventually affected the PLC sampling, neither got a seemingly correct reading.

To not meddle with the PLC, it seems that either the arduino should relay the signal to PLC (which is not an option, the device must work without arduino.) or the signal needs to be split with some transistor circuit before going to PLC or arduio. or whatever. I don't really know how this could be properly done. Can someone point me a direction or to some good references?

Thanks.

Use an optoisolator (4N25) with a resistor on the LED to reduce the current to only a few mA. This will still turn on the output but not effect the PLC.

Weedpharma

thanks, weedpharma. I drew it up, could you have a look ? hope I get you right.

optocoupler-split.PNG

There is no need to interfere with the existing wiring that I assume is simply a wire from "pulse" to the PLC. Take a wire from the "pulse" to a R to the optoisolator LED and gnd.

You are then just sucking a small amount of current from the pulse signal.

Weedpharma

I used to take a wire from the "pulse" to a voltage divider on the arduino side and connected it to arduino's discrete input. it seems to work, but the frequency arduino calculated is higher than the PLC by 10-20Hz
I don't really know where these extra count come from.

That approach feels like my previous attempt above. So I thought you mean something more complicated.
OK, I will try this one soon. it won't hurt to save another optocoupler :).
Meanwhile, do you think the circuit I drew above will work?

Thanks.

It will probably work. This assumes the output of your sensor is open collector.

You will need a pull-up R for the digital input of your Arduino.

As to why your count is different, we cannot tell without you program.

Please put your code in its own window as seen in other posts. This can be done by placing     [code]  and [/code]  around the code or use the </> icon. This makes it easier for others to read.

Weedpharma

I didn't write it myself, but used GitHub - GreyGnome/EnableInterrupt: New Arduino interrupt library, designed for Arduino Uno/Mega 2560/Leonardo/Due 's speed mode on hardware interrupt pins. namely just turn on the library, and harvest the count every second. Counted Hz is similar to what PLC would have when sensor connected solely to arduino. but higher when shared with PLC via voltage divider.