2026-09-06
An optocoupler (or optoisolator) is a tiny package containing an LED and a photodetector, separated by a transparent insulating gap. You drive the LED on the input side; the photodetector picks up the light and controls current on the output side. The two sides share no electrical connection — signals cross the gap as photons.
The point isn't to transmit light. The point is that the input and output circuits can sit at wildly different voltages. Typical isolation ratings are 2,500V to 5,000V RMS, meaning a fault on the high-voltage side won't destroy the microcontroller on the low-voltage side (or the human touching it).
Common variants:
Real-world example: A Raspberry Pi (3.3V logic) needs to read whether a 240V industrial machine is running. Wiring the mains directly to a GPIO pin would incinerate the Pi and potentially the operator. Instead, run the mains through a current-limiting resistor and the input LED of an optocoupler. The output phototransistor pulls a 3.3V GPIO line low when the LED is lit. The Pi sees a clean digital signal; there is literally an air gap between it and the 240V.
Design rule of thumb — Current Transfer Ratio (CTR): CTR is the ratio of output collector current to input LED current, expressed as a percentage. A PC817 has CTR around 50–600%, but you should design for the worst-case minimum, and derate further because CTR degrades over time (LEDs dim). A conservative rule: assume you'll get 20% of the datasheet's typical CTR after 10 years.
Quick calculation: You want 5 mA of output current to switch a transistor reliably. Datasheet says CTR = 100% typical, but you derate to 20%. Then required LED current = 5 mA / 0.20 = 25 mA. For a 5V drive with 1.2V LED forward voltage, series resistor = (5 - 1.2) / 0.025 = 152Ω, so pick 150Ω.
Optocouplers are also the traditional way to break ground loops: if two subsystems have "ground" at different potentials, an optocoupler on the signal line eliminates the loop entirely because there is no shared conductor.
