Resistor power dissipation when driving optocoupler from ac mains

So I've got this circuit, and I built it, and it works fine.

Schematic_irrigationstation_Sheet-1_20191002021215.png

The forwards voltage of the optos led is 1.2 (1.4max) and If = 20mA

I followed this: https://learn.edwinrobotics.com/230v110v-ac-mains-detection-using-arduino-raspberry-pi-and-esp8266-thing/#Step2

With the exception that I used an LTV-814 that doesn't require a bridge rectifier.

Give: Power = I^2 * R = (0.020A)2*(390000) = 156 watts

That doesn't make much sense to me. I'm only using a 1 watt resistor so the resistor should have blown up by now, but it doesn't even get hot.

What am I missing?

What am I missing?

You are confusing the maximum current rating of the LED with the actual current that the resistor supplies to the LED.

You don't say what your local main voltage is.

UK mains 230V
Power = V^2 / R
230^2 / 390000 = 0.135W
(I have ignored Vf as it is negligible compared to 230V)

For 230 Volts, the actual current is 0,6 mA. I would use 1 Watt resitor anyway. Small resistors are not mains rated.

PerryBebbington:
You are confusing the maximum current rating of the LED with the actual current that the resistor supplies to the LED.

You don't say what your local main voltage is.

UK mains 230V
Power = V^2 / R
230^2 / 390000 = 0.135W
(I have ignored Vf as it is negligible compared to 230V)

ok still a bit confused. please bare with me. i am using 120v mains.

if I^2R=V^2/R then why do I get different values and what do they mean?

Untitled.png

Untitled.png

jendalinda:
For 230 Volts, the actual current is 0,6 mA. I would use 1 Watt resitor anyway. Small resistors are not mains rated.

yup, i'm going to anyways, and some movs but this is more hypothetical than anything to wrap my head around some things.

Power dissipation is why we usually use a capacitor, with a smaller resistor just to suppress turn-on surges.

Unless you are using this for phase control timing.

And given that the optocoupler is close to the Arduino, you use INPUT_PULLUP rather than an external pull-up, which is closer to 47k than 10k, so you only need a fifth of the LED current anyway.

ok still a bit confused. please bare with me. i am using 120v mains.
if I^2R=V^2/R then why do I get different values and what do they mean?

I^2 * R does, as you say, equal V^2/R

The mistake you are making is to take the Imax of the LED, which is 20mA and use it in the calculation. The current through the LED is not 20mA. 20mA is the the maximum current the LED can withstand without going pop. The actual current through the LED is as per Ohms law, the supply voltage and the resistor value, so 120V / 390000 = 0.37mA, a lot less that 20mA.

120V * 0.000377A = 0.037W

Perhaps you should start by calculating the current:

I = E/R = 120 / 390,000 = 0.3ma

NOW...

P = I^2R or E^2/R or EI all end up = 36 milliwatts

This is different from PerryBebbington only because after he posted you mentioned you were using 120V mains.

Another suggestion, Physical wiring is important. You must keep the 390K and pins 1&2 of the opto, physically away from the other circuit components.

Although you said its working you should double check the Opto operating point at 0.3mA

Thank you Perry and John.

So, for the sake of completeness, given that the resistor is dissipating 36mW with a value of 390k a 1 watt resistor is more than overkill (?).

Further, I calculated my own resistor (rather than that of the original circuit) value given a peak voltage of 170 to be safe.

R = (170vpeak - 1.2forwardvoltage) / .020A = 8440 ohm (~8.5k)

P =170^2/8500 = 3.4 (need 5 watt resistor)

Using an 8.5k resistor vs a 390k resistor means that I'll lose/consume more energy due to heat correct?

I @ 8.5k =120/8500 = 14.12mA

I @ 390k = 120/390000 = 0.31mA

In my tests 390k was enough for the circuit to work, however according to the datasheet something called CTR that I don't fully understand if affected.

http://optoelectronics.liteon.com/upload/download/DS-70-96-0013/LTV-8X4%20series%20201509.pdf

Current Transfer Ratio is the current you need in the LED to produce a current in the transistor.
Worst case for this opto seems to be 20%,
meaning if you need 0.5mA collector current, you must (at least) have 2.5mA LED current.

Is that current detector circuit I gave you in the other thread still on the backburner?
The 50 ohm resistor in that dissipates <1mW for 4mA LED current.
No special or double resistors needed either, because it only has 0.2volt across.
Leo..

If your circuit is working, I think you probably have a 39K, 3.1mA, I would try a 33k, 3.6mA, 0.370 Watts, but still use a 1W resistor, it will get pretty warm. CTR, current transfer ratio is the ratio of current through the LED to current the photransistor can pass, if it were 50% and LED current was 10mA, transistor could pass 5mA (in general).

