Opto couplers and relays - please clarify

Hi there,

I have been trying to find out when to use optocouplers and when to use relays. Searching the web (and this forum) I haven't found a good explanation.
First off: I am a complete noob in electonics, I am just playing with arduino, trying to copy other people's projects at this stage.

I want to hack a remote control for power outlets - so basically shorting the buttons.

The remote control obviously does not have a big battery / use as lot of power. So I'd think that I can control this via an opto-coupler (like the one included in the Starter Kit - 4N35).
Opto-couplers are cheaper than relays - and smaller. However, most tutorials on the web dealing with hacking remotes use relays - and I am struggling to understand why?

Also the example of "hacking toys". In the Arduino Starter pack booklet they use an Optocoupler. In the example for the Monkey Couch Guardion on the make blog they use a relay Redirect Notice.

I know that for high voltages you should use a relay. But as long as you're dealing with battery-powered DC devices, wouldn't an Optocoupler be enough? What are the drawbacks, if any?
Optocouplers are cheaper and smaller, so you'd think it would be the natural choice.

Thanks for any feedback, and I'm sorry if this is a repeat question. I just haven't seen an answer that I understand.

Cheers,
Papu

HI Papu
I have recently used the opto coupler that came in the kit. I did not use the arduino as this was a separate project. I was wanting to change a very low amperage 12v supply to a higher amperage 12v. I used the opto with a 220ohms resistor between the +12v low supply and anode. The cathode to 0v. the higher amperage 12v to the collector. With power on the input side the emitter went high 12v.

So yes you can use an opto instead of a relay.

I do not agree with you TimFr

There are several differences between relays and opto-couplers.
1: relays can switch a high current, opto's can switch a low current
2: relays can switch a high voltage, opto's can switch a low voltage
3: relays have a limited number of switch-cycles (usually 500~5000), opto's have a virtually infinite number of switch cycles
4: the output of a relay is a switch (polarity-independent), the output of an opto is a transistor (polarity dependent)
5: the output of a relay has zero voltage drop, the output of an opto has 0,3~0,7V voltage drop.
6: a relay takes some time to switch (1mS or so), an opto switches much faster
7: a relay is driven by a coil, an opto is driven by an LED.

Since you are switching a motor on and of, i think you'll be dealing with currents that an opto-coupler can't handle. I think you definitely need a relay or a transistor or mosfet.

Looking at that Make example... it's not a very good example. They tell you to connect the relay coils directly to the Arduino which is not a good practice.

Using relays: http://arduino-info.wikispaces.com/ArduinoPower
Using mosfets: http://bildr.org/2012/03/rfp30n06le-arduino/

Chagrin:
Looking at that Make example... it's not a very good example. They tell you to connect the relay coils directly to the Arduino which is not a good practice.

Using relays: http://arduino-info.wikispaces.com/ArduinoPower
Using mosfets: http://bildr.org/2012/03/rfp30n06le-arduino/

Much worse than that, the circuit is more or less guaranteed to destroy the Arduino - where is the free-wheel
diode across the relay coil? That is an essential component. They are (or happen to be) using the on-board LED and resistor
that is attached to pin 13 as a snubber network, which is outrageous really...

muddy:
I do not agree with you TimFr

There are several differences between relays and opto-couplers.
1: relays can switch a high current, opto's can switch a low current
2: relays can switch a high voltage, opto's can switch a low voltage
3: relays have a limited number of switch-cycles (usually 500~5000), opto's have a virtually infinite number of switch cycles
4: the output of a relay is a switch (polarity-independent), the output of an opto is a transistor (polarity dependent)
5: the output of a relay has zero voltage drop, the output of an opto has 0,3~0,7V voltage drop.
6: a relay takes some time to switch (1mS or so), an opto switches much faster
7: a relay is driven by a coil, an opto is driven by an LED.

Since you are switching a motor on and of, i think you'll be dealing with currents that an opto-coupler can't handle. I think you definitely need a relay or a transistor or mosfet.

Can you show me one relay datasheet spec that validates your 500/5000 cycles on #3 point? I'll wait. :smiley:

Lefty

Typical switch cycles will be more like 100,000 - basically they wear out eventually, whereas an opto coupler
will happily switch at 100 kHz for decades or more.

Any mechanical device does represent a reliability issue, therefore it needs to be avoided :).

Today you have opto-coupled power devices you may switch kilowats, kilovolts, kiloampers..

retrolefty:

muddy:
3: relays have a limited number of switch-cycles (usually 500~5000), opto's have a virtually infinite number of switch cycles

Can you show me one relay datasheet spec that validates your 500/5000 cycles on #3 point? I'll wait. :smiley:

Lefty

My time as an appliance repairman would have been much different.

pito:
Any mechanical device does represent a reliability issue, therefore it needs to be avoided :).

I hear this often repeated. I worked until retirement at a large oil refinery and would estimate that there was probably in excess to 10,000 electromechanical relays used for control maybe much more. Even the highest safety rated triple-redundant safety shutdown systems used relays. It's just a matter of understanding the ratings and not exceeding them. The electromechanical relay will be with us for a long long time to come. There is no reason to avoid them when they in fact can be the best solution for a specific application. Modern cars have many relays in them, but then I guess they don't follow your advice. :smiley:

Lefty

Today you have opto-coupled power devices you may switch kilowats, kilovolts, kiloampers..

Thanks everyone.
Still not the "black and white" answer I was hoping for, but it seems like it's not quite clear.

