i want to monitor the state of some switches that are using ac voltage (48volt)
in my follow drawing i am sawing the 3 methods i used in order to achieve that (from first try until the third and final)
It is not correct, because in the negative semicycle, the voltage on the PC817 led will be approximately 67.8 V, and it will burn out.
Datasheet informs: Reverse voltage V Max 6V.
Current over the PC817 LED = 67.8V / 22 K = ~ 0.003 A = ~ 3 mA.
I think very little to sensitize the photo transistor.
Datasheet: Forward current mA Max: 50 mA.
I recommend ~ 25 mA.
= 67.8V / 0.025 = ~ 2K7. 2K7 resistor instead of 22K.
The output on the photo transistor will be pulsating at the frequency
of the input 48V.
The difference with the second case is that
the output will be continuous due to the effect of the 1uF capacitor.
In all cases the output of the photo transistor is a little confusing.
Is there a need for this LED on the arduino port?
I'm pretty sure those "results" are simulations because the Arduino isn't synchronized with the AC frequency and that's not exactly what you're going to see.
Not really. As long as you read a high periodically (i.e. once per cycle) the AC is present. You simulation appears to only show the switch-on (voltage present) state.
In the 1st circuit the LED will be off half of the time so it won't appear as bright as the other circuits. BTW the LED will probably be too dim with a 10K series resistor. You might try 1K or you can go lower but I haven't checked the current capability of that opto-isolator.
You can get rid of the existing 1K series resistor and connect the Arduino directly to the opto-isolator.
I'd go with the "simplest solution" - You can put a reversed diode or LED in parallel with the opto-isolator input to protect it.
If you put an LED on the opto's input you can eliminate ALL of the circuitry on the output-side by enabling the Arduino's built-in pull-up resistor. You might have to find an example of how to wire it. With a pull-up instead of a pull-down the Arduino will read low when the opto turns-on so you'd have to reverse your software logic.
Don't need to go to that sort of trouble, just use the third circuit with the smoothing capacitor.
Just use an LED and resistor between the input pin and gnd, it will come on when the 48Vac is present.
However putting a LED indicator on the output side of the opto-isolator is generally a bad idea because the CTR may only be 1 (AKA 100%) or lower (Note the wide specs on the PC817!).
The opto-coupler should be close to the Arduino and connect between the input pin and ground using INPUT_PULLUP. No other component is necessary. If you still must add a LED (with a resistor), it goes from the pin to 5 V,
If you sample the output at no less than four times the mains frequency, you guarantee to detect presence of the mains within two samples.