JCA34F:
If your circuit is working, I think you probably have a 39K, 3.1mA, I would try a 33k, 3.6mA, 0.370 Watts, but still use a 1W resistor, it will get pretty warm. CTR, current transfer ratio is the ratio of current through the LED to current the photransistor can pass, if it were 50% and LED current was 10mA, transistor could pass 5mA (in general).

Nope 390k 1 watt just ordered off digikey. 220k pullup resistor to 3.3v. voltage probes give me 3.2volts when mains off, and < 1 volt when mains is on. Enough for TTL logic to work. Thank you for your CTR explanation.

Wawa:
Current Transfer Ratio is the current you need in the LED to produce a current in the transistor.
Worst case for this opto seems to be 20%,
meaning if you need 0.5mA collector current, you must (at least) have 2.5mA LED current.

Is that current detector circuit I gave you in the other thread still on the backburner?
The 50 ohm resistor in that dissipates <1mW for 4mA LED current.
No special or double resistors needed either, because it only has 0.2volt across.
Leo..

You mean: Measure 50-70mA AC - Project Guidance - Arduino Forum? I didn't see a link/circuit you posted there? Are you referring to the opto/zener one? You did recommend 100k resistor, which I tried, and also worked fine.

Overall, nothing else is going to be on this section of the circuit. The SIGNAL will go directly in to a digital input of an esp8266 (lolin d1 mini pro) and be read if high/low. Given that device operates on a 3.3v signal, and TTL low is < 1v.

Honestly, I am pretty rusty with all this stuff, and I'm just trying to get an opto working with the least amount of parts and at the lowest possible current enough to provide me with a reliable TTL logic signal.

If the LED current should be 2.5mA it seems, with this circuit, I am looking at a ~68k resistor which will dissipate .211 watts

I've also attached a picture of the electrical characteristics of the ESP8266EX. It doesn't seem to tell me the amount of current that will flow when something is connected to an input. Just says Imax = 12mA

alex_fagard:
You mean: Measure 50-70mA AC - Project Guidance - Arduino Forum? I didn't see a link/circuit you posted there?
Are you referring to the opto/zener one?

You did recommend 100k resistor, which I tried, and also worked fine.

You're mixing up the voltage circuit (across the solenoid) with the current circuit (in series with the solenoid) that I described in post#3 there.

alex_fagard:
I've also attached a picture of the electrical characteristics of the ESP8266EX. It doesn't seem to tell me the amount of current that will flow when something is connected to an input. Just says Imax = 12mA

You're mixing up a pin set as input and a pin set as output.
Input pins don't take any current if the signal stays within VCC/GND of the MCU.
There only is a small pull up current if you enable pull up with pinMode.
Leo..

R = (170vpeak - 1.2forwardvoltage) / .020A = 8440 ohm (~8.5k)

P =170^2/8500 = 3.4 (need 5 watt resistor)

For future reference:

When calculating the power of a resistor connected to an AC source, E should be the RMS value of the waveform, not the peak. The Power calculated using the RMS voltage represents the amount of heat the resistor will be generating. Calculating using the peak will overstate your power dissipation.

Reason: Your mains waveform is a sine wave. The waveform is at the peak for a very short period of time then it drops all the way to zero before increasing again.

JohnRob:
When calculating the power of a resistor connected to an AC source, E should be the RMS value of the waveform, not the peak. The Power calculated using the RMS voltage represents the amount of heat the resistor will be generating. Calculating using the peak will overstate your power dissipation.

If the peak voltage is what you have, use that, then divide the power by two.

JohnRob:
For future reference:

When calculating the power of a resistor connected to an AC source, E should be the RMS value of the waveform, not the peak. The Power calculated using the RMS voltage represents the amount of heat the resistor will be generating. Calculating using the peak will overstate your power dissipation.

Reason: Your mains waveform is a sine wave. The waveform is at the peak for a very short period of time then it drops all the way to zero before increasing again.

Isn't overstating a good thing? Costs but a few cents for a larger wattage resistor.

The way to drive an optocoupler from the mains without having to dissipate significant heat is to use a capacitive dropper, and a back-to-back LED style opto coupler (or add a diode across the optocoupler to conduct in the opposite half cycle (LED reverse voltage ratings are usually only 5V).

240V into 20mA would be something like 1k5 fusible resistor in series with 0.27µF mains-rated cap
110V into 20mA say 750 ohms and 0.47µF cap.

The resistor must be fusible so it doesn't start a fire if the capacitor develops a short.

Note the if you were to use a single resistor it must be rated for high voltage, and be fusible.

Fusible resistors fail open-circuit on overload without flames.

I used this circuit for a 120V detector. For 240V, double the resistor values.
https://www.digikey.com/product-detail/en/broadcom-limited/HCPL-3700-000E/516-1545-5-ND/696045

This application note will help on selecting the resistor value

HCPL-3700 Avago Application Note.pdf (130 KB)

Paul__B:
If the peak voltage is what you have, use that, then divide the power by two.

I think you mean the square root of 2. I used 1.414 as close enough for most purposes.