An optocoupler is a component that transmits a signal between two electrically isolated circuits using light.
So far, in almost all our circuits, we have followed a fairly sound idea: sharing a common ground reference.
However, there are situations where connecting the grounds is dangerous or undesirable.
- What happens if you control an industrial motor that generates 1000 V spikes?
- What happens if you want to detect whether a 230 V bulb is on by connecting it to your microcontroller?
- What happens if you have an audio system and the motor introduces unbearable hum through the ground?
In these cases, we need the signal to pass, but the electrons must NOT pass. We need galvanic isolation. And the tool to achieve this is the optocoupler.
What is an optocoupler?
An optocoupler (or opto-isolator) is a component that transfers an electrical signal between two isolated circuits using light.
If we look inside a typical chip (like the famous PC817 or 4N25), we see that there are no wires connecting the input to the output.
Instead, we find:
- An LED (emitter): on the input side.
- A phototransistor (receiver): on the output side.
- A transparent dielectric barrier: between them.
Basic operation
The mechanism is tremendously simple yet effective:
- When we put current through the input, the internal LED turns on.
- The light travels inside the chip and strikes the base of the phototransistor.
- The phototransistor, upon receiving light, saturates (closes the switch) and allows current to flow on the output side.
The two sides exchange information via light, without a direct conductive connection between them.
The concept of galvanic isolation
Since the connection is made by light (photons) and not by wires (electrons):
- The input circuit can be at 5 V.
- The output circuit can be at 230 V, or even 10,000 V.
- They do not share a ground (GND).
If there is a catastrophic short circuit on the power side and everything burns out, the voltage spike will reach the phototransistor and destroy it. But it will stop there. Light does not conduct electricity. Your board, on the other side of the chasm, will be safe.
Key parameter: CTR
Just as the BJT had
CTR tells us what percentage of the current flowing through the LED will be allowed to flow through the phototransistor.
- A CTR of 100% means that if you put 10 mA into the LED, the transistor will allow 10 mA to pass.
- A CTR of 50% means that if you put 10 mA in, you will only get 5 mA on the other side.
CTR varies with temperature and component age. When designing, always assume the worst case (low CTR) and do not use optocouplers for precision analog signals, use them only for digital signals (ON/OFF).
How it is connected (the ground mistake)
To use an optocoupler correctly, we must have two separate power supplies (or accept that if we use the same source, we lose isolation against spikes, although basic protection is maintained).
Input Circuit (LED side)
It is connected just like a normal LED.
- Arduino Pin → Resistor (e.g., 220Ω) → Anode (Pin 1).
- Cathode (Pin 2) → Arduino GND.
Output Circuit (Transistor side)
It is connected like an NPN switch.
- Collector (Pin 4) → To the load or the reading pin of the other system (with pull-up).
- Emitter (Pin 3) → GND of the power stage.
For the isolation to be real, the input GND and the output GND must not be connected. If you connect the ground wires of both sides, you are creating an electrical bridge and the optocoupler loses its galvanic safety function.
If we exceed the specifications, the barrier can fail. Therefore, we must not promise that a microcontroller will always be protected against any spike on the power side.
Current Transfer Ratio
In a phototransistor optocoupler, the CTR (Current Transfer Ratio) relates the collector current to the LED current under specific conditions:
For example, a CTR of 50% would allow obtaining about 5 mA of collector current with 10 mA in the LED, provided the output voltage and other conditions match the specification.
CTR exhibits dispersion between units and varies with current, temperature, and aging. We must design using the minimum and maximum limits from the datasheet, not a typical value.
Input and output connection
On the input side, we calculate a resistor for the LED:
On the open-collector output, we usually use a pull-up resistor. Its value must allow the phototransistor to reach a valid low level with the minimum CTR and without exceeding its current.
To maintain isolation, we need isolated power supplies and no conductive connection between the references. If both sides share a source or ground, the component may still adapt or condition the signal, but galvanic isolation between them no longer exists.
Speed and analog signals
A saturated phototransistor can take a considerable amount of time to turn off. For high-speed communications, we must check propagation delays, capacitance, and connection mode, or choose a faster logic optocoupler.
There are also optocouplers and isolated amplifiers for analog signals. A generic phototransistor does not offer precise transfer by itself due to CTR variation, although it can work in feedback loops designed to compensate for it.
To maintain isolation, both sides must keep separate sources and references, in addition to the required distances on the board. If we connect their grounds, galvanic isolation disappears.
Common applications
- Isolated feedback in switching power supplies.
- Industrial digital inputs.
- Zero-crossing detection with specific components.
- Interfaces that must avoid galvanic connection between equipment.
Some relay boards include an optocoupler, but they may connect the grounds via traces or jumpers. The presence of the component does not prove that the module is truly isolated: you need to check the schematic and the power supply.