Optocoupler Resistor Calculation: PC817 and CTR Design

Devre Tasarımı ve Uygulama Notları Advanced 12 min read Published:
Optokuplör direnç hesabı: PC817 ve en kötü durum CTR tasarımı kapak görseli, LED ve fototransistör sembolü

Calculating optocoupler resistors takes two steps: the input resistor is chosen with the formula (Vin − VF) / IF so that the desired forward current (IF) flows through the LED; the pull-up resistor on the output is chosen large enough that it demands less current than the collector current the phototransistor can deliver in the worst case (IF × CTRmin). The calculation must use the minimum CTR from the datasheet and also account for the LED’s light loss over the years and for temperature. This article calculates, step by step, a circuit that carries a 24 V signal to a 3.3 V microcontroller through a PC817, and shows when the 4N35 and 6N137 are the better choice.

What is an optocoupler and how does it work?

An optocoupler (optoisolator) is a semiconductor device that carries a signal from one circuit to another by light, leaving no electrical connection between the two circuits. On the input side there is an infrared LED, and on the output side a light-sensitive receiver. In the PC817 and 4N35 the receiver is a phototransistor; as the current through the LED increases, the collector current the phototransistor can conduct also increases. In the 6N137, the receiver is a fast photodetector IC whose output is an open-collector logic gate.

Because it can keep the grounds of the two sides separate, an optocoupler is used to isolate 24 V industrial sensor inputs, signals from mains-connected circuits or a noisy motor driver from a microcontroller. This isolation only works when the two sides are truly powered separately: if you connect the input and output grounds to the same point, the isolation is lost.

What is CTR (current transfer ratio)?

CTR (Current Transfer Ratio) is the ratio of the phototransistor’s collector current to the LED forward current, given as a percentage: CTR = IC / IF × 100%. A CTR of 200% means that when 5 mA flows through the LED, the phototransistor can conduct up to 10 mA. Like the current gain of transistors, CTR varies over a wide range from part to part; it also depends on the LED current, temperature and the age of the part. That is why the design is based on the minimum value in the datasheet, not the typical value.

Pin numbers and pin functions of the 4-pin PC817, 6-pin 4N35 and 8-pin 6N137 optocouplers
Figure 1. Pin connections of the three optocouplers (top view). PC817: 1 anode, 2 cathode, 3 emitter, 4 collector. 4N35: 1 anode, 2 cathode, 3 no connection, 4 emitter, 5 collector, 6 base. 6N137: 2 anode, 3 cathode, 5 GND, 6 output, 7 enable, 8 VCC.

PC817, 4N35 and 6N137 parameter table

Values are taken from the manufacturers’ datasheets (Sharp PC817X series, Fairchild/onsemi 4N25–4N37 family, Avago 6N137). Unless otherwise stated, they apply at 25 °C.

Parameter PC817X3 4N35 6N137
Output type Phototransistor Phototransistor, base pin brought out Open-collector logic output with enable input
Package 4-pin DIP 6-pin DIP 8-pin DIP
CTR or threshold 200–400% (IF = 5 mA, VCE = 5 V; rank C) Min 100% (IF = 10 mA, VCE = 10 V); min 40% at −55 °C and +100 °C Threshold current typ 2 mA, max 5 mA
LED forward voltage (VF) Typ 1.2 V, max 1.4 V (20 mA) Typ 1.18 V, max 1.50 V (10 mA) Typ 1.5 V, max 1.75 V (10 mA)
Maximum LED current (continuous) 50 mA 60–100 mA depending on package option 20 mA (average)
LED reverse voltage limit 6 V 6 V 5 V
Output voltage limit VCEO 80 V VCEO 30 V VO 7 V, supply 4.5–5.5 V
Saturation voltage Max 0.2 V (IF = 20 mA, IC = 1 mA) Max 0.3 V (IF = 10 mA, IC = 0.5 mA) VOL max 0.6 V (13 mA)
Switching speed tr typ 4 µs, tf typ 3 µs; both max 18 µs (VCE = 2 V, IC = 2 mA, RL = 100 Ω) Turn-on and turn-off typ 2 µs, max 10 µs (non-saturated, IC = 2 mA, RL = 100 Ω) Propagation delay typ 48–50 ns, max 75 ns; typ 10 MBd
Isolation voltage 5.0 kV rms (1 minute) 5300 V rms (1 minute, black package) 3750 V rms (1 minute, UL1577)
Operating temperature −30 to +100 °C −55 to +100 °C −40 to +85 °C

The digit at the end of PC817 indicates the CTR rank. According to the model table in the datasheet, “3” is rank C: at IF = 5 mA and VCE = 5 V the collector current is 10–20 mA, meaning the CTR is between 200% and 400%. For the unranked PC817X, the range under the same conditions is 2.5–30 mA (50–600%). If you do not know the rank of the part you are designing with, you must use 50%.

