39
\$\begingroup\$

Another post on this site, when critiquing a pcb design, referred to "Arduino optocoupler disease" spreading across the internet. What type of design mistake does this refer to?

\$\endgroup\$
4
  • \$\begingroup\$ your question is answered in the post you linked \$\endgroup\$
    – jsotola
    Commented May 29 at 21:54
  • 14
    \$\begingroup\$ I am voting to reopen since the phenomenon is common enough here to warrant a definitive answer post. I've seen a few comments/answers that address a few aspects of it but usually they are within the context of a larger design review. Though maybe I'm missing an existing post? \$\endgroup\$
    – vir
    Commented May 29 at 22:21
  • \$\begingroup\$ The only information that I could find on the subject is in the listed post, the OP needs to clarify what the other links are to provide context. \$\endgroup\$
    – Voltage Spike
    Commented May 29 at 22:37
  • \$\begingroup\$ The term "Arduino optocoupler disease" is entirely made up by yours sincerely, hence the quotation marks. I'm glad that it resulted in this excellent Q&A! \$\endgroup\$
    – Lundin
    Commented Jul 1 at 13:51

4 Answers 4

36
\$\begingroup\$

The "optocoupler disease" is a symptom of a few misguided design choices that manifest as a "rash" of optocouplers on the outputs of an Arduino/RPi/microcontroller. The designer usually wants to prevent damage to the Arduino from high voltage from a differently-supplied section of the circuit making it back to the GPIO pin from a damaged component, inductive kickback from a relay or motor coil, or a possibly miswired connection. This is very understandable; frying probably the most expensive part of your project is always a bad day and if there is e.g. a relay that is switching line voltage, it can be tempting to add another layer of protection between lethal voltage and the user interface. What we frequently see in practice is something like this:

schematic

simulate this circuit – Schematic created using CircuitLab

At first glance, this looks reasonable; there is what appears to be an air gap between the two parts of the circuit with the optocoupler providing the isolated signal linkage between them. The fatal flaw is in thinking that ground is always and forever 0V and forgetting that it is simply another node:

schematic

simulate this circuit

(Apologies to @andy_aka for bussing ground)

With the ground connection made explicit, the signal path between both sides of the circuit - and, critically, around the optocoupler - is more obvious. The optocoupler, when deployed in this configuration, is not providing meaningful isolation. It is doubly useless if e.g. the relay portion of the circuit is being powered from the same supply as the Arduino.

So what are the options available to the designer? One option for this example - if isolation is still desired - is to have separated grounds between the 5V and 12V sides. This removes the path for voltage transients to conduct from one side to the other. Care should be taken, however, to ensure that there are no other parts of the circuit that require grounds to be harmonized between supply domains (transistors with a gate/base supplied by one side and a source/emitter referenced to the other, for example).

Another option is to remove the optoisolator entirely; this is what is generally recommended to designers in this situation. Since the original circuit didn't have meaningful isolation, there's no need to have a component that's only for show:

schematic

simulate this circuit

D2 provides a path for the inductive kick of the relay coil, shunting it away from Q2 and the GPIO pin; the relay itself provides the isolation between the switched circuit and everything else.

When are optocouplers useful? This is very application dependent so I'll just touch on it briefly and very generally. For applications in which the designer does not have control over what is attached to the input or the output and where an overvoltage could be reasonably expected to be present (e.g. GPIO pins that are accessible to the user), an optocoupler can be a useful addition. Switchmode power supplies are another canonical application in which feedback between the low voltage and high voltage sides is required while still maintaining galvanic isolation.

\$\endgroup\$
2
  • 8
    \$\begingroup\$ Sure, optocouplers have no galvanic isolation in common-ground configuration, making the design questionable. But I don't believe it's entirely useless, it's still doing something. It may still protect the GPIO port from a positive transient by greatly reducing its energy via high impedance - and keeping ground impedance low is necessary in all clamping circuits anyway. So one can say it's acting as a (wasteful equivalent of) a Zener/TVS diode - with the (questionable) "benefit" that one doesn't need to bother sizing the diode correctly according to surge energy when the voltage is low. \$\endgroup\$ Commented May 30 at 7:43
  • 1
    \$\begingroup\$ True true but the designer would need to make that choice intentionally and with an understanding of what types of transients are blocked vs which ones are still an issue. It's the optos put in "just in case" that usually don't have a thorough analysis of failure modes or expected transients. \$\endgroup\$
    – vir
    Commented May 31 at 0:32
