Are 4N35 optocouplers clamped at 22V?

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.

My math:

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.

My math:

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?

• If you're seeing more than about 1.5 volts on the input, either your optocoupler is dead or you're measuring things wrong. Nov 23 at 15:19
• Are you measuring with an oscilloscope or multimeter? If you are measuring with a multimeter, you might see when it starts to break down with reverse voltage and clamping to some -30 V or similar, half of the time. You are most probably damaging your optocoupler with that 325 V reverse voltage. Add a diode in series! Nov 23 at 15:21
• @winny I believe an antiparallel diode is more usual for optocouplers, but either would work. Nov 23 at 15:27
• @winny That was my thought; considering that the reverse voltage rating of opto inputs is usually 5 volts, clamping it with an antiparallel diode is probably the better option. Nov 23 at 15:51
• You MUST use an antiparallel diode to clamp your opto LED input. If you're veeerrrrry lucky, then the high R1 has limited breakdown current to something that hasn't blown the diode. Why is it clamped at 22 V? That's the reverse breakdown voltage. Nov 23 at 17:00