Three factors that reduce CTR

The minimum CTR in the datasheet is the value a new part delivers at a specific LED current and at 25 °C. In a real circuit, three factors pull this value down:

  • LED aging: In the design notes of the PC817 datasheet, Sharp states that the light output of optocoupler LEDs decreases over time and, as a general guideline for long-term use, asks that a 50% loss over 5 years be taken into account. The 6N137 datasheet also recommends an LED current of 6.3–10 mA and states that this range leaves at least a 20% LED aging margin. Sharp’s note concerns LED light output; treating the same loss as CTR loss in this article is an approximation.
  • Temperature: CTR changes with temperature. The 4N35 datasheet gives this as a guaranteed value: the CTR, at least 100% at 25 °C, is at least 40% at −55 °C and +100 °C. The PC817 datasheet shows the temperature effect only as a typical curve (relative CTR vs. ambient temperature graph); in that case the designer sets the margin.
  • LED current: CTR does not stay constant with LED current; the CTR vs. IF curve in the datasheet shows this. The PC817 datasheet also states that CTR variation increases when IF falls below 1 mA. To benefit from the guaranteed value, the safest approach is to drive the LED at or near the current at which the CTR is specified.

There is also the saturation effect: CTR is measured at a non-saturated operating point such as VCE = 5 V. In a switching circuit, however, the phototransistor is driven into saturation, and at a VCE of around 0.2 V the current it can conduct is lower. For this reason, in practice it is recommended to leave an additional margin of 1.5–2× between the current demanded by the pull-up resistor and the current calculated from the CTR; this is not a datasheet requirement but a common design rule.

Typical application: from a 24 V input to a 3.3 V microcontroller

The circuit below carries a 24 V switch or sensor output through a PC817 to the input of a microcontroller running at 3.3 V. On the input side, series resistor R1 sets the LED current, and diode D1, connected in reverse parallel with the LED, protects against reverse connection. On the output side, pull-up resistor R2 pulls the collector up to 3.3 V. When the LED is on, the phototransistor turns on and the output goes to logic 0; this connection inverts the signal.

Schematic of a circuit carrying a 24 V input through a PC817 optocoupler to a 3.3 V microcontroller input: 3.6 kΩ series resistor, reverse-parallel 1N4148 diode, 2.2 kΩ pull-up resistor and separate grounds
Figure 2. 24 V input circuit with the PC817. The dashed line is the isolation boundary; GND1 and GND2 are not connected to each other. Pin numbers match the PC817 datasheet.

Step 1: Input resistor (R1)

Assume the input can vary between 20 and 28 V. We set the LED current to stay around 5 mA, where the PC817’s CTR is specified. The lowest current occurs at the lowest input voltage and the highest VF:

  • R1 = (20 V − 1.4 V) / 5 mA = 3.72 kΩ → the next lower standard value, 3.6 kΩ, is chosen.
  • Lowest LED current: (20 − 1.4) / 3600 = 5.17 mA. A 5% tolerance resistor at its upper limit (3.78 kΩ) reduces the current to 4.92 mA; this difference stays within the margins below, but you can use a 1% tolerance resistor if you prefer.
  • Highest LED current (28 V, worst case ignoring VF): 28 / 3600 ≈ 7.8 mA. This is far below the 50 mA limit.
  • R1’s power in the worst case is 28² / 3600 ≈ 0.22 W. A quarter-watt resistor would be at its limit; choosing 0.5 W leaves headroom for heating.

The PC817’s LED reverse voltage limit is 6 V. If the cable on a 24 V line is connected in reverse, the LED easily exceeds this limit. D1 (a small-signal diode such as the 1N4148) conducts under reverse voltage and holds the reverse voltage across the LED at about 0.7 V; the current is still limited by R1 at that time.

Step 2: Worst-case CTR budget

For the PC817X3, the starting point is a minimum CTR of 200%. We derate it twice:

  1. 50% loss for LED aging: 200% × 0.5 = 100%.
  2. An additional factor of 0.5 for temperature (this is an assumption in this article, since the PC817 datasheet gives no guaranteed temperature value; check the relative CTR curve in the datasheet for your own temperature range): 100% × 0.5 = 50%.

The current the phototransistor can conduct in the worst case: IC,min = 5.17 mA × 0.50 ≈ 2.6 mA.

Worst-case CTR budget for the PC817X3: 10.3 mA at the start, 5.2 mA after aging, 2.6 mA after the temperature margin and the 1.4 mA demanded by the pull-up resistor
Figure 3. In the example circuit, the collector current the phototransistor can conduct decreases as each margin is deducted. The last column is the current the 2.2 kΩ pull-up resistor demands to pull the output to logic 0.

