ToolSphere
All perfboard layouts

PC817 Optocoupler Input Perfboard Layout

An optocoupler passes a signal across a gap with light, so the 12 V side and the microcontroller side share no wire, not even ground. This board reads a 12 V input (a switch, a PLC output, a sensor) into a 3.3 V GPIO.

PC817 optocoupler input perfboard layoutU1 PC817R1 2k2R2 10kJ1 12V INJ2 MCU
Open this layout in the simulator Connection check: no shorts, 6 named nets

Red wires carry power, white is ground, yellow and blue are signals. Every hole is an isolated pad; connections are the wires shown. In the simulator you can move parts, add your own and re-run the check.

Parts list

As an Amazon Associate, ToolSphere earns from qualifying purchases.

How it works

Input side. The PC817's LED needs a few milliamps. With 12 V in and about 1.2 V across the LED:

I_LED = (12 V − 1.2 V) ÷ 2.2 kΩ ≈ 4.9 mA

Output side. The phototransistor pulls the output to GND when the LED is lit. A 10 kΩ pull-up to +3V3 holds it high otherwise and needs only 0.33 mA, well within what the PC817 can sink at this LED current (its current-transfer ratio is at least 50%).

So the logic is inverted: 12 V present → output LOW. Read it with an ordinary digital input (no internal pull-up needed, the 10 kΩ is on the board).

Keep the sides apart. The input side's IN− is not connected to the board's GND; that separation is the whole point. On the board, leave a clear gap between the two halves.

Building it, step by step

  1. Place the PC817 in the middle with pins 1–2 (LED) facing the input side and 3–4 facing the microcontroller side.
  2. Fit R1 2.2 kΩ from IN+ to pin 1 (anode), and wire IN− to pin 2 (cathode).
  3. Run +3V3 and GND rails on the microcontroller side only.
  4. Fit R2 10 kΩ from +3V3 to pin 4 (collector), take pin 4 to the output header, and wire pin 3 (emitter) to GND.
  5. With 12 V applied the output should read LOW; with nothing applied, HIGH.

Tools for this build

Frequently asked questions

What resistor do I need for a PC817 on 12 V?

About 2.2 kΩ: (12 − 1.2) ÷ 2200 ≈ 4.9 mA through the LED. For 24 V inputs use about 4.7 kΩ.

Why is my optocoupler output inverted?

The phototransistor pulls the output down when the LED is lit, so input on reads LOW. Invert it in code, or move the resistor to the emitter side for non-inverted output.

Do the two grounds need to be connected?

No, and they shouldn't be: keeping the input ground separate is what protects the microcontroller from the other circuit.