What is the value of resistor in optocoupler?

What is the value of resistor in optocoupler?

I will use optocoupler to isolate the output, the circuit will turn OFF the computer via the PC switch of the motherboard.

See image below..

Around 220 Ohms should do it. An optocoupler has an LED on the "input" side so it's like any other LED. Do you know how to calculate the resistor for an LED?

You can check the datasheet if you want to make some calculations, but it's usually not too critical... You need enough current to create enough light to turn-on the phototransistor, but not so much current that you fry the internal LED or the Arduino.

Impossible to determine, since you didn't divulge how much current it will be switching -- that would the amount of current that normally flows through "PC Switch" [whatever that is].

BUT, a way to either determine the resistor value, or abandon this device if turns out to be inadequate for the task:

  • Find a datasheet [I usually go to **Mouser**, or **DigiKey** [etc] and search on the Part Number [PC 817 in this case].
    This is the one I referred to: [Taiwan Semi PC 817 Datasheet](http://"http://"http://"http://"http://"http://"http://"http://"https://www.mouser.com/datasheet/2/395/TPC817 SERIES_C1612-1114502.pdf""""""""), since the Sharp datasheet was pretty dismal.
  • Look for the Current Transfer Ration [the "CTR"] -- either in one of the tables, or a graph. Often it's included in the Description, at the top, but that's typically marketing claptrap, so I only trust what's in the datasheet proper [and even then trust is a tenuous thing ;)]
  • For this part, the CTS is claimed to be "80-600%", in the Description.
    In the ELECTRICAL SPECIFICATIONS (TA = 25°Cunless otherwise noted) table, it's shown that 80-600% is the 5mA case, where VCE is 5V.
    BUT, Figure 3, Figure 5 & Figure 6, tell much more of the story [along with Fig 7 & Fig 8 when yer taking temperature into consideration].
  • So, lets do a for instance: Say your "PC Switch" runs at a maximum of 7mA. Figure 3 shows that we need around 6 to 7mA of Forward Current through the Isolators internal LED, in order to put the internal Output Transistor into Saturation [the same as saying all-the-way-on]. So, for an IC of 7mA or less, this thing will be "ON" with a 6 - 7mA input current -- that, BTW, is a CTR of around 100%. And, in fact, if you look at Figures 5 & 6, you also get a value of around 100% - $#!T$ and Grins!!
    If we look at Figure 4, we see that at around 6 - 7mA, the LED's Forward Voltage will be around 1.1V at 25°C. SOOO...that resistor you asked about would have a value of [using 7mA as the forward current]:
[b]R[/b] = (5V - 1.1V)/7mA = [b]557Ω[/b]
  • Now, lets say your "PC Switch" sucks down up to 50mA. According to Figure 1, as long as the Ambient Temperature never goes above about around 50°C, this part is still within it's usable range, but that's the absolute max! Figure 3 doesn't even include 50mA. Figure 6 makes it look a bit scary to run this Isolator at 50mA! But, what the heck -- other indications are that the manufacturer approves :wink:
  • Figure 5* shows a CTR of around 110% at Forward Current of 50mA, so it's probably safe to assume that when IC is at 50mA, which is our design target, the CTR will also be at around 110% -- 'cuz, 110% is nearly 100%, so we're in the ballpark. So, using 110% as the CTR, that makes the needed Forward Current [for an IC of 50mA] right about:
[b]I[sub]F[/sub][/b] = I[sub]C[/sub]/110% = 50mA/1.1 = [b]45mA[/b]

Which, my friend, it a bit too much for the UNO. An UNO output is spec'ed to drive 40mA ABSOLUTE MAX -- with 20mA being the Recommended MAX.

And that, as they say, is how you do it!

BTW: When I say "Isolator", it mean OptoCoupler.

To be honest in this case , I would just use a small relay driven off a transistor from the Arduinoand powered off your power supply. The contacts are isolated and will switch the PC without any worry about whether it can operate the switching , polarities and so on.You can buy modules off eBay very cheaply that will do the job .

Google : arduino relay driver

A quick google actually shows you can buy 5v Reed type relays which will do the job and have coil resistance >250ohm, so you can drive direct from an Arduino pin without a transistor .
Look at Farnell for examples.

Mm, I would not.... Opto is easy for this. An I would grab a 470Ohm. Not to critical, current will be low.

The other thing I have picked up from optocoupler datasheets is they get worse with age. As you use them, the CTR drops.

Of course the datasheet never says how bad this problem is. They all try to say that theirs is better than the competition but that is really just admitting that they all have the same problem.

I have seen rule-of-thumb guidelines to take the worst figure in the datasheet and add 100% for ageing.

MorganS:
The other thing I have picked up from optocoupler datasheets is they get worse with age. As you use them, the CTR drops.

Of course the datasheet never says how bad this problem is.

Interesting. I got my first notion of this when I searched for a datasheet for the PC 817, for this post, which led me to the following Sharp datasheet, that admits the very thing:

https://www.mouser.com/datasheet/2/365/PC817XxNIP1B_12Oct16_Spec_ED-16P011-1360323.pdf
On the page titled "Precautions for PhotoCouplers" Section 2