Component guide · Intermediate · 3 min read
Optocouplers
How the PC817 Isolates Circuits
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
An optocoupler contains an LED and a light-sensitive transistor in one package with no electrical connection between them. Turning on the LED switches the transistor, so a signal crosses between two circuits that do not share ground. The common PC817 needs a resistor on its LED (about 330 Ω to 1 kΩ from 5 V) and a pull-up on its output transistor for a clean logic signal.
Key specs at a glance
- Input
- Infrared LED, forward voltage about 1.2 V, 5 to 20 mA
- Output
- Phototransistor, up to 35 V, 50 mA
- CTR
- Current transfer ratio 50 to 600% (PC817 grades A to D)
- Isolation
- About 5000 V RMS for 1 minute (PC817)
- Speed
- Tens of kHz; use 6N137-type parts for fast signals
- Package
- 4-pin DIP; 4-channel PC847
Why isolate?
keep a mains-side circuit (such as a zero-cross detector or a relay driver on a high-voltage board) separate from the low-voltage microcontroller.
stop motor or relay noise on one ground from upsetting a sensitive circuit.
read a 12 or 24 V industrial sensor or PLC output with a 3.3 V microcontroller.
a fault on the far side destroys a cheap optocoupler instead of your board.
The relay modules many people use have a PC817 on the input for exactly this reason; see relay modules.
Wiring a PC817 as an isolated input
| PC817 pin | Function | Connect to |
|---|---|---|
| 1 (anode) | LED + | Signal source through a resistor (for 24 V input, about 2.2 kΩ) |
| 2 (cathode) | LED - | Source ground |
| 4 (collector) | Output | Microcontroller input pin and a 10 kΩ pull-up to 3.3 or 5 V |
| 3 (emitter) | Output ground | Microcontroller ground |
- 1 (anode)
- Function:
- LED +
- Connect to:
- Signal source through a resistor (for 24 V input, about 2.2 kΩ)
- 2 (cathode)
- Function:
- LED -
- Connect to:
- Source ground
- 4 (collector)
- Function:
- Output
- Connect to:
- Microcontroller input pin and a 10 kΩ pull-up to 3.3 or 5 V
- 3 (emitter)
- Function:
- Output ground
- Connect to:
- Microcontroller ground
Choosing the resistors
LED resistor: R = (Vin - 1.2 V) / I. For a 5 V source at 10 mA: (5 - 1.2) / 0.01 = 380 Ω, so 330 or 390 Ω. For 24 V at 10 mA: about 2.2 kΩ, rated 0.25 W or more. Output pull-up: 4.7 to 10 kΩ. The output current must stay below LED current x CTR; with 10 mA in and a CTR of at least 50%, the transistor can sink 5 mA, so a 10 kΩ pull-up (0.33 to 0.5 mA) switches cleanly. The output is inverted: LED on pulls the pin LOW.
Speed and other types
The PC817 switches in a few microseconds to tens of microseconds, fine for buttons, sensors and slow PWM, but too slow for fast serial links. Use a high-speed logic optocoupler (6N137, HCPL-2601) for UART or SPI isolation, or a digital isolator chip for very high speeds. For switching AC loads, a triac optocoupler (MOC3021 or MOC3041) drives a triac; this is how many SSRs work. See SSR vs relay.
Try it: LED resistor calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- No series resistor on the LED side.
- Joining the two grounds, which defeats the isolation.
- Forgetting the output is inverted.
- Using a PC817 for fast serial or high-frequency PWM.
- Too large a pull-up for the CTR, so the output never goes fully low.
Frequently asked questions
What does an optocoupler do?
It passes a signal between two circuits using light, so the circuits do not share an electrical connection or ground.
What resistor do I need for a PC817?
About 330 to 390 Ω for a 5 V input at 10 mA, and around 2.2 kΩ for 24 V. Use a 4.7 to 10 kΩ pull-up on the output.
Is the PC817 output inverted?
Wired with a pull-up on the collector, yes: when the LED is on, the output goes LOW.
Can an optocoupler switch AC mains?
A triac-output optocoupler such as the MOC3041 can trigger a triac that switches AC, but mains circuits need proper isolation, layout and safety knowledge.
How fast can a PC817 switch?
Up to roughly tens of kHz in typical circuits. Use a 6N137 or a digital isolator for faster signals.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 161 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.



