Relay Module Status

I have a SainSmart 8 Relay Module hooked up to an Arduino nano. I am a bit confused with the status of this module. As an example, I have D2 of the Arduino board hooked up to relay #1.

When D2 is high (5V) then the LED for relay #1 is off When D2 is low (0V) then the LED for relay #1 is on

This is totally counter intuitive. If I have a signal to the pin then the LED should be on, and if there is no signal it should be off. The only way I can explain this is if they light the LED because they want to indicate the NO status. However, that doesn't make any sense because there are both NO and NC pins so there is no preference.

Now if I look at the actual output, the normally open connection is closed (connected) when my input is low (0V) and the normally open connection is open (disconnected) when my input is high (5V). So that also indicates that the status of the LED shows the NO status (it's off when disconnected, on when connected).

So basically I have

Input LED NO NC 0V on closed open 5V off open closed

This is confusing. I would expect that if I have an input of 0V the LED is off and the NO is open (disconnected). Instead, when I have 0V the LED is on and the NO is closed. What am I getting wrong?

With current technology available today, it is easier to switch the ground of a controlled device. In the past, with actual physical switches, it was easier to switch the positive. "Intuitive" is just history.

You code should use self-contained functions like fanOn() and then that function can take care of the polarity of the relay logic. You write the function to do what you want. If you get a different technology in the future, you only need to re-write one or two functions instead of searching all through your code for HIGH and LOW.

I usually use #define to get intuitive values

// if button is pressed, signal is low (button wired between pin and ground, use pull-up)
#define ISPRESSED LOW
// relay activated if low
#define RELAY_ON LOW

const byte btnPin = 3;
const byte relayPin = 2;

void setup()
{
  pinMode(btnPin, INPUT_PULLUP);
  pinMode(relayPin, OUTPUT);
}

void loop()
{
  if(digitalRead(btnPin) == ISPRESSED)
  {
    digitaWrite(relayPin, RELAY_ON);
  }
  else
  {
    digitaWrite(relayPin, !RELAY_ON);
  }
}

MorganS: With current technology available today, it is easier to switch the ground of a controlled device. In the past, with actual physical switches, it was easier to switch the positive. "Intuitive" is just history.

You code should use self-contained functions like fanOn() and then that function can take care of the polarity of the relay logic. You write the function to do what you want. If you get a different technology in the future, you only need to re-write one or two functions instead of searching all through your code for HIGH and LOW.

Actually, And active low circuit has been easy to implement since the early days of logic chips. you could always hook a LED either to the + or -, and have it light up accordingly. I was using both techniques in the 70s. And for most relay modules that's really all you're doing, lighting a LED, actually two LEDs. One LED is inside an optical coupler. And it doesn't matter which type logic output that you use, as long as the LEDs are in the right orientation. all logic use a totem pole output. One transistor is stacked on top of the other. These can be either an NPN, and PNP or a N, and P FET. when one transistors on the other is off. also, many logic gates applies a very small current from the input.

The Arduino logic outputs have three states, high, low, and high z. When the output is high, a positive voltage is applied. When the output is low, a negative voltage is applied. In the high z state, no voltage is applied. And one more thing you need to realize, electricity travels from negative to positive. Not positive to negative. So our logic thinking is actually backwards from what really happens. yes I know you learned that in school, or at least you should have, but sometimes it's hard for people to wrap their heads around it. All the Math still works or at least what we need. It only matters when you get into the chip design level.

sterretje: I usually use #define to get intuitive values

I don't know why this doesn't get recommended more often, regardless of the polarity of a system. "ISPRESSED" or "RELAY_ON" just makes so much more sense when you're reading a function.

mulu: When D2 is high (5V) then the LED for relay #1 is off When D2 is low (0V) then the LED for relay #1 is on

This is totally counter intuitive.

Not to me. The relay module (not the Arduino) supplies the power. The Arduino just has to sink it (switch to ground). Leo..

mulu: I have a SainSmart 8 Relay Module hooked up to an Arduino nano. I am a bit confused with the status of this module. As an example, I have D2 of the Arduino board hooked up to relay #1.

When D2 is high (5V) then the LED for relay #1 is off When D2 is low (0V) then the LED for relay #1 is on

This is totally counter intuitive.

I don't have the same relay module as you, but experienced the same thing in my rig. Oh and I agree, it does appear counter intuitive. One would reasonably expect that when the digital output from the Arduino is HIGH, that the NO relay contact swithces to CLOSED, and the NC relay contact switches to OPEN. Seems sensible.

I simply amended my code/relay connections accordingly to suit my requirement.

I use LEDs On to indicate active Relay coils on my relay boards. Shift a 1 into a shift register, the LED turns on, and the relay coil energizes. http://www.crossroadsfencing.com/BobuinoRev17/ Video of Uno-shield in action https://www.youtube.com/watch?v=ukRtgLK_b5c And the stand-alone version https://www.youtube.com/watch?v=oHTRGXyd3xU |500x304

@CrossRoads I think you're using a TPIC6x595/6 to drive those relays. That would require a HIGH (in the byte) from the Arduino to activate a relay. More logical for newbies. Leo..

I tried the famous Blink code with a slight amendment

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(8, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
   digitalWrite(LED_BUILTIN, HIGH);    // turn the LED off by making the voltage LOW
 delay(1000);                       // wait for a second
  digitalWrite(8, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second

When the UNO LED was on (HIGH) Pipn 8 was HIGH, but the LED on the relay board was off. The NO contact on the relay was closed.

Not a big deal as it's easy to amend in code or on the relay, but somewhat illogical - well, to me!

"This is totally counter intuitive. "

If you are serious about this stuff, you must be able to understand negative logic.

theMusicMan: When the UNO LED was on (HIGH) Pipn 8 was HIGH, but the LED on the relay board was off. The NO contact on the relay was closed.

Not a big deal as it's easy to amend in code or on the relay, but somewhat illogical - well, to me!

When you say closed, do you mean that power can go through the contacts, or not through the contacts.

I asked this because many people that is new to electronics get it wrong. When a switch is opened, the power cannot go through it. When a switch is closed, power can pass through the switch. On most relay boards, when the LED is on, the relay is energized. Which means power can go through the normally open contacts, but not through the normally closed contacts. the reverse is true when the relay is not energized.

I just want to clarify what you mean.

Hi Joe, yep that's how I understand it, too!

Here's another example of code and output for what's happening on my relay board, which is strange.

Example code 1

void setup() {
  // initialize digital pin LED_BUILTIN and PIN 8 as outputs.
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(8, OUTPUT);

}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(8, HIGH);   // turn the relay on (HIGH is the voltage level)
}

What I see from example code 1

The output (physical look) of my UNO and relay for the example code 1 above is:

Input PIN 13 = HIGH PIN 8 + HIGH

LED on pin 13 = ON LED on relay board = OFF NO contact on relay board = OPEN i.e. no power can get through NC contact on relay board = CLOSED i.e. power can get through

Example Code 2

void setup() {
  // initialize digital pin LED_BUILTIN and PIN 8 as outputs.
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(8, OUTPUT);

}

void loop() {
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(8, LOW);   // turn the relay on (HIGH is the voltage level)
}

What I see from example code 2

The output (physical look) of my UNO and relay for the example code 2 above is:

Input

PIN 13 = LOW PIN 8 = LOW

LED on pin 13 = OFF LED on relay board = ON NO contact on relay board = CLOSED i.e. no power can get through NC contact on relay board = OPEN i.e. power can get through

This is what I thought is counter intuitive.

" LED on pin 13 = ON LED on relay board = OFF NO contact on relay board = OPEN i.e. no power can get through NC contact on relay board = CLOSED i.e. power can get through [/color]"

" LED on pin 13 = OFF LED on relay board = ON NO contact on relay board = CLOSED i.e. no power can get through NC contact on relay board = OPEN i.e. power can get through "

Look at your statement carefully. Do you see the reason why I asked the question.

When a relay is (Not energized) no power can go through the normally open contacts. Power can only go through the normally closed contacts. The reverse is true when the relay is energized.

It's an easy mistake to make, since many science teachers refer to An open or closed door analogy when teaching electricity. but it is a bad analogy. And should not be used. They are not referring to a door. they are referring to the original style bar switch. when this type of switch is open, no contact is made. When it is closed, contact is made and the electricity can flow.

Also you need to understand that when the Arduino output pin goes low, power can flow from the Arduino to the input pin of the connected device. When the Arduino pin goes high, power can flow from the input pin of the connected device to the Arduino. In this case the relay board is your connected device. The 5V power pin on the relay board provides the power for the LED. If you remove the - power from the relay board, The LED will still light up, but the relays will no longer work. The negative is only used for the relays. The + pin provides power for the LEDs. It also provides power, Through a jumper to the relays. You can remove this jumper and provide power directly to the relay, from a second power supply. this is to provide total isolation between the relays and the control circuits. remember to remove the - connector from the Arduino board to your relays if you need total isolation. but if you remove the original + power connector, The LEDs will no longer work.

Hope this helps.

Thanks everybody for the replies. Apparently, I am not getting anything wrong but this is the way this module works. As for "thinking like a relay module is implemented", I suppose I could do that. However, I think it's totally reasonable to assume that the LED is on when power is supplied to an input and that NO is closed (because in the normal/not energized state it is open). I am not going to argue my point and just write my program accordingly (inverse the state). Thanks again!

Did you see what your mistake was.

" NO contact on relay board = OPEN i.e. no power can get through NC contact on relay board = CLOSED i.e. power can get through

" NO contact on relay board = CLOSED i.e. no power can get through NC contact on relay board = OPEN i.e. power can get through "

You used the same events regardless of whether the contacts were open or closed.

I was not arguing with you, but just wanted to make sure you understood what was happening. When reading this, if I did not know how the relay work, I would have no idea what you were talking about.

I apologize if you took it the wrong way, I was just trying to clarify what you were talking about.

Hey Joe, absolutely no offence taken at all matey! None whatsoever.