Step 3: Pull-up resistor (R2)

When the phototransistor is on, the current through R2 is (3.3 V − VCE(sat)) / R2. This current must stay clearly below 2.6 mA:

  • Smallest R2 = (3.3 − 0.2) / 2.6 mA ≈ 1.19 kΩ. The 0.2 V here is the maximum saturation voltage given in the datasheet under the condition IF = 20 mA and IC = 1 mA; it is not guaranteed at a 5 mA LED current, and the margin below covers this difference too.
  • 2.2 kΩ is chosen for saturation margin. The demanded current becomes 3.1 / 2200 ≈ 1.41 mA; compared with the 2.6 mA available, this leaves a margin of about 1.8×.
  • In cutoff (LED off), dark current pulls the output down. In the PC817 this current is at most 100 nA at 25 °C and 50 V; across 2.2 kΩ it causes a 0.22 mV drop. Dark current increases with temperature, but even if it rises to 10 µA the drop is 22 mV and the logic 1 level is not affected.

A larger pull-up resistor eases the current budget but slows switching. The 4 µs / 3 µs rise and fall times in the datasheet are measured with a 100 Ω load; the response time vs. load resistance graph shows that these times lengthen markedly as the load resistance rises into the kilohm range. Choosing 47 kΩ for R2 on the idea that “the bigger, the less current” slows the signal unnecessarily.

How is the same circuit calculated with the 4N35?

The advantage of the 4N35 is that it gives a guaranteed lower limit over temperature: the CTR is at least 40% at the extremes of −55 °C and +100 °C (the datasheet gives no separate values for the temperatures in between; according to the typical curves, CTR is higher there). Since this value is specified at IF = 10 mA, we drive the LED at 10 mA:

  • R1 = (20 − 1.5) / 10 mA = 1.85 kΩ → 1.8 kΩ; lowest IF = 18.5 / 1800 ≈ 10.3 mA.
  • Worst-case CTR: 40% × 0.5 (aging; we use the margin recommended by Sharp here as an assumption as well) = 20%; IC,min = 10.3 mA × 0.20 ≈ 2.06 mA. With a 2.2 kΩ pull-up, the margin is only about 1.5×. Raising R2 to 3.3 kΩ is the better choice: taking the datasheet’s 0.3 V (under the condition IC = 0.5 mA, IF = 10 mA) as the 4N35’s saturation voltage, the demanded current is (3.3 − 0.3) / 3300 ≈ 0.91 mA and the margin is about 2.3×.
  • The higher LED current raises R1’s power at 28 V to 28² / 1800 ≈ 0.44 W. A 1 W resistor is required, and the power dissipated per input is about twice that of the PC817 circuit.

Pin 6 of the 4N35 is the phototransistor’s base. In noisy environments, a floating base pin can pick up interference. A resistor connected between base and emitter speeds up turn-off and raises the noise threshold, but it reduces the effective CTR by diverting part of the base current generated by light in the phototransistor to the emitter; if you use this resistor, recalculate the CTR budget. On the output side, the 4N35’s VCEO limit is 30 V; on the PC817 it is 80 V.

When speed is needed: 6N137

Phototransistor optocouplers switch on and off on the order of microseconds. That is enough for slow signals such as switches, relay contacts and 24 V sensor inputs. If a fast UART, SPI or PWM signal must be isolated, you move to a logic-output optocoupler such as the 6N137. According to the datasheet, its propagation delay is typically 48–50 ns, at most 75 ns at 25 °C, and its typical data rate is 10 MBd.

There is no CTR calculation with the 6N137; when the LED current exceeds a threshold, the output goes to logic 0. The points to watch in the design are stated clearly in the datasheet:

  • The output side is powered from 4.5–5.5 V (pin 8 VCC, pin 5 GND), and a 0.1 µF ceramic decoupling capacitor must be connected between these two pins, as close to the pins as possible.
  • The threshold current is at most 5 mA. For best performance and at least a 20% LED aging margin, the manufacturer recommends an LED current of 6.3–10 mA; the upper limit of the recommended operating range is 15 mA, and the absolute average limit is 20 mA.
  • The output is open collector and is taken from pin 6; the recommended pull-up resistor is between 330 Ω and 4 kΩ.
  • If the enable pin (pin 7) is left floating or set to logic 1, the output follows the LED (logic 0 when the LED is on); if it is set to logic 0, the output stays at logic 1 regardless of the LED. The datasheet allows leaving it floating; in noisy environments, connecting the pin to VCC is common practice.