I obviously need to read up on basic electronics, as I have no idea of what "voltage drop" means. And "Ampere" sounds like a french cheese to me.

In this regard: I just bought the book MAKE:Electronics, which is supposed to be a good beginners guide. What is your favorite web-resource for leaning basic electronics?

Cheers, and thanks again all!

Papu

TimFr:
HI Papu
I have recently used the opto coupler that came in the kit. I did not use the arduino as this was a separate project. I was wanting to change a very low amperage 12v supply to a higher amperage 12v. I used the opto with a 220ohms resistor between the +12v low supply and anode. The cathode to 0v. the higher amperage 12v to the collector. With power on the input side the emitter went high 12v.

So yes you can use an opto instead of a relay.

You can use an opto instead of a relay, if the current is only a few milliamps.

If you connected that optoisolator to a mosfet, which powers the rest of your circuit that's a better way to go (along the lines of an SSR)

Hope I can help you. An optocoupler is simply an led grouped with a phototransistor switch. The switching is done with a transistor so you will have the voltage drop across it of a diode ( diodes when conducting drop generally .6 volt and a transistor is like a diode that can turn on or off ). Opto's are used to Isolate the controlling device from the switched device so the only thing your controlling device sees is the led in the optocoupler. When you use an optocoupler, your switched circuit must be able to be controlled by a low power transistor switch. The opto isolation is generally used when there is going to be a difference in voltage from the controlling circuit and the switched circuit, so in that condition a 5 volt controller like the arduino can switch a 12 volt circuit on or off with an optocoupler.
The optocoupler is used only in low power switching (like less then 1 amp), where a relay being simply a mechanical switch can switch several amps depending on the particular relay. Think of a relay as your wall light switch controlling the light in your house ( you are cotrolling the AC circuit without touching the circuit wires) . The relay can be switched by the low voltage of a microcontroller using 5 volt to power a coil that magnetically pulls closed a switch that in turn can then operate your house lights. The relay being a mechanical switch, controls any other circuit being AC or DC where a optocoupler is mostly for DC switching. Hope that helps you understand more about it. Jim..

There is overlap on many electronic components and choice comes down to different factors.

A relay is a mechanical device made with 'conductors' so you get virtually no voltage drop on the output.

An opto coupler is a semiconductor and has a resistance. That is why the voltage drop.

Bottom line, if you find an opto coulpler with the input/output characteristics you need then it can be interchanged for the relay. Yes, you do need to brush up on some basic electricity if you want to do more than blindly follow examples. Lots of good references on the web. Check a few out and see which one/s help you understand it the best. If one is murky try another. To start try this one: http://www.electronics-tutorials.ws/dccircuits/dcp_1.html

jtechian:
Hope I can help you. An optocoupler is simply an led grouped with a phototransistor switch. The switching is done with a transistor so you will have the voltage drop across it of a diode ( diodes when conducting drop generally .6 volt and a transistor is like a diode that can turn on or off ). Opto's are used to Isolate the controlling device from the switched device so the only thing your controlling device sees is the led in the optocoupler. When you use an optocoupler, your switched circuit must be able to be controlled by a low power transistor switch. The opto isolation is generally used when there is going to be a difference in voltage from the controlling circuit and the switched circuit, so in that condition a 5 volt controller like the arduino can switch a 12 volt circuit on or off with an optocoupler.
The optocoupler is used only in low power switching (like less then 1 amp), where a relay being simply a mechanical switch can switch several amps depending on the particular relay. Think of a relay as your wall light switch controlling the light in your house ( you are cotrolling the AC circuit without touching the circuit wires) . The relay can be switched by the low voltage of a microcontroller using 5 volt to power a coil that magnetically pulls closed a switch that in turn can then operate your house lights. The relay being a mechanical switch, controls any other circuit being AC or DC where a optocoupler is mostly for DC switching. Hope that helps you understand more about it. Jim..

That's it - now I get it! Thanks all. Sorry for being so slow - really lacking basic electronics, and will now study up before I ask another basic question.

I am surprised nobody picked up on the makezine article before...

The back EMF alone from the magnetic field alone generated by the energized field, is enough to kill the arduino, why there's no protective diode (AT LEAST) across the relay
terminals is beyond me...

As for any other issues...

Chagrin:
Looking at that Make example... it's not a very good example. They tell you to connect the relay coils directly to the Arduino which is not a good practice.

Using relays: http://arduino-info.wikispaces.com/ArduinoPower
Using mosfets: http://bildr.org/2012/03/rfp30n06le-arduino/

What's the MA draw of a typical coil relay anyhow? <40ma?

What's the MA draw of a typical coil relay anyhow? <40ma?

There is no "typical" coil current rating, there is just the datasheet rating for the specific relay you choose to use. I've seem some 5vdc reed relays that draw under 15ma and therefore can be driven directly from an arduino output pin just like an LED. Others of course will have much higher coil current.

Lefty

By typical i mean, cheapy relay from china (Blue boxes)

All mine sit on PCB's, I could measure how many ohms but i can't be bothered......

cjdelphi:
By typical i mean, cheapy relay from china (Blue boxes)

All mine sit on PCB's, I could measure how many ohms but i can't be bothered......

72ma for the 5V OMRON / 10A relays.

Btw, pin 13 has an LED on it which (kinda) protects it from the inductive spike of the relay. I realized that when I read their instructions but, well, when you see things like that it's just not easy to find the appropriate words. :wink: