Power supply best practices question for relay module

Hello,

I am constructing a 120VAC fan controller project. The fan itself will be activated with this relay module.

The module requires a 5VDC power source and has an opto-isolated trigger input that draws 5mA from what I can tell. This will be controlled by an Arduino Uno R3.

In prototyping I have supplied the 5VDC to the relay module directly from +5V and GND on the UNO. This works just fine and does not seem to cause any issues. When the coil it engaged, I am measuring about 60mA of current draw on the modules power leads. I'm not totally sure if that is excessive or not for the +5V Uno supply.

I am wondering what would be the best practice for powering this relay once built into a permanent solution. My initial thoughts were one of the following:

  • Use a separate wall wort or usb brick to provide power to the Arduino and then continue using 5V power directly from the Uno to power the relay.

  • Use a separate wall wort or usb brick to provide power to the Arduino. Use the same power supply to go the the relay independently and tie the grounds together between the Arduino and the relay. This would be in an effort to reduce the current that the Arduino has to supply.

  • Some other third thing that I don't know about.

Additionally I wonder if it is more proper/normal to have the external DC power supply as described above or to tap off of the 120VAC inside the project enclosure and run a 5VDC power supply inside the enclosure, thus eliminating the extra cord.

Thank you for your time and for any information you can provide on what is the best way to approach this.

Oh also, this is my first real project after finishing the tutorials. While everything seems to work in the prototype, would it be appropriate to create a post in this forum with all details, just asking for general thoughts and code review?

It’s not a good idea to significantly load the 5v pin, depending on your input voltage and the load you can overheat the Arduino voltage regulator because of the power it has to then dissipate .

I would use a power supply to generate 5v dc ( stabilised) from wherever you like , and feed the Arduino via the 5v pin , and the relay module from the same supply .

mmitchellmoss:
would it be appropriate to create a post in this forum with all details, just asking for general thoughts and code review?

Yes, that is considered normal around here...

@hammy, Thank you for the response. That is definitely what I will do then so as to not load the Arduino too heavily. I have a question though. You said:

hammy:
feed the Arduino via the 5v pin , and the relay module from the same supply .

Does this mean that I can also supply Vin to an Arduino by applying it to the +5V terminal of the Arduino. Sorry if that is a dumb question, but I am very new to this and have only used the USB terminal for power so far.

@aarg, Thanks, that sounds great. I will try to get a post together to solicit everyones' input.

one of those things that is obvious after it's explained, but not before:

  • if you run a current through a wire, you generate a magnetic field
  • if you pass a magnetic field across a wire, you generate a current
  • if you pass a current through a coil of wire you get a larger magnetic field, because more wire
  • if you cut off that current, the larger magnetic field collapses
  • back into the coil
  • generating a reverse polarity voltage spike back into the current source
  • which explains the vast blue spark when you unplug a coil

and your Arduino eats that reverse spike. On an old Triumph motorcycle, 6 volt coils, I measured 321 V spikes when the points opened.

which is why NASA was insistent that the products they bought have a diode across the rely coil, with a high enough PIV ( Peak Inverse Voltage ) rating to shunt the voltage spike to ground or the regulated power supply:

you have the same situation on the load side. in the drawing above, if COM is a power source, and NO & NC both go to inductive loads, both NO & NC need a diode that is reverse biased to the load voltage, shunting the reverse spike from the load to ground. A diode on COM can't work, because it will be disconnected at the precise time it is needed.

it is called a commutating diode. this is not a particular kind of diode, like a zener or Schottky diode. It's a generic diode that is used to mitigate the effect of polarity reversal.

SSRs do not need commutating diodes on the 5 volt logic side, but use them on the load side.

Hi Geek Emeritus,

Thank you very much for your well written response.

I am familiar with adding the diode across the coil to shunt the induced current upon field collapse. However, I have never thought about the need for it on the load side when dealing with an inductive load.

I am having a bit of trouble visualizing the diode(s) on the load side. Given that it is an A/C circuit, I would think that traditional diodes would not work as they would be forward biased half the time. I am assuming that is why you mentioned the Zener diode. Is the thought that you would choose a value of 200 Volts or something like that for a 120V source and then it would only conduct if there were a power-off spike? Also, when you say that they should be connected from NO & NC to ground, do you mean to Neutral or to the actual A/C ground? I realize that they are both really the same wire as far as potential difference is concerned, but I didn't know if there was a real-world difference that I should be aware of.

I have attached a drawing of what I am thinking of. Is this about right? Would I need a diode on the NC side if I am not using that contact?