For example, for a 6N137 driven from a 5 V logic output, R1 ≈ (5 − 1.5) / 8 mA ≈ 440 Ω. With 430 Ω, the current is about 8.1 mA at typical VF and about 7.6 mA at the highest VF (1.75 V); both are within the recommended 6.3–10 mA range. Also take into account that the driver output will drop slightly below 5 V under load.

Which optocoupler should you choose?

PC817X3Sharp Microelectronics · EE01364$0.11910 In StockView

4N35onsemi · EE01334-1$0.1565 In StockView

6N137Broadcom Limited · EE01811$0.488 In StockView
  • PC817X3: Thanks to its narrow CTR rank (200–400%), it works with a low LED current, and it has an 80 V VCEO and a small 4-pin package. It suits slow signals such as multi-channel digital input boards, PLC-style 24 V inputs and feedback in switching power supplies.
  • 4N35: It has a guaranteed lower CTR limit at the extremes of −55 °C and +100 °C and a base pin brought out. It is a good reference part for academic or industrial designs where you want to close the calculation over a wide temperature range with a datasheet guarantee.
  • 6N137: For digital communication signals in the megabaud range. It requires a 5 V supply and a decoupling capacitor on the output side.

For other options, see the Transistor Output Optocouplers and Logic Output Optocouplers categories. If you are powering the isolated side with a linear regulator, the 7805 vs. AMS1117 comparison article explains regulator selection.

Common mistakes

  • Calculating with the typical CTR: The circuit works on the bench, but in the field a few years later or on a cold morning the output fails to go to logic 0. The calculation must always use the minimum CTR.
  • Assuming a narrow rank for a PC817 of unknown rank: The lower limit of the unranked PC817X is 50%; a circuit calculated assuming 200% can end up with a quarter of the needed current.
  • Forgetting reverse voltage protection: The reverse voltage limit of the LEDs is 5–6 V. A line carrying alternating voltage or one that may be connected in reverse needs a reverse-parallel diode.
  • Joining the grounds of the two sides: If the grounds are joined, the isolation is lost. Sufficient clearance must also be left on the board between the copper areas of the input and output sides.
  • Not checking resistor power: As the LED current increases, the series resistor on 24 V inputs can exceed a quarter watt; in the example 4N35 circuit, it rose to 0.44 W for 10 mA.
  • Skipping the decoupling capacitor on the 6N137: The datasheet makes the 0.1 µF capacitor between pins 5 and 8 mandatory.

Frequently asked questions

How is the PC817 input resistor calculated?

With the formula R = (Vin − VF) / IF. For the PC817, VF is typically 1.2 V and at most 1.4 V. Because the CTR is specified at 5 mA, most designs choose an IF of around 5 mA. To drive it from a 5 V microcontroller output, using the highest VF gives (5 − 1.4) / 5 mA = 720 Ω; 680 Ω can be used as the standard value. Check in the microcontroller’s datasheet the output pin’s voltage under load and that it can supply this current.

What value should the pull-up resistor on an optocoupler output be?

The pull-up resistor is chosen large enough that the current (VCC − VCE(sat)) / R stays below the worst-case IF × CTRmin, and small enough not to slow switching unnecessarily. In this article’s 24 V → 3.3 V example, the result is 2.2 kΩ. There is no single correct value; it depends on the LED current, the CTR rank and the supply voltage.

What does the “3” in PC817X3 mean?

It indicates the CTR rank. According to the Sharp datasheet, the PC817X3 is rank C: at IF = 5 mA and VCE = 5 V the collector current is 10–20 mA, meaning the CTR is between 200% and 400%. For the unranked PC817X, the range under the same conditions is 50–600%.

Can a 4N35 be used instead of a PC817?

Functionally yes, but the package and pinout are different (6 pins instead of 4), and the CTR is specified at a different current. To guarantee the same output current with the 4N35, the LED current must be raised and the input resistor recalculated; in the example circuit, this meant a 1.8 kΩ / 1 W input resistor instead of 3.6 kΩ and a 3.3 kΩ pull-up instead of 2.2 kΩ.

Conclusion

The reliability of an optocoupler circuit depends on choosing two resistors correctly. The input resistor must supply the LED current at which the CTR is specified even at the lowest input voltage; the pull-up resistor must allow the phototransistor to saturate even with the lowest CTR remaining after aging and temperature. In the example, a 3.6 kΩ / 0.5 W input resistor and a 2.2 kΩ pull-up for the PC817X3 left a margin of about 1.8× across the 20–28 V range. For designs that need a datasheet guarantee over a wider temperature range the 4N35 is the better choice, and for fast digital signals the 6N137.

References

Products in this article

More from Devre Tasarımı ve Uygulama Notları