arduino and relays

I am using an arduino uno and an 8 channel relay (http://www.ebay.com/itm/231682185473?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT)

I have the 5V and Ground from a regulated power supply going to jd-vcc and grnd on the relay with jumper removed. 5V from arduino going to relay board vcc, all 8 channels connected to pins 2-9.

The code that follows turns the relay board led's on and off as intended but the green led i have connected to channel 8 (or any channel for that matter) does not turn on when that relay is set to RELAY_ON. The ground( black wire) of the green led connected to common and the red wire connected to NC.

Any advice?

/* Relay Control Tests V1.0
Relay is active in LOW
To ensure no relay activation from reset until
application is ready, initialize relay on OFF MODE (HIGH).
When testing a 16 channel relay you should use an arduino MEGA
The code below uses an Arduino UNO R3
*/

/*-----( Import needed libraries )-----*/
#include "Streaming.h"

// Arduino Digital I/O pin numbers for UNO R3
//note: relay pins 13-17 are analog inputs 0-4 i.e., A0, A1, A2, A3, A4
enum {
Relay1 = 2, Relay2 = 3, Relay3 = 4, Relay4 = 5, Relay5 = 6, Relay6 = 7,
Relay7 = 8, Relay8 = 9, Relay9 = 10, Relay10 = 11, Relay11 = 12,
Relay12 = 13 , Relay13 = 14, Relay14 = 15, Relay15 = 16, Relay16 = 17
};

enum { RELAY_OFF = HIGH, RELAY_ON = LOW}; 

/*-----( Declare Variables )-----*/
const byte relays[]= { Relay1,Relay2,Relay3,Relay4,
Relay5,Relay6,Relay7,Relay8,
Relay9,Relay10,Relay11,Relay12,
Relay13,Relay14,Relay15,Relay16 };
enum { maxRelayCount = sizeof relays / sizeof relays[0] };

void setup()   //Initializes all variables and settings
{
Serial.begin(9600);
//Input the amount of relays on the board
// need to get this working next

//Set pins to OFF & declare pins as OUTPUTS
for (int i = 0; i < maxRelayCount; ++i) {
digitalWrite(relays[i], RELAY_OFF);
pinMode(relays[i], OUTPUT);
// Serial.print("Relay " +[i] + " set HIGH and as OUTPUTS");
Serial.print("Relay ");
Serial.print(i);
Serial.println(" set HIGH and as OUTPUT");;
}

//Check that all relays are inactive at Reset
delay(4000); 

}
void loop()   
{

//---( Turn all 8 relays ON in sequence)---
for (int i = 0; i < 8; ++i) {  //channel count hard-coded for now to 8
  digitalWrite(relays[i], RELAY_ON);    
  Serial.print("LED for relay #");
  Serial.print(i+1);
  Serial.println(" is on");
  delay(4000);
  digitalWrite(relays[i], RELAY_OFF);
  Serial.print("LED for relay #");
  Serial.print(i+1);
  Serial.println(" is now off");
  delay(1500);           
}
}

So, where does the energy to light the LED come from?

The ground( black wire) of the green led connected to common and the red wire connected to NC.

NC   normally closed
COM  common
NO   normally open

Your led is NS (normally shorted). You might want to consider using a current limiting resistor, the JD-VCC and NO terminals.

My led has a current limiting resistor on the negative side. I also tried it on the NO terminal. It still doesn't light. Am I wrong in assuming that a separately powered relay board supplies its voltage through the relay switch so that if it is LOW the 5V is supplied to whatever is attached to that specific relay, in this case the green led or does each item attached to a relay need its own power?

dinotom:
Am I wrong in assuming that a separately powered relay board supplies its voltage through the relay switch so that if it is LOW the 5V is supplied to whatever is attached to that specific relay...

If I'm understanding you correctly, then, yes, you're wrong about that. A relay board typically presents only the contacts of the relay, otherwise unconnected. This relay board seems to present a normally open contact, a common connection point, and a normally closed contact for each relay.

It looks like it might be this board - 8-Channel 5V Relay Module for Arduino Raspberry Pi – SainSmart.com. If so, then you can find a link to an archive file containing its schematic on that page.

A relay is just a switch you can operate electronically. It has either a connection between COM and NC or a connection between COM and NO. So it does not supply power :wink:

That is generally the function of a relay to isolate circuits. These relay modules can be used for mains voltages, which you certainly don't want connected to your Arduino.

Hi,
The separate power needed for your relay board is to drive the relay coils, not to provide power to the switched output terminals of the relays.
The relays must be separately powered as the arduino cannot supply the current needed to power the relay coils.

Hope this helps.. Tom.. :slight_smile:

Hi,
I think this is the schematic for your relay board.

Tom... :slight_smile:

8 channel relay.pdf (22.7 KB)

Thanks for clarifying that Tom, now I understand why my meter always showed 0V whether the relay was open or closed. So how would I wire the green led to the relay? Ground to ground obviously but not sure where the supply of power comes into play here between the relay and green led I'm using to see if switch turns on and off.

... as suggested in reply#2:

dlloyd, ty... I figured that out on the train into work will test later

dlloyd...it works now thank you for your assistance