# Why are relays so frequently driven by optocouplers?

Since the advent of the many microcontroller development boards, like Arduino, there have been a number of relay modules sold to drive mains AC loads.

A lot of these seem to use an optocoupler, driver transistor and a relay to drive the load (example on Amazon)

Why are they implemented like this?

Some of my thoughts:

• Relays provide as good or better isolation than most optocouplers
• There is still a driver transistor present, so it is not component saving
• There is still inductive kickback protection, so it is not component saving
• Optocouplers are not as cheap as transistors, so additional cost compared to just a driver transistor
• There is no need to meet any regulatory requirements as these are DIY products
• I have never seen small mains relays driven by optocouplers in commercial equipment
• A number of these boards don't seem to be designed brilliantly (no regard to clearance or creepage), so even if the optocoupler is simply to provide two layers of isolation, the board fails at this.
-
Cargo-cult design? Maybe the designers are copying schematics from each other without thinking about it too much. As you said yourself, they don't seem to be designed well in general. –  AndrejaKo Feb 27 '13 at 10:17
16A@250V is a lot of power and it does seem that the design is pretty naive on a lot of these. –  Cybergibbons Feb 27 '13 at 14:31
Currently, a combination of Kaz and The Photon's answers seem most plausible. Industrial controls could be improved by use of optocouplers, and these hobbyist boards have likely cloned them. –  Cybergibbons Feb 28 '13 at 0:38

First, a possibly more permanent link to this product is here. And the schematic is here.

Two reasons it makes sense to use optoisolators here:

• The controlling device might be very far away so that it doesn't share a common ground reference with the relay board (except as connected through a long cable). Using the optoisolator means the control signal is used purely as a differential signal between Vcc and the control signal, both sourced from the controller circuit; ground potential differences won't affect the operation.

• The relay coil voltage is not necessarily the same as the controller's Vcc. It could even be generated by an off-line (unisolated) supply. The optoisolator then provides isolation between the potentially unisolated JD-VCC supply and the controller circuits.

-
Slightly off topic These exactly same modules go for $2.25 (maybe even less) so the$7.99 link is a bad price. ledsee.com/index.php/arduino-modules2013-02-16-10-32-17/… –  jippie Feb 27 '13 at 20:29
I think these are both very valid reasons when needed, and are why most industrial control system inputs will be optoisolated. But my gut feeling is that they sound like rare use cases, especially for hobbyist boards that are <\$50. –  Cybergibbons Feb 27 '13 at 20:34
@Cybergibbons, I admit the 2nd one is kind of a stretch. But I think the first would be pretty common...Also I imagine these boards weren't originally designed just to work with Arduinos --- that's just a market they found where they can sell a lot of them --- they could also be used in general industrial controls, etc. –  The Photon Feb 27 '13 at 21:31
And in industrial controls you might a have a ground-loop or induced transient problem with a much shorter cable length due to big switching loads etc in the environment. –  The Photon Feb 27 '13 at 21:33
I'd personally never dream of using something so low cost in an industrial situation - generally a single relay from a good manufacturer costs more. That's my reasoning as to why I'd not expect them to be considerations for hobby boards, when you could trim these components and the board would still work. Thoughts? –  Cybergibbons Feb 28 '13 at 0:36

Probably a number or reasons, but the most important being that it will prevent transient voltage from damaging the driving transistor. And depending on the application, it will help prevent AC noise from interfering in the rest of the circuit.

You bring up some good points, however optocouplers are commonly used to isolate components from potentially dangerous outside sources. They are cheap and simple to implement. And they can potentially offer more protection than a diode. And of course, as you pointed out:

A number of these boards don't seem to be designed brilliantly (no regard to clearance or creepage), so even if the optocoupler is simply to provide two layers of isolation, the board fails at this.

-
Wouldn't a flyback diode be a cheaper way to prevent the transient back EMF damaging the transistor? –  Rocketmagnet Feb 27 '13 at 14:18
I think Garrett means from the input side, which I hadn't considered. Most optocouplers can take a wide range of inputs. –  Cybergibbons Feb 27 '13 at 14:30
@Rocketmagnet: The speed at which a relay can switch off will be a function of the amount of reverse voltage that is allowed to appear across it. Using a simple diode across a relay may be effective from a protection standpoint, but will cause the relay to behave "sluggishly". –  supercat Feb 27 '13 at 16:07

I suspect a big part of the reason has to do with the idea that if there are two isolation barriers, there will continue to be an isolation barrier even if one is accidentally or intentionally bridged. When working with circuits, especially if one is a klutz, one may sometimes briefly short things which really shouldn't be shorted (e.g. because a scope ground clip decides to come undone and flail itself across the board). Adding an extra layer of isolation reduces the likelihood that such an accident will cause significant damage to anything. Most mass-produced products will never be on anyone's workbench, much less a workbench belonging to a klutz, but many home-brew products will spend a great deal of time on such workbenches. Further, home-brew boards are often made without solder mask, greatly increasing the likelihood that of stray ground clip or probe making an unwanted contact.

In addition to providing protection against accidental bridging, if there are two full isolation barriers it may be possible (if one is careful) to bridge one while doing diagnostics involving the other while maintaining an isolation barrier between the two main parts of the system. For example, if one wants to determine the amount of time that elapses between the processor setting an output and a solenoid receiving power, one could start by confirming the relay-coil ground and contact-side ground were isolated, bridging the relay ground and CPU ground, and measuring the time between the CPU output and the relay coil. One could then isolate the relay-coil ground and CPU ground and--after double-checking that they really were isolated, bridge the relay-coil ground and contact-side ground and measure timings between the coil and the things they control. Performing such measurements in a system with only single isolation would probably require having a scope with two probes that were isolated from each other. Such rigs exist, but they're generally expensive.

-