I am trying to implement the following circuit. I am trying to understand how the resistance values are calculated. I followed this - "how do I calculate resistor value"

Mains detection with optocoupler

According to my optocoupler (SFH6202) datasheet, following are the calculations:

VF(typical) = 1.25V

If = 60mA


Vres = V - Vf = 230 - 1.25 = 228.75

R = Vres / If = 228.75/.06 = 3812.5

But the circuit shows two 100K resistors. Am I doing something wrong here?

Also the Power dissipation is:

P = Vres * Ifmax = 228.75 * 0.06 = 13.72 W

The power dissipation seems too high for 1/4, 1/8 or 1/10 W resistors. Am I doing something wrong in this calculation also? Or do I need some special kind of resistors?

  • 2
    \$\begingroup\$ 60mA is the absolute maximum DC forward current. It is not the recommended operating value, it is the threshold of doom. Study the transfer characteristics later in the datasheet. \$\endgroup\$
    – user133493
    Jan 10, 2018 at 7:45
  • 1
    \$\begingroup\$ Please read stevenh's answer here: electronics.stackexchange.com/questions/33042/… \$\endgroup\$
    – user133493
    Jan 10, 2018 at 7:58
  • 1
    \$\begingroup\$ I assume you try to use AC main. So I rather use the peak to peak of 230Vrms which is 325V \$\endgroup\$
    – Péter
    Jan 10, 2018 at 11:08
  • \$\begingroup\$ Your opto-coupler would work just fine with 10 mA of current. Now your resistors only need a 3 watt rating. \$\endgroup\$
    – user105652
    Jan 18, 2018 at 1:39

1 Answer 1


The opto-coupler has a forward transfer characteristic that specifies how much photo-transistor current will result from so much LED current i.e. Ic/If. With your device at If = 1 mA, the minimum figure specified for your range of devices is 13%, so let's work with this.

Your Ic load as shown is approx. 10 uA. I imagine you're driving a further load, probably a logic gate, so let's allow for Ic = 50 uA. You can buffer the opto-isolator output with a transistor if you need any more output current than that. That makes If at least (100/13) x 50 uA or 384.6 uA, so let's work with an If of 400 uA.

You don't say what your application is or what sort of waveform you're looking for from the opto-isolator. I'll have to make a presumption about your circuit so that I can proceed with the arithmetic: the output must pulse logic low while mains is present, it doesn't have to be continuous. Your circuit currently does this, losing output at lower voltages near zero-crossing.

So the series resistor value must be high enough to not dissipate excessive average power, while low enough to let enough If through during the lower part of the mains cycle. Let's start with the latter.

UK mains is 230 Vrms +10%/-6% so the peak voltage of the waveform is (230 x 1.1) x sqrt(2) or 358 V.

The resistance to let 400 uA through at an instantaneous mains voltage level Vm down to, say, 20 V and with the opto-coupler's max. Vf of 1.65 V is:

(20 - 1.65) / 0.0004 = 45,875 = 44 K

From Prms = Vrms^2/R, the average power dissipation in the same resistance from 230 Vrms +10% is :

(230 x 1.1)^2 / 44,000 = 1.45 W

This is unacceptably high for the function being performed, so let's have the opto-coupler work from Vm down to 80 V and try again:

(80 - 1.65) / 0.0004 = 195,875 = 200 K

(230 x 1.1)^2 / 200,000 = 320 mW

This is much more palatable. Now to the implementation itself...

The circuit needs to have Single Point Of Failure (SPOF) protection to operate safely from the mains. This means that the effect of a failure of a single component in your mains-powered circuit needs to be considered for every component. For SPOF, 'failure' means that the component fails short-circuit or open-circuit. Components don't all fail this way in real life but this is how it is considered in SPOF.

Considering SPOF here, a single series resistor could fail short-circuit and destroy the opto-isolator so two series resistors are used instead for SPOF protection. If one fails short-circuit, the other must still be working as we are considering a single point of failure. Each resistor must be rated the handle the full power it would then have to dissipate:

(230 x 1.1)^2 / 100,000 = 640 mW

For reliable circuit operation over a long lifetime, we will derate it for power and use 1 W part. This allows about 50 % margin over what it could ever dissipate against what it can handle continuously dissipating.

So, we finally get to a circuit:


simulate this circuit – Schematic created using CircuitLab

With mains applied, Vout will drive low when mains voltage Vm is above +Vmol or below -Vmol.

Vm for output low (Vmol) is somewhere between an maximum range of 1.65 V and 80 V, depending on the particular opto-isolator and load. But this is only a maximum range and the real transition range will be much narrower than that. As an educated-but-complete guess, it'll be between 30 V and 50 V.

In practice, if the slew rate of Vout is too slow to be used by its loading circuit then pass it through a Schmitt trigger first, such as an op-amp or one (or two, for non-inverted) 74xx14 Schmitt inverters. If you require a continuous level on Vout, use Vout to trigger a retriggerable monostable with a minimum period of 10 ms and take the monostable output as your signal.

  • 1
    \$\begingroup\$ Thanks for the beautiful answer. I went through it two times, and still missing some parts... I will do couple more rounds with it until I understand all details. Thanks! \$\endgroup\$ Aug 29, 2021 at 21:17
  • \$\begingroup\$ @CarlosGarcia, you're very welcome. Please do upvote answers if they're valuable. \$\endgroup\$
    – TonyM
    Aug 29, 2021 at 22:30

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