Optocoupler
An optocoupler, or opto-isolator, passes a signal between two circuits with light: an LED inside shines on a phototransistor across a sealed gap, so the two sides share no wire at all. How much output current the LED’s current buys is its current transfer ratio, so at 50% CTR, 10 mA in gives 5 mA out.
CTR = IC ÷ IF × 100%
where IC is the phototransistor’s collector current and IF the LED’s forward current.
A common PC817 isolates its sides to 5,000 V.
What is an optocoupler?
An optocoupler is a chip that carries a signal from one circuit to another as light, so the two circuits can work at very different voltages with no electrical connection between them.
Current through the input’s LED makes the output’s phototransistor conduct. Figure 1 shows the output following the LED, and why too little LED current leaves it stuck halfway.
1 mA in the LED: light crosses the gap and the phototransistor can pass 1 mA. Pulling 5 V down through 10 kΩ needs only 0.48 mA, so it turns fully on: 0.2 V, LOW.
How does an optocoupler work?
An optocoupler works with an infrared LED and a light-sensitive transistor facing each other in one sealed package; light from the LED does the job a base current normally would.
The clear insulation between them withstands thousands of volts, 5,000 V for a PC817, while light passes freely. No light reaches the transistor from outside, so only the LED can switch it.
What is an optocoupler’s CTR?
The current transfer ratio is the output current you get for each unit of LED current, as a percentage: 100% means 1 mA in gives 1 mA out.
It varies hugely between parts, from 50% to 600% for a PC817, and drops as the LED ages. So choose the output’s pull-up resistor for the weakest CTR, as Figure 2 shows.
10 kΩ pull-up: pulling the output low needs 4.8 V ÷ 10 kΩ = 0.48 mA, and the weakest part offers 1 mA, so the output reads 0.2 V, LOW. A sound choice.
What optocoupler outputs are there: transistor, Darlington, triac or photovoltaic?
Optocouplers differ in what sits opposite the LED: a phototransistor for general signals, a Darlington pair for more gain, a logic gate for speed, a light-triggered triac for mains, or photovoltaic cells to drive a MOSFET.
Triac-output parts fire a larger triac; photovoltaic ones make up a solid-state relay’s insides, stacking tiny photodiodes to make several volts at microamps. Figure 3 compares them.
Phototransistor, such as the PC817, 4N35: for general on-off signals, such as a button or a mains detector, up to tens of kilohertz.
Why use an optocoupler?
Optocouplers are used to keep dangerous or noisy voltages away from delicate circuits, and to connect circuits whose grounds must stay apart.
They sense mains from a safe low-voltage side, protect a microcontroller from motor and relay spikes, break ground loops that cause hum, and link 3.3 V and 12 V logic. Every MIDI input uses one, so connected instruments never share a ground.
How do you connect an optocoupler to an Arduino?
To connect an optocoupler to an Arduino, drive the LED from an output pin through a resistor, and connect the phototransistor from an input pin to ground, with a pull-up resistor or the pin’s internal pull-up.
On a PC817, pin 1 is the LED’s anode, pin 2 its cathode, pin 3 the emitter and pin 4 the collector. The two sides should have separate supplies and grounds, or the isolation does nothing. An Arduino then reads LOW whenever the LED is lit.
How do you size an optocoupler’s resistor and find its CTR?
To size an optocoupler’s resistor, subtract the LED’s 1.2 V from the pin voltage and divide by the current, (5 − 1.2) ÷ 0.01 = 380 Ω; for the CTR, divide the output current by the LED current.
Example 1: the input resistor
A 5 V microcontroller pin drives an optocoupler’s LED, which drops 1.2 V. What resistor runs it at about 5 mA?
- Given
- a 5 V pin driving an optocoupler’s LED, which drops 1.2 V, at about 5 mA
- Find
- its series resistor
- Solution
- R = (5 V − 1.2 V) ÷ 5 mA = 760 ΩThe next standard value up, 820 Ω, gives 4.63 mA
- Answer
- 820 Ω
Example 2: measuring CTR
With 5 mA in its LED, an optocoupler’s phototransistor passes 5 mA. What is its CTR?
- Given
- 5 mA into an optocoupler’s LED, and 5 mA out of its phototransistor
- Find
- its current transfer ratio
- Solution
- CTR = IC ÷ IF × 100% = 5 mA ÷ 5 mA × 100% = 100%
- Answer
- 100%
Summary
Key equations
- CTR = IC ÷ IF × 100% current transfer ratio
- R = (Vpin − 1.2 V) ÷ IF the input resistor
- IC ≥ V ÷ Rpull-up to pull the output low
Key terms
- Isolation
- No electrical path between sides.
- CTR
- Output current per input current.
- Phototransistor
- A transistor switched by light.
- Ground loop
- Unwanted current through shared grounds.
Practice problems
-
What carries the signal across an optocoupler?
An LED shines on a phototransistor across a sealed gap; no wire joins the two sides.
-
10 mA into the LED gives 5 mA out. What is the CTR?
CTR = 5 mA ÷ 10 mA × 100% = 50%.
-
A 5 V pin drives an optocoupler’s 1.2 V LED at 10 mA. What resistor?
(5 V − 1.2 V) ÷ 0.01 A = 380 Ω; the next standard value up is 390 Ω.
-
Why design the output for the lowest CTR on the datasheet?
Any part you buy, or the same part years later, may only reach the lowest figure.
-
Which kind of optocoupler switches a triac for mains loads?
Parts like the MOC3021 have a light-triggered triac that fires a larger triac.
FAQ
What is a photovoltaic-output optocoupler?
One whose output is a stack of tiny photodiodes instead of a transistor: light from its LED makes several volts at a few microamps, enough to switch on a MOSFET’s gate, as inside many solid-state relays.
What is the difference between an optocoupler and a relay?
A relay switches with moving metal contacts and a coil; an optocoupler uses light and a semiconductor, so it is silent, fast and never wears out, but carries less current.
Is an optocoupler the same as an opto-isolator?
Yes, the names are used for the same part, sometimes called a photocoupler too.
How fast is an optocoupler?
A phototransistor type like the PC817 manages tens of kilohertz; logic-output types like the 6N137 reach about 10 Mbit/s.
Why is my optocoupler’s output stuck halfway?
The phototransistor isn’t passing enough current for the pull-up: raise the LED current or use a bigger pull-up resistor.
Does an optocoupler invert the signal?
With the usual pull-up wiring, yes: LED on gives a LOW output. Swap to a pull-down on the emitter for a non-inverted output.
What does the PC817 do?
It is a common, cheap single-channel optocoupler with a phototransistor output and 5,000 V isolation.
Can an optocoupler pass analog signals?
Roughly, since its CTR isn’t linear or stable; special linear optocouplers with feedback photodiodes do it accurately.