First thanks for taking the time to read this.
I have a Mega 2560 and I purchased 2 8 relay boards. My code is listed below, when run the program all my relays come on?
Here is the stranger thing, when digitalWrite(Relay1, HIGH) - it will turn it off!!!!!
I don't want all the relays one upon power up, I'd like all relays to stay LOW until told to go HIGH.It could be in these boards I guess, unless I'm not getting something correct in my program.
There is a jumper (on the relay board) that can let you move it to two of three pins. How it is in the photo the relays will click even though they are backwards (HIGH is off and Low is ON). If I take the jumper off the leds will come on and off following the code but the relays do not click (come on). If I put the jumper the other way it turns off the ardunio (shorting it from what I can tell).
Link to the board I'm using below:
VCC on the relay board is going to 5V on the Ardunio
GND on the relay board is going to GND on the Ardunio
IN1 on the relay board is going to pin 22 on the Ardunio
IN2 " 23
IN3 " 24
IN4 " 25
IN5 " 26
IN6 " 27
IN7 " 28
IN8 " 29
******************** ACTUAL CODE BELOW ********************
// put your setup code here, to run once:
//
//
// Ardunio Input Setup //
int Input1 = 1;
int Input2 = 2;
int Input3 = 3;
int Input4 = 4;
int Input5 = 5;
int Input6 = 6;
int Input7 = 7;
int Input8 = 8;
int Input9 = 9;
int Input10 = 10;
int Input11 = 11;
int Input12 = 12;
int Input13 = 13;
int Input14 = 14;
int Input15 = 15;
int Input16 = 16;
int Input17 = 17;
int Input18 = 18;
int Input19 = 19;
int Input20 = 20;
int Input21 = 21;
// Relay Board 1 Setup
//
int Relay1 = 22; //Relay #1 Relay Board #1
int Relay2 = 23; //Relay #2 Relay Board #1
int Relay3 = 24; //Relay #3 Relay Board #1
int Relay4 = 25; //Relay #4 Relay Board #1
int Relay5 = 26; //Relay #5 Relay Board #1
int Relay6 = 27; //Relay #6 Relay Board #1
int Relay7 = 28; //Relay #7 Relay Board #1
int Relay8 = 29; //Relay #8 Relay Board #1
//
// Relay Board 2 Setup
//
int Relay9 = 30; //Relay #9 Relay Board #2
int Relay10 = 31; //Relay #10 Relay Board #2
int Relay11 = 32; //Relay #11 Relay Board #2
int Relay12 = 33; //Relay #12 Relay Board #2
int Relay13 = 34; //Relay #13 Relay Board #2
int Relay14 = 35; //Relay #14 Relay Board #2
int Relay15 = 36; //Relay #15 Relay Board #2
int Relay16 = 37; //Relay #16 Relay Board #2
int FirstScan = 40;//Internal Bit Turned On During First Scan and Never Turned Off.
//
//
//
void setup() {
//
// Setup For Ardunio To Monitor Pins 1 through 21 as Inputs
//
pinMode(Input1, INPUT); // Sets The Ardunio Pin 1 As A Digital Input
pinMode(Input2, INPUT); // Sets The Ardunio Pin 2 As A Digital Input
pinMode(Input3, INPUT); // Sets The Ardunio Pin 3 As A Digital Input
pinMode(Input4, INPUT); // Sets The Ardunio Pin 4 As A Digital Input
pinMode(Input5, INPUT); // Sets The Ardunio Pin 5 As A Digital Input
pinMode(Input6, INPUT); // Sets The Ardunio Pin 6 As A Digital Input
pinMode(Input7, INPUT); // Sets The Ardunio Pin 7 As A Digital Input
pinMode(Input8, INPUT); // Sets The Ardunio Pin 8 As A Digital Input
pinMode(Input9, INPUT); // Sets The Ardunio Pin 9 As A Digital Input
pinMode(Input10, INPUT); // Sets The Ardunio Pin 10 As A Digital Input
pinMode(Input11, INPUT); // Sets The Ardunio Pin 11 As A Digital Input
pinMode(Input12, INPUT); // Sets The Ardunio Pin 12 As A Digital Input
pinMode(Input13, INPUT); // Sets The Ardunio Pin 13 As A Digital Input
pinMode(Input14, INPUT); // Sets The Ardunio Pin 14 As A Digital Input
pinMode(Input15, INPUT); // Sets The Ardunio Pin 15 As A Digital Input
pinMode(Input16, INPUT); // Sets The Ardunio Pin 16 As A Digital Input
pinMode(Input17, INPUT); // Sets The Ardunio Pin 17 As A Digital Input
pinMode(Input18, INPUT); // Sets The Ardunio Pin 18 As A Digital Input
pinMode(Input19, INPUT); // Sets The Ardunio Pin 19 As A Digital Input
pinMode(Input20, INPUT); // Sets The Ardunio Pin 20 As A Digital Input
pinMode(Input21, INPUT); // Sets The Ardunio Pin 21 As A Digital Input
//
// Setup For Ardunio To Control Relays 1 Through 8 On Relay Board #1.
//
pinMode(Relay1, OUTPUT); // Sets The Ardunio Pin 22 As A Digital Output
pinMode(Relay2, OUTPUT); // Sets The Ardunio Pin 23 As A Digital Output
pinMode(Relay3, OUTPUT); // Sets The Ardunio Pin 24 As A Digital Output
pinMode(Relay4, OUTPUT); // Sets The Ardunio Pin 25 As A Digital Output
pinMode(Relay5, OUTPUT); // Sets The Ardunio Pin 26 As A Digital Output
pinMode(Relay6, OUTPUT); // Sets The Ardunio Pin 27 As A Digital Output
pinMode(Relay7, OUTPUT); // Sets The Ardunio Pin 28 As A Digital Output
pinMode(Relay8, OUTPUT); // Sets The Ardunio Pin 29 As A Digital Output
//
// Setup For Ardunio To Control Relays 9 Through 16 On Relay Board #2.
//
pinMode(Relay9, OUTPUT); // Sets The Ardunio Pin 22 As A Digital Output
pinMode(Relay10, OUTPUT); // Sets The Ardunio Pin 23 As A Digital Output
pinMode(Relay11, OUTPUT); // Sets The Ardunio Pin 24 As A Digital Output
pinMode(Relay12, OUTPUT); // Sets The Ardunio Pin 25 As A Digital Output
pinMode(Relay13, OUTPUT); // Sets The Ardunio Pin 26 As A Digital Output
pinMode(Relay14, OUTPUT); // Sets The Ardunio Pin 27 As A Digital Output
pinMode(Relay15, OUTPUT); // Sets The Ardunio Pin 28 As A Digital Output
pinMode(Relay16, OUTPUT); // Sets The Ardunio Pin 29 As A Digital Output
pinMode(FirstScan, OUTPUT); //Sets The Ardunio Pin 40 As A Digital Output Wired To Nothing.
}
void loop()
{
// put your main code here, to run repeatedly:
digitalWrite(Relay1, HIGH);
}