Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

How to drive an AC relay off the Netduino?


  • Please log in to reply
12 replies to this topic

#1 Daniel Minnaar

Daniel Minnaar

    Advanced Member

  • Members
  • PipPipPip
  • 46 posts
  • LocationJohannesburg, South Africa

Posted 19 December 2011 - 04:55 AM

Hi there, I need to switch a pump on and off again every few hours or so. The contactors on the pump need 110VAC, so I've been told to use a 12V - 110V relay. I've read a few articles here and on the arduino forums, but I find it's more about the discussion thereof instead of a how-to instruction... oh, and I've also seen the famous diagram floating around for relays on the arduino (http://www.arduino.c...ning/relays.pdf) but I don't think that helps me because I need an AC relay. Also, I've read that I need to use transistors and diodes... why? I don't suppose anyone has a how-to guide on this? Thanks!

#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 19 December 2011 - 05:13 AM

Hello Reactive.
The circuit shown is right to drive a relay, no matter whether your load is DC or AC. However, the relay must be targeted for a reliable and safe usage on high voltages (110VAC), as long as relatively high current (some Ampere).

The problem is just on the pump side, that is the relay contacts. Since a pump is a "coil" (i.e. a magnetic machine), it works as an inductor.
What's the problem?...The problem is when the contacts open.

Practical rule: an inductor "tries" to preserve the current flowing through it, by raising the voltage across its leads.

Thus, as soon the contacts open, the pump current will cease. However, since it's an inductor, it will raise the voltage (even kiloVolts), so that a spark easily happens between the contacts. This spark discharges all the magnetic energy, and the process is gone.
To solve this, you should place a capacitor across the contacts. Upon the pump specs, the capacitor can vary from 0.1uF to some uF.
In any case, it must be targeted for *at least* 250V, and it *cannot* be electrolytic or tantalum (i.e. polarized).
I'd suggest to ask your reseller.
Cheers
Biggest fault of Netduino? It runs by electricity.

#3 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 19 December 2011 - 08:28 AM

Hi Reactive, Mario I think Reactive's query is more about AC and DC, as he is not sure he can drive an AC circuit with a DC control voltage. The answer is that you can drive an AC pump with a DC control voltage, because a relay is actually two electrically isolated circuits. One circuits switches a switch in the other circuit but no current flows between them. One circuit you could call the coil circuit, Reactive needs to use a Relay with a dc coil as he is going to turn the relay on and off with DC coming from the Netduino. Use the famous diagram, it works. Anything Driven off the Netduino will always use a DC relay. The other circuit is the load circuit, the relay's part of which is just the equivalent of an on/off switch. for Reactive he should make sure that the relay can switch 110v AC at the pumps rated current. Reactive you don't need an AC relay you need a DC relay(5 or 12 volt). The difference is on the coil side. Both sorts of relays can switch both AC and DC loads but be aware that the voltage and current ratings for the load will be different and so each relay should come with ratings for both AC and DC loads.
STEFF Shield High Powered Led Driver shield.

#4 Daniel Minnaar

Daniel Minnaar

    Advanced Member

  • Members
  • PipPipPip
  • 46 posts
  • LocationJohannesburg, South Africa

Posted 19 December 2011 - 09:42 AM

Hello Reactive.
The circuit shown is right to drive a relay, no matter whether your load is DC or AC. However, the relay must be targeted for a reliable and safe usage on high voltages (110VAC), as long as relatively high current (some Ampere).

The problem is just on the pump side, that is the relay contacts. Since a pump is a "coil" (i.e. a magnetic machine), it works as an inductor.
What's the problem?...The problem is when the contacts open.

Practical rule: an inductor "tries" to preserve the current flowing through it, by raising the voltage across its leads.

Thus, as soon the contacts open, the pump current will cease. However, since it's an inductor, it will raise the voltage (even kiloVolts), so that a spark easily happens between the contacts. This spark discharges all the magnetic energy, and the process is gone.
To solve this, you should place a capacitor across the contacts. Upon the pump specs, the capacitor can vary from 0.1uF to some uF.
In any case, it must be targeted for *at least* 250V, and it *cannot* be electrolytic or tantalum (i.e. polarized).
I'd suggest to ask your reseller.
Cheers


Thanks Mario. The engineers already use the pump manually, so I'm sure that they've already implemented something to cater for the induction problem... or were you referring to the reason why I need a diode and transistor?

Hi Reactive, Mario

I think Reactive's query is more about AC and DC, as he is not sure he can drive an AC circuit with a DC control voltage.

The answer is that you can drive an AC pump with a DC control voltage, because a relay is actually two electrically isolated circuits. One circuits switches a switch in the other circuit but no current flows between them.

One circuit you could call the coil circuit, Reactive needs to use a Relay with a dc coil as he is going to turn the relay on and off with DC coming from the Netduino. Use the famous diagram, it works. Anything Driven off the Netduino will always use a DC relay.

The other circuit is the load circuit, the relay's part of which is just the equivalent of an on/off switch. for Reactive he should make sure that the relay can switch 110v AC at the pumps rated current.

Reactive you don't need an AC relay you need a DC relay(5 or 12 volt). The difference is on the coil side.

Both sorts of relays can switch both AC and DC loads but be aware that the voltage and current ratings for the load will be different and so each relay should come with ratings for both AC and DC loads.


Very helpful, thanks Magpie. So, all I need to do is get a 5VDC SSR which switches to 110VAC, and then just drive the digital pin high whenever I want the relay to switch?

#5 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 19 December 2011 - 10:02 AM

Hi Reactive Firstly I must own up, I have never yet used an SSR so my experience is zero, but I have recently bought 2 so that will change. SSR's (Solid State Relays) tend not to be as good for switching inductive loads, such as pumps and motors. I think a normal electromagnetic relay would be your best bet. 5volt relays wont be as common for relays with high current switching capability, so If you power your netduino off a 12 volt supply you can grab the 12 volts from the netduino itself and use a 12 volt relay. The 6th pin next to the two ground pins Vraw? . This will wire into the relays.pdf circuit as Relay Power V+. Use the diode in the circuit.
STEFF Shield High Powered Led Driver shield.

#6 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 19 December 2011 - 12:45 PM

Happy that you guys have found the solution. Sorry for misunderstanding the question. Cheers
Biggest fault of Netduino? It runs by electricity.

#7 Daniel Minnaar

Daniel Minnaar

    Advanced Member

  • Members
  • PipPipPip
  • 46 posts
  • LocationJohannesburg, South Africa

Posted 19 December 2011 - 01:59 PM

Hi Reactive
Firstly I must own up, I have never yet used an SSR so my experience is zero, but I have recently bought 2 so that will change.

SSR's (Solid State Relays) tend not to be as good for switching inductive loads, such as pumps and motors. I think a normal electromagnetic relay would be your best bet. 5volt relays wont be as common for relays with high current switching capability, so If you power your netduino off a 12 volt supply you can grab the 12 volts from the netduino itself and use a 12 volt relay. The 6th pin next to the two ground pins Vraw? . This will wire into the relays.pdf circuit as Relay Power V+.
Use the diode in the circuit.


Magpie, what do I do when the 12V relay is DC but I need to switch to AC? And do I need the transistor from the diagram? I'm also not very sure how I wire up the circuit with the digital output pin... or do I get to control the 12v vraw pin?

#8 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 19 December 2011 - 02:26 PM


Also, I've read that I need to use transistors and diodes... why?


Hi Reactive,

Why the transistor?

You need to use a transistor because the Netduino/Arduino digital outputs cannot provide enough current to directly drive the coil in the relay. The transistor is capable of handling more current; in this circuit, it acts as an on/off switch controlled by the Netduino. The resistor is there to allow enough current to flow from the Netduino to turn on the transistor. (In the relay diagram, for a Netduino and using the 1K ohm resistor, this will be around 2.6mA - which is a lot less than the 100mA or more that might be needed to drive a typical relay coil.)



The 5V or 12V coil in the relay is a type of inductor. When current passes through it, it stores up energy in a magnetic field.

As Mario was explaining, when you try to stop the current flowing through an inductor, that energy in the magnetic field has to go somewhere. Its a bit like trying to instantly stop a flywheel. In the case of in inductor, the stored energy causes the electrical current to want to keep flowing. If there is nowhere for the current to go, the voltage across the terminals of the inductor can shoot up. With a mechanical switch this can cause sparks, which in turn can burn away the switch contacts or can even weld the contacts together.

"Switch mode" power supplies use this principal to either boost or reduce a voltage without using a bulky transformer.

So why the diode?

Well when the transistor (our switch) is turned off, the current in the inductor will keep going - it has to. If it has nowhere to go, the voltage will build up and may destroy other components in the circuit - e.g. the transistor (and possibly the Netduino that is driving it!).
The diode stops this from happening by providing a short circuit across the coil to dump the current.

Referring to the relay diagram when the transistor is on, current flows from the top to the bottom through the transistor. At the moment the transistor turns off, the current instead flows clockwise through the diode averting disaster.


Finally as Mario described, a similar problem exists on the pump side of your relay - you can get a spark across the relay contacts. This poses little danger (if any) to the Netduino but may reduce the reliability or life of the relay. If the load was low voltage DC, you could just use another diode across the load. Since you are working with an AC load, you need a suitably rated capacitor across the relay terminals.

Hope this helps - Paul

#9 Daniel Minnaar

Daniel Minnaar

    Advanced Member

  • Members
  • PipPipPip
  • 46 posts
  • LocationJohannesburg, South Africa

Posted 19 December 2011 - 02:55 PM

Hi Reactive,

Why the transistor?

You need to use a transistor because the Netduino/Arduino digital outputs cannot provide enough current to directly drive the coil in the relay. The transistor is capable of handling more current; in this circuit, it acts as an on/off switch controlled by the Netduino. The resistor is there to allow enough current to flow from the Netduino to turn on the transistor. (In the relay diagram, for a Netduino and using the 1K ohm resistor, this will be around 2.6mA - which is a lot less than the 100mA or more that might be needed to drive a typical relay coil.)



The 5V or 12V coil in the relay is a type of inductor. When current passes through it, it stores up energy in a magnetic field.

As Mario was explaining, when you try to stop the current flowing through an inductor, that energy in the magnetic field has to go somewhere. Its a bit like trying to instantly stop a flywheel. In the case of in inductor, the stored energy causes the electrical current to want to keep flowing. If there is nowhere for the current to go, the voltage across the terminals of the inductor can shoot up. With a mechanical switch this can cause sparks, which in turn can burn away the switch contacts or can even weld the contacts together.

"Switch mode" power supplies use this principal to either boost or reduce a voltage without using a bulky transformer.

So why the diode?

Well when the transistor (our switch) is turned off, the current in the inductor will keep going - it has to. If it has nowhere to go, the voltage will build up and may destroy other components in the circuit - e.g. the transistor (and possibly the Netduino that is driving it!).
The diode stops this from happening by providing a short circuit across the coil to dump the current.

Referring to the relay diagram when the transistor is on, current flows from the top to the bottom through the transistor. At the moment the transistor turns off, the current instead flows clockwise through the diode averting disaster.


Finally as Mario described, a similar problem exists on the pump side of your relay - you can get a spark across the relay contacts. This poses little danger (if any) to the Netduino but may reduce the reliability or life of the relay. If the load was low voltage DC, you could just use another diode across the load. Since you are working with an AC load, you need a suitably rated capacitor across the relay terminals.

Hope this helps - Paul


That's an excellent guide, thanks Paul. Just out of interest - surely the resistor will restrict the amount of current flowing to the transistor, unless I use a parallel configuration?

If I use the digital output pin with it's 5V threshold, I suppose I wouldn't be able to drive a 12V relay as Magpie suggested using the raw V+ pin. If I can't find a 5V relay, what other options do I have?

#10 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 19 December 2011 - 03:58 PM

That's an excellent guide, thanks Paul. Just out of interest - surely the resistor will restrict the amount of current flowing to the transistor, unless I use a parallel configuration?

If I use the digital output pin with it's 5V threshold, I suppose I wouldn't be able to drive a 12V relay as Magpie suggested using the raw V+ pin. If I can't find a 5V relay, what other options do I have?


Thank you - I just added to the very sound replies from Mario & Magpie.
(Mario has started a Wiki page that is worth a visit.)

The whole point of the resistor is to restrict the current from the Netduino. The current flowing through the resistor goes to the base of the transistor and flows down to ground via the emitter. This current from the Netduino does not actually pass through the relay coil. Instead, when this very small current flows, it allows a much bigger current to flow from the collector to the emitter of the transistor. A transistor is an amplifier with a gain. The type of transistor shown amplifies the current flowing from base to emitter. (Other types of transistor use a voltage rather than a flowing current to control the output). In this case the amount of current through the resistor is large enough that the result is like an ON/OFF switch.

(The Netduino actually has 3.3V digital outputs.)

I believe that Magpie was suggesting that:
  • using a 5V relay, you could supply the relay coil voltage "Relay power V+" from the 5V pin on the Netduino.
  • using a 12V relay you might be able to power the relay from the Netduino Vin pin. This will depend on how you are powering the Netduino. You might for example be powering the Netduino using the maximum 12V on the barrel connector - in this case, the 12V would also be available on the Vin pin.

Note that the current you can draw from the 5V pin should not exceed 800mA. See the How much current can I draw... Wiki FAQ page.
The Vin output is not regulated like the 5V output, hence I am not sure how much current you may draw on the Vin pin. Without any other information, I would not exceed the 800mA.

Paul

#11 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 19 December 2011 - 09:35 PM

Hi all, Just one point If you do use the ciruit in the "famous diagram" you would be safe from overloading the netduino board. Assuming no wiring mistakes, and you are not using the 12volts also for the load circuit, the only way you could then overload the Netduino board is if you can actually buy a DC relay that uses more than 800mA in the coil. That would be a real power waster. See the relay spec sheet for coil current, or you may have to work it out from coil power or coil resistance. If you end up with a figure of < 800ma your circuit is ok. It's more likely to be 30-150 mA.
STEFF Shield High Powered Led Driver shield.

#12 dougY

dougY

    Member

  • Members
  • PipPip
  • 19 posts

Posted 09 February 2012 - 05:49 PM

....
To solve this, you should place a capacitor across the contacts. Upon the pump specs, the capacitor can vary from 0.1uF to some uF.
In any case, it must be targeted for *at least* 250V, and it *cannot* be electrolytic or tantalum (i.e. polarized).
I'd suggest to ask your reseller.
Cheers


hey mario. thanks for all the advice i see you giving.
its especially great for those of us coming from purely software backgrounds.

anyway, to follow up on what's quoted above, do you think this cap is enough for a relay that is switching on a compressor for a refrigerator that's rated at 1.4A 120VAC
http://search.digike...6014-ND/2208913
its rated 0.1uF and 500V

also, lets say the fridge had a larger motor of say 3A 120VAC (the 1.4A motor is for a small one)
how much would you need to step up capacity?
http://search.digike...-3510-ND/789642
this one is rated .22uF and 500V

#13 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 09 February 2012 - 06:46 PM

Doug, if the problem is the spark on a mechanical relay, then the value of the capacitor won't be critical at all. You may try to use one cap of 0.1 uF, or maybe two or three in parallel. When you put caps in parallel, the max voltage keeps the same (or the min among), but the overall capacity is the sum of all. So, buy 2-3 caps of 0.1 uF and forget the problem. Usually the *major* problems are related to the home energy counter. I don't know you, but here are almost all digital, thus the problem is over. Years ago, we had magnetic counters (a spinning disc), which were able to measure only one part of the energy. Let's say that voltage and current have normally a phase shift: for a pure resistor (e.g. iron, bulb, etc), the shift is zero. This kind of energy is fully measured by the "OLD" counters. BTW, if you connect a transformer without any load, the phase shift is about 90 degrees. The counters weren't able to measure this shift, and the Electric Company imposed to place capacitors, wherever the phase shift could be relevant. Hope it helps. Cheers
Biggest fault of Netduino? It runs by electricity.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.