1
\$\begingroup\$

I am trying to detect mains with an ESP32, for that I started testing this circuit:

enter image description here

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?

\$\endgroup\$
9
  • 3
    \$\begingroup\$ If you're seeing more than about 1.5 volts on the input, either your optocoupler is dead or you're measuring things wrong. \$\endgroup\$
    – Hearth
    Nov 23 at 15:19
  • 3
    \$\begingroup\$ 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! \$\endgroup\$
    – winny
    Nov 23 at 15:21
  • 3
    \$\begingroup\$ @winny I believe an antiparallel diode is more usual for optocouplers, but either would work. \$\endgroup\$
    – Hearth
    Nov 23 at 15:27
  • 1
    \$\begingroup\$ @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. \$\endgroup\$
    – Hearth
    Nov 23 at 15:51
  • 4
    \$\begingroup\$ 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. \$\endgroup\$
    – Neil_UK
    Nov 23 at 17:00
3
\$\begingroup\$

Since I did not have a diode, the optocoupler could not handle the 325V reverse voltage.

I was measuring 22V because that is the reverse breakdown voltage of the diode.

By adding a diode in series to R1, I started measuring 1.2V as expected.

Since this was just a test, I did not try the anti-parallel solution, but it is probably a better solution, and the explanation is in the comments to the question.

I did no try further because I will probably use a bidirectional input optocoupler, which solves this problem as well.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.