Author Topic: Relays and Optocoupler - When is it required?  (Read 6304 times)

0 Members and 1 Guest are viewing this topic.

Offline anfiltTopic starter

  • Newbie
  • Posts: 8
  • Country: us
Relays and Optocoupler - When is it required?
« on: May 23, 2021, 01:56:38 am »
So I was looking at various schematics for driving a relay. One things I noticed often when a micro-controller is involved they often also include an optocoupler. However, when the relay coil voltage is the same, like a with 5V MCU and 5V coil I noticed a lot designs still include the optocoupler, is this mainly done to limit noise or similar when the coil is switched off? Like the coil already provides isolation from the load being driven so that does not seem to be the reason. What made me think about this a little more closely is because I also saw some designs without an optocoupler when the driving the switching transistors.

--Summary--
It make sense to have one when the voltage is much different because if one of the switching transistors failed it could also blow up your controller. For example 24V coil and 5V MCU. However, when they are the same why would some designs not include an optocoupler and some do?
« Last Edit: May 23, 2021, 02:37:39 am by anfilt »
 

Offline pqass

  • Frequent Contributor
  • **
  • Posts: 726
  • Country: ca
Re: Relays and Optocoupler - When is it required?
« Reply #1 on: May 23, 2021, 04:42:52 am »
"...with 5V MCU and 5V coil I noticed a lot designs still include the optocoupler."   Really? I've not had that experience.

As you said, there is isolation already so the extra optocoupler before the relay isn't really needed.  Unless they don't share the same ground.  Besides, you'll still need a NPN low-side transistor to switch the relay since MCUs or optocouplers won't be able to source/sink 80mA or so of current that a typical 5V coil demands.

"...switching transistors failed it could also blow up your controller."
Not really likely for just 80mA of current unless someone forgot the flyback diode.

"For example 24V coil and 5V MCU."
A low-side NPN transistor would have no problem with the 24V coil Vcc interoperating with a 5V MCU Vcc. Using a high-side PNP on its own would be a problem though.

"...why would some designs not include an optocoupler..."
Madman Muntz got it!   ;D   https://en.wikipedia.org/wiki/Muntzing   
 

Offline anfiltTopic starter

  • Newbie
  • Posts: 8
  • Country: us
Re: Relays and Optocoupler - When is it required?
« Reply #2 on: May 23, 2021, 05:42:25 am »
""...with 5V MCU and 5V coil I noticed a lot designs still include the optocoupler."   Really? I've not had that experience." Well I have found a fair few of them that's what I mean by a lot. So I just trying to understand why.
« Last Edit: May 23, 2021, 05:55:44 am by anfilt »
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 785
  • Country: ca
Re: Relays and Optocoupler - When is it required?
« Reply #3 on: May 23, 2021, 02:17:17 pm »
Search pattern "resetting microcontroller when relay switched off"
google's first findings https://electronics.stackexchange.com/questions/101815/pic16f628a-resetting-after-relay-turned-off
 

Offline penfold

  • Frequent Contributor
  • **
  • Posts: 675
  • Country: gb
Re: Relays and Optocoupler - When is it required?
« Reply #4 on: May 23, 2021, 03:24:11 pm »
I can't say I've ever seen it done in a commercial design. So long as the creepage and clearance between the coil and contacts are maintained on the PCB as it is within the device, a suitably rated drive transistor and flyback diode or snubber arrangement is used on the coil itself... then I see very little reason to need do it.

In some extreme EMC cases, maybe 12pF or so coil to contact capacitance may be too much, or perhaps the relay could be physically in a separate I/O domain of the PCB which would warrant some isolation, but I would expect a separate power supply. Whether an opto is the right device to offer such isolation is a bit academic, but it is a case for isolation nonetheless.
 

Offline fcb

  • Super Contributor
  • ***
  • Posts: 2117
  • Country: gb
  • Test instrument designer/G1YWC
    • Electron Plus
Re: Relays and Optocoupler - When is it required?
« Reply #5 on: May 23, 2021, 04:00:13 pm »
So I was looking at various schematics for driving a relay. One things I noticed often when a micro-controller is involved they often also include an optocoupler. However, when the relay coil voltage is the same, like a with 5V MCU and 5V coil I noticed a lot designs still include the optocoupler, is this mainly done to limit noise or similar when the coil is switched off? Like the coil already provides isolation from the load being driven so that does not seem to be the reason. What made me think about this a little more closely is because I also saw some designs without an optocoupler when the driving the switching transistors.

