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);
}
}