Relay question

Hi,

I want to connect a simple relay to my Arduino but I can't seem to understand most tutorials. For as far as I know there are 5 ports on a relay:

  • NO (normally open)
  • NC (normally closed)
  • Com (where the ground of the circuit goes)
  • 5v (the arduino pin or 5v)
  • Gnd (arduino ground)

But most tutorials, like this one: http://makezine.com/2009/02/02/connecting-a-relay-to-arduino/
and the Keyes 5V Relay module for example, have a "Signal interface" port.
WHY is this??!!

The relay is triggered by 5V, so why do we have to connect 5v AND an Arduino output pin to the relay?? What's the use of the 5V connection?

Thanks in advance!

You do not have to connect both 5v power and your output pin to the line labeled 5v. Its labeled such because it takes 5 volts to cycle the relay, which it will receive from the output pin.

COM(Common): Is not Ground! (you may be using it that way, but to say that is always true is incorrect) It is the line that is being switched by the relay.
-When the relay is off COM is connected to NC and disconnected from NO.
-When the relay is on COM is connected to NO and disconnected from NC.

-Paul

Ah ok that explains. But then how is the diode connected? Would it be: Pin > transistor > diode > relay? Because the diode should be between the 5v and the pin..?

And where does the ground from the relay go? I don't see that in the sketch either.

edit: (To me it looks like the Arduino Pin is 'toggling' the transistor to connect the Ground from the relay to the Arduino ground.)

The relay is triggered by 5V, so why do we have to connect 5v AND an Arduino output pin to the relay?? What's the use of the 5V connection?

You don't just have a relay, you have a relay module. :wink: It has a transistor.

That means the Arduino's I/O pin (which can only supply up to 40mA) does not have to provide the current to the relay's coil. It only has to provide a 5V low-current "signal". However, this does mean you have to provide 5V power to the module, which would not be need when you directly power a relay coil. You also must provide a ground for the coil and/or transistor driver.

The coil-side of a relay is totally isolated from the contacts... The coil needs voltage & current and you can do whatever you wish with the contacts.

If you look at the SPDT schematic [u]here[/u], notice that "B" is connected to "C" (common). That's the "normal" condition so "B" is normally closed or "NC".

When the relay is activated "C" gets connected to "A" (normally open) and the the connection to "B" is broken. There is never a connection between A & B.

The common connection could be ground, or it can be whatever you want to use it for..... An example might be two speakers "A" & "B", with "C" connected to your stereo. The "normal" connection would be speaker-B, and with the relay coil energized, the sound would be switched-over to speaker-A. (With a stereo, you'd actually need a DPDT relay to handle left & right speaker pairs.)

Those relay modules are controlled by an opto-isolator ... just like connecting an LED and resistor, so that's why 5V and a control signal is required. Note that they use reverse logic, where LOW turns on the IRLED and activates the relay.

Use a separate power supply for the relay board.
To get full isolaton, remove the jumper and do not connect a ground wire from the relay board to the arduino.

Ok so it's the relay 'module' that I didn't quite understand. I however just have a normal relay, so I'll have to build that setup myself, using the sketch from flickr. Then I still don't understand where in that sketch the Ground from the relay has to go.

The arduino Pin (which is 5v..) goes to the transistor, and from there it goes to the relay. It also shows the 5v line going to the Relay but pguerra says that's just the Pin. So why is the transistor going to both the relay (as a 5v line) AND the ground of the Arduino?

Ah ok that explains. But then how is the diode connected? Would it be: Pin > transistor > diode > relay? Because the diode should be between the 5v and the pin..?

...And where does the ground from the relay go?

Don't worry about the transistor or diode. The manufacturer has (hopefully) got everything wired correctly. Wire 5V and ground as they are marked and Signal Interface goes to an Arduino I/O pin (whatever pin your sketch is "talking to ").

[u]This schematic[/u] shows how a transistor is used as a relay driver. But, you might not know if a "module" is made with a transistor, MOSFET, a driver IC, or it might have an optical isolator, etc.

The diode is wired "backwards" to "short out" the [u]back EMF[/u].

...When power is suddenly removed from a coil/inductor, the magnetic field collapses and this generates a voltage. Basically the current "tries" to keep flowing at the same mA rate it was flowing when powered. But, since the coil is now a generator (like a battery) and current is flowing in the same direction, the voltage is reversed.* The diode conducts in this reverse direction, all of the current is diverted through the diode.

...Hold on., here we go! The reversed voltage isn't usually the problem. The problem is when you suddenly "break" the circuit you have infinite resistance. Ohm's Law says you need infinite voltage to get current through infinite resistance. Of course, you don't get infinite voltage but you can get a thousand volts or more and often a spark!!!! It's usually that high voltage that causes the real damage to your electronics if you don't have the diode. (When you get a spark, the air is ionizing and you no longer have infinite resistance.)

  • Current flows from positive to negative in the "load", but since current flows "in a circle", that means the current inside the battery is flowing from negative to positive. When the magnetic field collapses and the coil starts acting like a generator with the current flowing in the same direction as before, but the voltage is reversed.

Then I still don't understand where in that sketch the Ground from the relay has to go.

In that circuit, the ground only goes to the transistor. There is no ground directly to the relay. (The relay gets "grounded" through the transistor, and that's what activated the relay.)

That makezene schematic shows an "extra" ground that you don't need. Just connect the Arduino's ground to the emitter of the transistor.

Thanks for the explanations :slight_smile:

DVDdoug:
In that circuit, the ground only goes to the transistor. There is no ground directly to the relay. (The relay gets "grounded" through the transistor, and that's what activated the relay.)

So (correct me if I'm wrong): The Arduino pin triggers the ground from the relay to the arduino gnd? This just doesn't make sense in my head since the pin is Positive and the Ground negative :stuck_out_tongue:

Think of it this way - the Arduino can control a High Side Switch, or a Low Side Switch.
Either way, current will flow from the Supply to Gnd when the switch is closed to energize the coil and make the relay contact flip from NC to NO.
If the supply is 12V, it is easier (needs fewer components) for the Arduino to control a Low Side Switch (i.e. transistor), because only a 5V signal is needed.
While the High Side, the control signal needs to go to 12V to turn the switch off, and Low to turn it on. 12V smokes the Arduino IO pin.

Ah thanks so much for that picture! I think I understand now :slight_smile:
Going to try it out and see if it works! :wink: Thanks to all for the help.