--Summary--
It make sense to have one when the voltage is much different because if one of the switching transistors failed it could also blow up your controller. For example 24V coil and 5V MCU. However, when they are the same why would some designs not include an optocoupler and some do?
Before I say something like 'what a load of tosh', any chance you can post links or pictures of the schematics?? There maybe a different reason for using an opto-coupler than you think.

The only reason you would include an optocoupler in a relay driver is if you need isolation between voltage domains for some reason (different earthing, floating supplies, isolation for noise (see earthing) etc).  You certainly wouldn't use it as method of isolating back-EMF spikes.

If you are using opto-couplers as method of getting enhanced creepage/clearance, then perhaps - but relays tend to have greater creepage/clearance than most common optocouplers.

You might use an opto-coupled triac (MOC3020 etc..) to drive a 24VAC or mains coil type relay. An opto-coupled solid-state switch as coil drive amplifier.
https://electron.plus Power Analysers, VI Signature Testers, Voltage References, Picoammeters, Curve Tracers.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4427
  • Country: dk
Re: Relays and Optocoupler - When is it required?
« Reply #6 on: May 23, 2021, 05:54:52 pm »
seems like the hardware version of https://en.wikipedia.org/wiki/Cargo_cult_programming
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Relays and Optocoupler - When is it required?
« Reply #7 on: May 23, 2021, 06:31:29 pm »
I can't say I've ever seen it done in a commercial design. So long as the creepage and clearance between the coil and contacts are maintained on the PCB as it is within the device, a suitably rated drive transistor and flyback diode or snubber arrangement is used on the coil itself... then I see very little reason to need do it.

I did a commercial design that had a 5V microcontroller switching a relay with a 12V coil using a low side NPN transistor and a flyback diode across the coil, the relay was switching 240VAC at up to a few amps. We have not had any failures either on the bench or in the field.

I suppose optocouplers could be handy for something like a relay board meant for beginners, it does provide an extra degree of protection against accidental shorts, mis-wiring, and stuff like that but I see no reason to use an optocoupler in most cases.
 

Offline penfold

  • Frequent Contributor
  • **
  • Posts: 675
  • Country: gb
Re: Relays and Optocoupler - When is it required?
« Reply #8 on: May 23, 2021, 07:09:42 pm »
I can't say I've ever seen it done in a commercial design. So long as the creepage and clearance between the coil and contacts are maintained on the PCB as it is within the device, a suitably rated drive transistor and flyback diode or snubber arrangement is used on the coil itself... then I see very little reason to need do it.
I did a commercial design that had a 5V microcontroller switching a relay with a 12V coil using a low side NPN transistor and a flyback diode across the coil, the relay was switching 240VAC at up to a few amps. We have not had any failures either on the bench or in the field.

Hence the "So long as ..."... though on second thoughts I retract that, it was a slightly foolish comment since I doubt there's any safety standard that would allow the opto to be the limiting factor rather than the relay's isolation itself.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Relays and Optocoupler - When is it required?
« Reply #9 on: May 23, 2021, 08:31:18 pm »
I did a quick search and using an MCU to drive an opto-coupler, driving a relay seems to be quite common. Schematics I've found on hobbyist sites and photographs of commercially available modules show opto-couplers driving relays. I suspect it's a case of copy paste. There's no need for an opto-coupler, as the 0V for the relay coil, is normally shared with the MCU's power supply. If it isn't, then I can see the need for an opto-coupler, but would prefer to drive the relay from the same power supply, as the MCU, if at all possible and not use an opto-isolator.

https://www.instructables.com/How-Does-It-Work-DIY-Relay-Modules/
https://www.amazon.co.uk/SUNFOUNDER-2-Channel-Optocoupler-Expansion-Raspberry/dp/B00E0NTPP4
https://electronics.stackexchange.com/questions/464343/driving-relay-directly-from-optocoupler-what-is-best
https://circuits-diy.com/optocoupler-relay-driver-with-pc817-2n3904/
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Relays and Optocoupler - When is it required?
« Reply #10 on: May 23, 2021, 08:57:09 pm »
One application where I could potentially see a need for the optocoupler is in a medical device, where there tend to be greater requirements for isolation and a little redundancy is a welcome addition for the small cost it adds to relatively expensive low volume equipment. Generally speaking though I agree that it's probably largely a case of somebody saw a relay driver that used it somewhere so they used the same approach.
 

Offline fcb

  • Super Contributor
  • ***
  • Posts: 2117
  • Country: gb
  • Test instrument designer/G1YWC
    • Electron Plus
Re: Relays and Optocoupler - When is it required?
« Reply #11 on: May 23, 2021, 09:01:45 pm »
Thanks Zero999 for those links.  Some of these 'engineers' need taking outside and re-educating with the hot-end of soldering iron, cargo-cult indeed as someone has said.

