The input side is an LED that needs a series resistor, and the output side is a transistor that needs a pull-up resistor.
What the message means
The two sides are electrically separate. The LED lights when current flows, and the transistor then pulls the output line low.
Fix it in this order
- Put a resistor in series with the input LED, chosen from the supply voltage and the LED current in the datasheet.
- Connect a pull-up resistor from the output (collector) to the supply on the output side, and the emitter to the output ground.
- Check the pin order and which side is the LED.
- Remember the output is inverted: the line goes low when the LED is on.
- Keep the two grounds apart if you want isolation.
- Check the speed, since a basic optocoupler is slow for fast signals.
Why it happens
An optocoupler passes a signal by light, so the two sides share no electrical connection. The input side is an LED, which needs a resistor to set its current, and the output side is a transistor that does nothing until light reaches it.
The output transistor can only pull its pin low. It needs a resistor to the supply to make the pin high when it is off. How much current the LED needs for a given output current is set by the part’s current transfer ratio, so check your datasheet.
If you see this, do this
| You see | Do this |
|---|---|
| Output never changes | Input resistor or pin order. |
| Output always low | Check the pull-up and the input current. |
Related
transistor base resistor, LED resistor calculator.
Last reviewed: November 2026. These are the usual causes and the order that finds them fastest. Test on your own board; clones and cables differ.
Why this happens
The PC817 has an infrared LED on the input side and a phototransistor on the output side. The LED needs a series resistor because it behaves like a diode, with a forward voltage of roughly 1.2 V. The output transistor is controlled by light only; its base is not connected. When the LED is on, the transistor conducts between collector and emitter, but it can only pull the line toward the emitter side. With nothing else, the line floats when the transistor is off.
The current transfer ratio (CTR) says how much output current you get for a given LED current. The datasheet gives a wide range for the PC817, from about 50 percent to 600 percent at 5 mA, so design for the lowest value. The part is also slow, in the order of microseconds to tens of microseconds, which is fine for switches and slow logic but not for fast signals.
How to confirm the cause
- Measure the voltage across the input LED pins while the input is driven. About 1.2 V means the LED conducts. Near 0 V means the input is off or the pins are reversed.
- Measure the voltage across the series resistor and divide by its value to get the LED current. Aim for several milliamps.
- Measure the output voltage with the LED on. It should fall to a few tenths of a volt. If it stays high, the transistor is not turning on.
- Confirm the pin order. On the standard 4-pin package, pin 1 is the LED anode, pin 2 the cathode, pin 3 the emitter and pin 4 the collector.
- Check the output side has its own supply and a pull-up to that supply.
Worked example
Driving a PC817 from a 5 V pin and reading the output on a second microcontroller input.
Input, 5 V: R = (5.0 - 1.2) / 0.005 = 760 ohm -> 680 ohm (5.6 mA)
Input, 3.3 V: R = (3.3 - 1.2) / 0.005 = 420 ohm -> 390 ohm (5.4 mA)
Output: 10 kohm pull-up to 5 V, so 5 / 10k = 0.5 mA needed
CTR check: 5 mA x 0.5 (lowest CTR) = 2.5 mA available > 0.5 mA, OK
Code: pinMode(IN, INPUT_PULLUP); bool on = (digitalRead(IN) == LOW);Common mistakes
- Connecting the LED side without a resistor.
- Forgetting the output is inverted: the line is low when the LED is on.
- Joining the grounds of the input and output sides, which defeats the isolation.
- Choosing a very large pull-up and getting slow edges.
- Applying a reverse voltage to the input LED.
If this did not fix it
- Check the input current. A 3.3 V source with a large resistor may provide too little LED current to switch fully.
- Check whether your module already has its own resistors and pull-ups, so you are not adding extra ones.
- Check the part for damage; a PC817 overdriven without a resistor can lose its output.