I'm creating a logic based circuit and below is my schematic.
The circuit first steps down a 24 VDC input to about 3.7 VDC using a 150K ohm resistance and a 5.1V Zener diode.
This 3.7 VDC is fed to the input of optocoupler PC817 pin 1 and 2.
On the output, I wanted to read the high and low through an Arduino connected to pin 3 and 4 of the optocoupler. I was planning to pass in 5 VDC from the Arduino to one of its digital I/O pin through the optocoupler.
Is there anything wrong here? I'm not able to read the high on the output of the optocoupler. I checked that the voltage around pin 1 and 2 is 3.7v.
Update
I reduced the resistance to about 4K since i didn't have the exact 4.7K as mentioned in the comments below. I also tried 5.6K, however seems like the optocoupler doesn't work in any case.
Best Answer
Something like this should work in most situations (with low switching frequencies, up to a few KHz or so):
simulate this circuit – Schematic created using CircuitLab
This produces a non-inverted output.
If you need the output to be inverted, connect pin 3 to GND, connect the Arduino input to pin 4 and put a pull-up between pin 4 and +5V. I'm assuming your Arduino runs on 5V.