← How-Tos
electronics Sep 11, 2026 ◯ 7 min read

Optocouplers and Digital Isolation for Makers: Protecting Microcontrollers from High-Voltage and Noisy Signals

optocoupleroptoisolatorpc8174n35digital isolationesp32arduinomains sensingground loopelectrical isolation

A surprising number of "why did my microcontroller just die" posts on maker forums trace back to the same root cause: a GPIO pin got directly connected to something on a different electrical reference — a mains-adjacent circuit, a motor driver's noisy ground, or a separate power domain — and a voltage spike, ground loop, or straight-up wiring mistake fried the pin or the whole board. An optocoupler (also called an optoisolator) solves this by transmitting a signal across a physical gap using light instead of a wire, which means there is no direct electrical connection at all between the two sides. It's one of the cheapest and most underused components for making a maker project genuinely robust, and this guide covers when to reach for one, how to wire the common parts, and where a full digital isolator IC is worth the extra cost instead.

How an Optocoupler Actually Isolates a Signal

Inside an optocoupler package is an LED on one side and a phototransistor (or photodiode, or more specialized photo-detector) on the other, with no electrical connection between them — only a light path across a small internal gap. Drive current through the LED, it emits light, the phototransistor on the far side detects that light and switches on, and the output signal follows the input with a small propagation delay. Because the only coupling between input and output is optical, the two sides can sit on completely different ground references, different voltage domains, or even different AC/DC systems entirely, and a fault or spike on one side has no direct electrical path to reach the other.

The Two Common Parts

PartTypeSpeedBest for PC817 (and similar EL817, LTV817)Phototransistor outputSlow (a few kHz max, tens of microseconds propagation delay)General GPIO isolation, simple on/off signals, mains zero-cross detection, opto-isolating a relay driver stage 4N35 / 4N25 / 6N137Phototransistor (4N series) or high-speed logic-gate output (6N137)4N series similar to PC817; 6N137 supports up to ~10Mbps4N series for basic isolation; 6N137 for isolating faster digital signals like UART at higher baud rates

For the overwhelming majority of maker use cases — isolating a button press, a zero-cross detection signal, a slow status line, or the input side of a relay driver — the PC817 is the default choice: it's inexpensive, available everywhere, and simple to wire. Reach for a faster part like the 6N137 only when the isolated signal itself needs real bandwidth, such as isolating a UART or SPI line running above a few kHz.

Basic Wiring: Isolating a GPIO Input

A common use case is reading a signal from a separate voltage domain — a 24V industrial sensor, a mains-referenced zero-cross detector, or another microcontroller's 5V logic feeding into a 3.3V ESP32 — without connecting the two grounds together.

Basic Wiring: Isolating a GPIO Output (Driving a Relay or External Circuit)

The same part works in reverse to isolate a microcontroller output driving something on a different voltage domain — most commonly, driving a relay coil or a mains-side solid-state relay input without exposing the microcontroller to that side's voltage at all.

  1. GPIO pin drives the optocoupler's LED through a current-limiting resistor sized for the GPIO's logic voltage (a 3.3V ESP32 GPIO driving a PC817 LED at 10mA needs roughly (3.3V - 1.2V)/10mA ≈ 220Ω).
  2. The phototransistor output switches the relay coil, SSR input, or downstream circuit, powered from that circuit's own supply rail — completely separate from the microcontroller's power rail.
  3. A flyback diode across an inductive load (a relay coil) on the isolated side is still required, exactly as it would be without isolation — the optocoupler protects the microcontroller from the isolated side's voltage domain, but it doesn't eliminate the need for standard inductive-load protection on that side.

When Isolation Actually Matters

When to Use a Dedicated Digital Isolator IC Instead

Modern digital isolator ICs (Analog Devices' ADuM series, Texas Instruments' ISOxxxx family) use magnetic or capacitive coupling instead of an LED/phototransistor pair, and they're worth the extra cost — typically a few dollars versus a few cents for a PC817 — when a project needs higher signal bandwidth (tens of Mbps), multiple isolated channels in one small package, or better propagation delay consistency for time-sensitive signals like SPI or high-speed UART. For simple GPIO-level isolation at low speed, the humble optocoupler remains hard to beat on cost and simplicity.

Practical Notes and Pitfalls

Optical isolation is one of those components that's cheap enough to use liberally and important enough that its absence is a common, avoidable cause of fried boards and mystery noise in maker projects. Any signal crossing between a microcontroller and mains power, a separately-powered system, or field wiring leaving an enclosure is a reasonable candidate for a PC817 and a couple of resistors standing between "one wiring mistake kills the whole board" and "one wiring mistake kills a fifty-cent part."