Optocoupler (4N35)
An infrared LED and a phototransistor sealed in one black DIP-6, facing each other across a gap of clear plastic.
Aliases: optoisolator, opto-isolator, 4N35, PC817 (the four-pin cousin on every relay module).
Current through the LED makes light, the light turns the transistor on, and the two sides share no wire. That is the point of the part: the circuit on the transistor side can have its own supply and its own ground, and nothing on one side can reach the other. The Arduino Starter Kit's "Hacking Buttons" project wires the transistor across the button of another gadget, so a sketch can press it without touching the gadget's circuit.
Pins
Notch to the left, as on any DIP:
| Pin | Package pin | What it does |
|---|---|---|
A |
1 | Anode of the infrared LED. |
K |
2 | Cathode of the LED. |
NC |
3 | Not connected, on the real part too. |
E |
4 | Emitter of the phototransistor. |
C |
5 | Collector of the phototransistor. |
B |
6 | The transistor's base. Left open in the model: see below. |
Properties
ctr is the current transfer ratio in percent: the collector current the
transistor can carry for each milliamp in the LED, at the datasheet's test point
(10 mA in the LED, 10 V across the transistor). 120 by default.
While it runs
The part number glows red while the LED carries more than a milliamp. The probe is the LED current in milliamps.
Wiring it
The LED is an LED: it wants a resistor. On the board's side, a pin through 220 ohm
into A and K to ground gives about 17 mA. On the other side, C and E go
where a switch would go, collector to the more positive side:
const int OPTO_PIN = 2;
void setup() {
pinMode(OPTO_PIN, OUTPUT);
}
void loop() {
digitalWrite(OPTO_PIN, HIGH); // "press"
delay(300);
digitalWrite(OPTO_PIN, LOW); // "release"
delay(1700);
}
What the model gets right
Isolation. The LED side and the transistor side are separate circuits with no path between them, so each can have its own ground.
The LED's drop. It is an infrared GaAs LED, not a visible one: 1.2 V at 10 mA and about 1.35 V at 50 mA, from the 4N35 sheets (1.5 V maximum). Under about 1 V it passes almost nothing.
The current transfer ratio. The transistor's light comes from the LED current,
solved in the same step, so its collector current in the active region is ctr
times the LED current at the test point: every vendor's 4N35 guarantees at least
100 %, and the default of 120 % is an assumption just above that floor. A
transistor asked for less than that saturates, about 0.1 V from collector to
emitter, which is the "pressed" state a button circuit needs.
It is a transistor, not a contact. Wired backwards across a button (emitter to the positive side) it barely conducts, and it only carries current one way.
What it does not model
The base pin: the 4N35 brings the transistor's base out on pin 6 so a resistor to
the emitter can speed up switching. Here the base is open inside, as in most hobby
circuits, and anything wired to B has no effect.
The switching time (a few microseconds), the CTR's fall at very low and very high LED currents and as the part ages, temperature, and the isolation voltage, which here is unlimited.
Common mistakes
No resistor in series with the LED: a pin straight into A pushes as much current
as the pin can, far past the LED's rating.
Collector and emitter the wrong way around across the gadget's button.
Expecting it to switch mains or a motor: the transistor is good for tens of milliamps. To switch more, use it to drive a transistor or a relay.
See it in action
Opto press presses a battery-powered gadget's button from an Uno. Open it at /templates.