15
\$\begingroup\$

It's not really a mistake. In most cases, the optocouplers may work in the design just fine and there are no mistakes in the design, but it's just a component that's useless, so why put useless components in the design for no reason.

It's a specific instance of "cargo cult", a thing used or added because everyone else seems to use it for some reason that nobody really seems to know why exactly.

It's so cool to be able to say your design has an optocoupler as it is generally used for safety and isolation, but in reality, in most Arduino designs, it is usually designed in a way that does not isolate anything, wastes power to do its function of passing signals through it and just adds cost and PCB size to the design, as the design could even be just done without the useless optocoupler, maybe even better.

Like in the post you refer, the optocouplers add no value. They don't isolate. Driving the optocoupler input draws more current from Arduino GPIO pin than driving the transistor base directly. Optocoupler output leakage current may even cause problems with the transistor not being able to fully turn off. The transistor is anyway required as the Arduino or optocoupler output cannot drive the current needed by the relay.

\$\endgroup\$
2
  • \$\begingroup\$ So in summary, it increases cost, wastes power, and may prevent the transistor from fully turning off. How is that "not really a mistake" though? \$\endgroup\$
    – marcelm
    Commented May 30 at 8:26
  • 1
    \$\begingroup\$ @marcelm You can also design in the useless optocoupler correctly. Then it only increases cost and wastes power, and will work perfectly, without isolating anything because it does not need to. The two mistakes in the linked question are not having a series curret limting resitor for transitor base, and not having a pull-down resistor to prevent leakage current from causing problems. \$\endgroup\$
    – Justme
    Commented May 30 at 8:31
9
\$\begingroup\$

Optoisolators (also known as optocouplers, or just optos for short) are a valuable tool for passing signals across isolation boundaries, but all too often one sees designs in the arduino/pi/maker world that use an optoisolator but do not place it across an isolation boundary.

A common example is driving relays. Lets say the relay contacts are used to switch dangerous voltages. Naively one might think that two isolation barriers are better than one, and therefore using an optocoupler to drive their relay will make things safer.

The thing is the relay coil needs power! So unless you arrange a separate power source for the relay coil, which is isolated from both the "safe" and "dangerous" parts of your system, you have nullified one of your two isolation barriers. Most common in opto+relay setups is to see the opto nullified, while the relay provides the only effective isolation barrier.

Now relays can be perfectly good isolation barriers, but your focus should be on firstly selecting an appropriate relay and secondly laying out the PCB in a way that maximises the isolation. Not on adding an optoisolator that gives you a false sense of safety.

It makes me cringe when I see a relay board advertised with ineffective optoisolators "for safety", while completely screwing up the creepage/clearance around the relays that form the only effective isolation barrier.

\$\endgroup\$
3
\$\begingroup\$

In circuits where a microprocessor pin is used to switch a transistor, it's common for failures of that transistor to fry the controller pin as well, especially since newer controller's I/O pins aren't as beefy as older ones (I had a windows PIC 16C620 which was supposed to monitor voltage on a pot that wasn't supposed to be connected to mains, but accidentally got bridged. The PIC had a 1K resistor between a port pin and mains, and there was enough current to make the resistor disappear except for the legs, but the PIC--even the ADC--remained functional. "They don't make 'em like that anymore"). Using an opto-isolator may avoid that kind of damage, and using an opto when driving off-board relays may be useful for minimizing the amount of repair that would be required after a catastrophic event. If, however, everything that's coil-side of the relay is contained on the same board, the transistor and protection network should be designed so that the transistor is never stressed anywhere near failure. If transistors are blowing up often enough to be a problem, there's something wrong with the design an opto is unlikely to fix.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.