https://electron.plus Power Analysers, VI Signature Testers, Voltage References, Picoammeters, Curve Tracers.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3361
  • Country: nl
Re: Relays and Optocoupler - When is it required?
« Reply #12 on: May 24, 2021, 02:56:39 am »
My father had a greenhouse (about 6000 square meters of glass) and the first climate computer was an 8080 based beast the size of a desk with a real terminal on top and it looked quite impressive when I was 8 years old.

Later I found out there were rows upon rows of reed relays in the thing that switched some 200+ wires from a separate 24V source and at the end of all those wires (about 40meter long) there were 12V signal relays which again switched big contractors for motors up to 5.5kW.

That thing worked quite reliably for about 20+ years.
Part of the reliability was probably from using several layers of isolation. The reed relays are also only capable of switching small currents. Not enough to switch the big 3-phase contactors. Yet another reason for the extra layers is that during maintenance a mistake is made  (for example replacing a faulty 5kW contactor), it would only fire back so far and not reach the climate control computer itself.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16620
  • Country: us
  • DavidH
Re: Relays and Optocoupler - When is it required?
« Reply #13 on: May 24, 2021, 08:45:12 am »
An optocoupler may be used to drive a relay so that the return current from the relay is not shared with the digital logic's return currents and the relay's return current can be more easily directed to the best grounding point.  Essentially it makes it easier to maintain a single point ground, although it applies just as well to the positive supply if that is shared with CMOS digital logic where the threshold voltage relies on both the ground and supply potential.

The optocoupler also provides more electrostatic isolation (less capacitance) between the logic and fast edges of the inductive solenoid coil than a transistor will.

You might also see an optocoupler used to provide protection against ESD, although this applies even more so to human interface circuits.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Relays and Optocoupler - When is it required?
« Reply #14 on: May 24, 2021, 07:12:12 pm »
I still don't see the point in using both a relay and opto-coupler.

It won't provide any greater degree of isolation from the relay contacts, unless the coil is driven off a separate power supply, with a greater level of separation, than the MCU's power supply.

I don't see how the return current from the relay coil is an issue. It's normally only a few tens of mA and even if the layout isn't that great, the emitter of the driver transistor will just bounce up a little, which is no big deal, unless the trace is stupidly thin. If there are concerns about return currents causing interference, I'd be more inclined to shift the relay to the negative rail and drive it with a PNP transistor, with an NPN driving the base, rather than mess around with an opto-coupler. Note the load in the circuit is the relay coil.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16620
  • Country: us
  • DavidH
Re: Relays and Optocoupler - When is it required?
« Reply #15 on: May 24, 2021, 08:05:29 pm »
Moving the return current to the positive supply does not help with CMOS logic.

And if the return current is not a problem, which is likely with a good layout, coupling from the high dV/dt though the transistors is still there.  And good layouts are not always possible; the base current has to return through the emitter somehow, and using an optocoupler allows its point of return to be explicitly determined by breaking any possible ground loop.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Relays and Optocoupler - When is it required?
« Reply #16 on: May 24, 2021, 09:15:18 pm »
Moving the return current to the positive supply does not help with CMOS logic.

And if the return current is not a problem, which is likely with a good layout, coupling from the high dV/dt though the transistors is still there.  And good layouts are not always possible; the base current has to return through the emitter somehow, and using an optocoupler allows its point of return to be explicitly determined by breaking any possible ground loop.
Well if two transistors are used, as I've shown, the base current will be much smaller, than with the one, or indeed an opto-coupler, which has a poor CTR. It's a better solution than an opto-coupler an a much cheaper.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Relays and Optocoupler - When is it required?
« Reply #17 on: May 25, 2021, 07:38:26 pm »
Digikey has a bunch of different optocouplers in stock for 23 cents each in qty 10, I'm not sure two transistors are going to be "much cheaper" than that. Even if it isn't necessary, I could see it being worthwhile if it makes routing the PCB a little easier.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Relays and Optocoupler - When is it required?
« Reply #18 on: May 25, 2021, 09:28:23 pm »
Digikey has a bunch of different optocouplers in stock for 23 cents each in qty 10, I'm not sure two transistors are going to be "much cheaper" than that. Even if it isn't necessary, I could see it being worthwhile if it makes routing the PCB a little easier.
Have you seen how cheap BJTs are?

Did you look at the links I posted? Most of them have both a BJT and an opto-coupler. People here are giving them far too much credit. :palm:
https://images-na.ssl-images-amazon.com/images/I/71oYyAoyO3L._AC_SL1500_.jpg
https://circuits-diy.com/wp-content/uploads/2020/07/Optocoupler-Relay-Driver-with-PC817-2N3904.png