Thank you again.

Does this mean that I can also supply Vin to an Arduino by applying it to the +5V terminal of the Arduino.

If you look at your Arduino you’ll see both a Vin pin and a 5V pin. So it can be a little confusing. The 5V pin can only take a well regulated 5 volt supply input. The Vin pin can only take 7-12v because it feeds into the onboard voltage regulator.

So yes, what @hammy is suggesting above is taking the 5v supply and connecting it to the Arduino 5V pin.

Officially speaking the 5V pin is supposed to be an output but you can also supply the Arduino with it if you trust your supply.

If you supply 7-12v to the Vin pin, then there will be 5 volts available as an output on the 5V pin.

So depending on how you are setting things up, that 5V pin can be used either as an input or output.

@steve20016, that makes perfect sense. Thank you very much for the explanation of how those pins operate.

That relay module is not opto-isolated unless you remove the jumper and connect the centre pin to your Arduino Vcc or ground with the "IN" pin to the Arduino I/O pin and connect the "DC+" and "DC-" pins separately to your relay supply.


Perhaps most importantly, is that you keep all the wires for each function - connections to the opto-coupler and power for the relay - bundled together. In your case, you might as well use the link and run the three wires as a bundle, from relay module to Arduino.

As you note, this relay requires about 60 mA to actuate. This will generally be tolerable if you are powering it through the USB jack as most power sources you connect will be able to provide up to 500 mA. The UNO has a "polyfuse" intended to shut it off if you attempt to draw more current than that through the USB jack. Even the extra 60 mA for the relay is however a bit much to ask if you wanted to power the UNO through "Vin" or the "Barrel jack" and in general it is simply not appropriate to use these power options for any "real world" applications.

Now it is appropriate to power the Arduino with regulated 5 V through the "5V" pin, noting that it will not in any case need to draw more than a couple of hundred mA itself. The only thing about which you need to be cautious, is that it may according to some pundits be undesirable to have it powered through the "5V" pin while it is plugged into the USB port on a PC for programming or using the serial monitor.

As you also note, you cannot use a diode "snubber" across the relay contacts for AC, you need a resistor-capacitor network using a mains-rated capacitor. These are actually available as a single component - but it is likely to be cheaper to use a separate resistor - generally of the order of 100 Ohms (as pictured) and a mains rated capacitor of a fraction of a microfarad.

@Paul__B, thank you for that well written detailed post. That is great information.

That relay module is not opto-isolated unless you remove the jumper and connect the centre pin to your Arduino Vcc or ground with the "IN" pin to the Arduino I/O pin and connect the "DC+" and "DC-" pins separately to your relay supply.

Ahhhh, that is the kind of information that would have been nice to have been included with unit. Thank you very much. I'd like to try and find a schematic for the thing some time to see what all is going on in there.

When you say:

Paul__B:
Perhaps most importantly, is that you keep all the wires for each function - connections to the opto-coupler and power for the relay - bundled together. In your case, you might as well use the link and run the three wires as a bundle, from relay module to Arduino.

Is the main reason for saying this is important is that we are trying to physically separate the high voltage wiring from the control wiring so as to not risk cross connection, or was there another reason like interference or something like that.

Also, thanks for the information on the power supply specs for the various ways of feeding the Arduino. That helps a lot.

you need a resistor-capacitor network using a mains-rated capacitor. These are actually available as a single component - but it is likely to be cheaper to use a separate resistor - generally of the order of 100 Ohms (as pictured) and a mains rated capacitor of a fraction of a microfarad.

Very cool. I did not know that these existed. I looked them up and they do seem kind of pricey. I'll have to look into making some of them as you described.

mmitchellmoss:
Is the main reason for saying this is important is that we are trying to physically separate the high voltage wiring from the control wiring so as to not risk cross connection, or was there another reason like interference or something like that.

And indeed it is of course both of these matters.

You always need to keep the high (mains) voltage physically and clearly separate from the low voltage for safety, but it is also most important to avoid the switching impulses that can cause the arcing of relay contacts, from being coupled back into the microprocessor circuitry and causing code and hardware such as displays to malfunction and crash.

Coupling can be both electrostatic over the stray capacitance between one wire and another, and electromagnetic where a loop of wire in which the current transient occurs, inductively couples an another nearby loop of wire in the signal and control circuits. This is why it is important to keep both wires of any given circuit together so that the electric field from any one wire tends to be cancelled by the adjacent ground (and supply) return and they do not form any open loops which can produce or pick up a magnetic field.