Choosing the correct resistor to be used with an optocoupler

Thread Starter

Ping pong

Joined Feb 13, 2022
78
Hey, I'm working on a small Arduino project that basically turns on two relays when a few 12v triggers are active.
Since a nano will probably fry instantly if the 12v trigger wire is directly connected to it, i used to use a 5v1 Zener diodes coupled with a few resistors to step down voltage to 5v. However, I've recently discovered these amazing little parts called optocoupler that'll isolate the nano from the trigger source, lowering the chances of me frying it even more.
Although they are cool and all, I'm kinda confused on what type of resistor should be used on the led side, R1 and R2 in this case (schematic shamelessly copied from a different thread)
1705856163803.png
I've watched numerous yt videos on how to calculate the correct resistor value. some simply suggest using ohms law [(12v-1.2v)/0.05] while other suggest that this isn't enough and you should always choose a larger resistance value from what you have calculated. Other mention something about the wattage of the resistor and how it should be greater too than the load, all of which has confused me to death.
Hence why I'm here again, looking for some guidance :) Your input will be much appreciated!
 

Dodgydave

Joined Jun 22, 2012
11,302
Your drawing shows 2.5V led supply, that won't make the led work, if its on a 5V supply use 120 to 330 ohms resistors.
For 12V supply use 470 to 1K ohms.
 

Dodgydave

Joined Jun 22, 2012
11,302
Subtract the led voltage from the supply voltage, this gives the Voltage across the resistor, and divide it by the led current, that will give you the resistance to use.

So if your led has a 2.8V drop and needs 20mA,, then on a 5V supply// 5-2.8= 2.2V /20mA = 110 ohms.

Wattage can be found by V x I or I^R as explained by @Papabravo
 
Last edited:

Papabravo

Joined Feb 24, 2006
21,225
The second part of the question is to calculate the power being dissipated by the resistor. To get the power in watts, square the current and multiply by the resistor's value. Thus:

\( P\;=\;I^2R\;=\;(.020)^2\cdot110\;\Omega\;=\;44\times10^{-3}\text{, or }44\text{ milliwatts} \)

A 1/8 watt resistor will handle the job just fine. You can go bigger but never smaller.
 

tonyStewart

Joined May 8, 2012
131
Subtract the led voltage from the supply voltage, this gives the Voltage across the resistor, and divide it by the led current, that will give you the resistance to use.

So if your led has a 2.8V drop and needs 20mA,, then on a 5V supply// 5-2.8= 2.2V /20mA = 110 ohms.

Wattage can be found by V x I or I^R as explained by @Papabravo
This 2.8V is incorrect for an IR LED. It will be < 1.2V at <= 5mA (and < 1.4V at 20 mA.)
The plots show maximum CTR at @ 25'C around Ic= 2.5mA but the front page indicates a guarantee of ;
CTR : MIN. 50% at If =5 mA for Vce =5V. However when using the output as a saturated switch Vce=Vce(sat) CTR due to the transistor hFE will reduce to around 10% of the peak CTR where a "typical" of CTR=670% would become 67% but they guarantee 50% only at Vce =5V and not Vce < 0.7V where it is saturated. They do not include all cold temp. thermal effects in their table specs. either, only 25'C, so a more conservative wide temp range design spec to use is CTR=10% .
1706282101233.png

You best bet is to use between 2.5 mA to 5 mA input and choose Rc for CTR = 5% to 20% of Iin. depending on your output voltage threshold. Note they tend to use 5% in examples like below = Ic/If. I tend to use 10% CTR saturated for most designs.
1706282591889.png
Next to compute Resistors:

Rin = (Vin- Vf) / Iin For Vin =2.5V, Vf = 1.2V, Iin= 5mA, Rin = 1.3/5m = 260 ohms. Your Lock driver may have Rs= 25 to 50 ohms = Vol/Io so choose the difference. e.g. Rs = 220 Ohm

Rout = (Vcc-Vout)/Iin/10%, for Vcc=12V, Vout=0.1V, Iin=5mA, CTR(sat)=10% then Rout ~ 12/5m/10%= 24 kohm
 

Audioguru again

Joined Oct 21, 2019
6,688
The LED in the opto-coupler is not a visible one, instead it is a low-forward voltage infrared one. Sharp's PC817 datasheet shows a typical forward voltage of 1.2V at 20mA with a maximum peak voltage of 3V at 0.5A! They show extremely short durations at the high current.
 
Top