I am trying to detect mains with an ESP32, for that I started testing this circuit:
I bought a 4N35 optocoupler and 110kΩ resistors.
My first test was using 2 resistors in series, so R1 = 220kΩ.
The LED turns on, I see 22V and 0.96mA across pins 1 and 2.
V = I * R => 230V = 0.001A * 230KΩ
Then I added 10 series resistors, so R1 = 1.1MΩ.
The LED also works, I still see 22V across pin 1 and 2 of the optocupler, and I = 0.21mA.
V = I * R => 230V = 0.00021A * 1095KΩ
Why is the voltage of the optocoupler clamped at 22V?
How can I calculate the optimal (maximum?) R1 value that will make my circuit work?