Microcontrollers are widely used for controlling transistors and relays. Transistors and relays are used for actuating or (energizing) equipment with a higher voltage than an MCU can handle. For example, fans, lights, television, door locks, furnaces, and appliances can be automated using an MCU, however, most operate at higher voltages compared to the voltage tolerances as designated in an MCU’s Input/Output (I/O) specification. Microcontrollers used in Arduinos, Microchip’s PICs, and STMicroelectronics’ MCUs usually operate in the range of 3 – 5 VDC. When high voltage equipment is controlled by (and electrically connected to) an MCU, the high voltage equipment produces back EMF headed towards the MCU’s circuit and adds noise to the signals. These noisy signals can cause circuits to malfunction or cause permanent damage.
Another major challenge is protecting sensitive circuits from the risk of receiving electrical surges. High voltage equipment, powered by a high voltage source, can initiate an electrical surge. If a sensitive circuit is exposed to an electrical surge, the components can burn up immediately. In engineering slang, this means an electrical surge can “let out the magic smoke.”
To reject back EMF, noise, and electrical surges from entering an MCU circuit, optocouplers are often used. Optocouplers create a safe connection between high voltage equipment and microcontrollers with a means of complete electrical insulation. In case the high voltage circuit induces an electrical surge, the surge remains only on the output side of the optocoupler, and the circuit at input side remains safe and unaffected, as both sides are electrically isolated. Optocouplers are also called photodiodes, optoisolators, photocouplers, photo relays, and optical isolators.
Internal view of a phototransistor-based optocoupler
Phototransistor-based optocouplers contain an Infrared Emitting Diodes (IRED) on the input side and a phototransistor on the output side. Both sides are optically connected, and there is no electrical connection between the input and output side. When a voltage signal is passed on the input side, the IRED turns on, and the light that the IRED emits then falls on the receiving phototransistor, resulting in current flow through the phototransistor’s collector and emitter. [i]
How to make optocouplers at home
Although many optocouplers are fairly cheap and readily available online, they can be developed at home using an LED, a light dependent resistor, and an opaque tube, perhaps made with duct tape.
The phototransistor and LED are inserted inside the tube, facing towards each other. Tightly enclose the tube so that the phototransistor cannot be affected by an external light source. It is recommended to use an internally reflective tube, however, as a non-reflective tube might absorb LED light, affecting the efficiency of the optocoupler. This simple design can be used in hobby projects, functioning quite well as a standard optocoupler. [ii]