An opto-coupler has a much poorer CTR, than the hFE of a BJT, so goodness knows why anyone would use one, when unnecessary.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Relays and Optocoupler - When is it required?
« Reply #19 on: May 25, 2021, 10:03:33 pm »
Like I said, maybe it makes the PCB layout easier? Maybe it makes them sleep better at night? Maybe some very expensive or safety critical equipment is controlling the relay and you want to avoid any chance of damage due to transistor failing shorted, or a faulty connection resulting in a spike from the relay coil traveling back into the control circuitry? I've never used one to drive a relay but I can believe there might be a valid reason for doing so. There are also probably a lot of people who saw it done somewhere so they do it too, without really understanding why/if it's necessary. When it's a 23 cent part and we aren't talking large volume production who cares?
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Relays and Optocoupler - When is it required?
« Reply #20 on: May 26, 2021, 10:56:33 am »
Like I said, maybe it makes the PCB layout easier? Maybe it makes them sleep better at night? Maybe some very expensive or safety critical equipment is controlling the relay and you want to avoid any chance of damage due to transistor failing shorted, or a faulty connection resulting in a spike from the relay coil traveling back into the control circuitry? I've never used one to drive a relay but I can believe there might be a valid reason for doing so. There are also probably a lot of people who saw it done somewhere so they do it too, without really understanding why/if it's necessary. When it's a 23 cent part and we aren't talking large volume production who cares?
The part about being safety critical made me laugh, considering the cheap Chinese modules often lack other important safety features, such as sufficient creepage between the contact and coil. I suspect the part of your reply I've changed to bold, is the most likely reason. There are plenty of designs on the Internet with pointless/inappropriate parts, due to copy paster.
 

Offline Jwillis

  • Super Contributor
  • ***
  • Posts: 1710
  • Country: ca
Re: Relays and Optocoupler - When is it required?
« Reply #21 on: May 26, 2021, 12:05:59 pm »
A discharging coil can have voltages many times higher than the energizing voltage . But the diode should be enough to resolve that .
Galvanic isolation also addresses any ground potential differences or ground looping which can cause errors to occur in an MCU .
Transients can also create line noise which could also have an effect .
It all very much depends on what components are being used and circuit design.
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6264
  • Country: fi
    • My home page and email address
Re: Relays and Optocoupler - When is it required?
« Reply #22 on: May 26, 2021, 12:37:22 pm »
If the relay is very far from the microcontroller, then using an optocoupler close to the microcontroller, and a separate power circuit for the relays (completely isolated from the microcontroller), might make sense in an electrically noisy environment.  That way, any currents induced in the long wires would have to be pretty big to affect the operation, since they'd only affect the relays.

For example, consider a DIY CNC or plasma table, with the relay controlling a spindle motor or coolant pump.

I personally really dislike designs where the logic and the motors share a ground.  It is extremely common, but causes all sorts of issues; not the least of which are ground loops if you connect a computer in a separate mains circuit to the logic.  The optimum location for the isolation is between the microcontroller and the stepper drivers, and costs very little (see e.g. SI86xx and ISO76xx digital isolators), even including Trinamic drivers with UART/SPI comms and not just the typical STEP and DIR pulse lines.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Relays and Optocoupler - When is it required?
« Reply #23 on: May 26, 2021, 09:57:04 pm »
The part about being safety critical made me laugh, considering the cheap Chinese modules often lack other important safety features, such as sufficient creepage between the contact and coil. I suspect the part of your reply I've changed to bold, is the most likely reason. There are plenty of designs on the Internet with pointless/inappropriate parts, due to copy paster.

I'm not talking about cheap Chinese relay modules specifically, I'm speaking in general when I say there may be legitimate reasons to include an opto isolator driving a relay, not that the cheap Chinese modules may be legitimate reasons. Those cheap modules are a good candidate for the designer having seen it used somewhere and gone with that approach.

 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: Relays and Optocoupler - When is it required?
« Reply #24 on: May 26, 2021, 09:58:54 pm »
A discharging coil can have voltages many times higher than the energizing voltage . But the diode should be enough to resolve that .
Galvanic isolation also addresses any ground potential differences or ground looping which can cause errors to occur in an MCU .
Transients can also create line noise which could also have an effect .
It all very much depends on what components are being used and circuit design.

Should, yes. But what if the diode fails? Without isolation a failed diode could result in damage or unpredictable behavior to other parts of the system, with isolation that situation is very unlikely.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf