Problem controlling a 4 channel relay shield with 7 inputs

Hi, I am using an Arduino Mega to control 4 relays (on a shield) with 7 inputs. The inputs are controlled by breaking a 5V line with 24V relays that i swithed also externally by limit switches.

The problem that I am having is once I connect power to the system the third 5V relay on the relay shield instantly comes on (switches), and when I simulate the inputs all four relays flickeron and off.

Here is the code that I used:

int Relay1 = 25;
int Relay2 = 27;
int Relay3 = 29;
int Relay4 = 31;
int Pot1 = A0;
int Pot2 = A1;

int Sig1 = 48;
int Sig2 = 46;
int Sig3 = 44;
int Sig4 = 42;
int Sig5 = 40;
int Sig6 = 38;
int Sig7 = 36;
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int val6 = 0;
int val7 = 0;
int Pot1val = 0;
int Pot2val = 0;

void setup() {
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(Sig1, INPUT);
pinMode(Sig2, INPUT);
pinMode(Sig4, INPUT);
pinMode(Sig5, INPUT);
pinMode(Sig6, INPUT);
pinMode(Sig7, INPUT);
pinMode(HDL1, INPUT);
pinMode(FDL2, INPUT);

}

void loop() {
val1 = digitalRead(Sig1);
val2 = digitalRead(Sig2);
val4 = digitalRead(Sig4);
val5 = digitalRead(Sig5);
val6 = digitalRead(Sig6);
val7 = digitalRead(Sig7);
Pot1val = analogRead(Pot1);
Pot2val = analogRead(Pot2);

if ((val1 == HIGH) && (val6 == HIGH) && (val2 == LOW)) {
digitalWrite(Relay1, HIGH);
}
delay(10);

if ((val1 == HIGH) && (val6 == HIGH) && (val2 == HIGH)) {
digitalWrite(Relay2, HIGH);
}
delay(10);

if ((val1 == HIGH) && (val5 == HIGH) && (val2 == HIGH)) {
digitalWrite(Relay2, LOW);
delay(Pot1val * 30);
digitalWrite(Relay3, HIGH);
}
delay(10);

if ((val1 == HIGH) && (val6 == HIGH) && (val2 == HIGH)) {
digitalWrite(Relay3, LOW);
digitalWrite(Relay1, LOW);
} 
delay(10);

if ((val1 == HIGH) && (val6 == HIGH) && (val2 == LOW)) {
digitalWrite(Relay2, HIGH);
}
delay(10);

if ((val1 == HIGH) && (val4 == HIGH) && (val2 == LOW)) {
delay(Pot2val * 30);
digitalWrite(Relay4, HIGH);
} else if (val7 == HIGH) {
  digitalWrite(Relay4, LOW);
}
delay(10);

}

I am attaching a drawing that I made of the circuit, unfortunately I don't know how to insert it in the post sorry.

Please let me know if I need to supply any additional information.

Show us the actual image of the wiring.
Give links to components.
Posting images:
https://forum.arduino.cc/index.php?topic=519037.0

You may need to turn on INPUT_PULLUP on your inputs.
You may need kickback diodes on the relay coils.

Hi larryd,

Thank you for your quick response.

Here is the photo of the wiring (it's a bit rough because we are trying to determine where the problem is :o ):

Try again to attach the image.

See instructions in the link post #2.

Sorry, here are the links:

Mega board:
Mega Board

Relay Shield:
4 Channel Relay Shield

Blank Shield(for screw terminals):
Mega Prototyping Shield V3

12v Power Supply(for powering the Mega board):
12V Power Supply

And the image:

Relay module cct.

Take a picture of your complete circuit wiring and attach it to a post..

Give a link for Sig1-7.

Read this:
https://forum.arduino.cc/index.php?topic=519037.0%20%C2%A0%20%C2%A0

troubleshooting technique: the wolf fence

you have:

void loop() {
val1 = digitalRead(Sig1);
val2 = digitalRead(Sig2);
val4 = digitalRead(Sig4);
val5 = digitalRead(Sig5);
val6 = digitalRead(Sig6);
val7 = digitalRead(Sig7);
Pot1val = analogRead(Pot1);
Pot2val = analogRead(Pot2);

if ((val1 == HIGH) && (val6 == HIGH) && (val2 == LOW)) {
digitalWrite(Relay1, HIGH);
}
delay(10);

if ((val1 == HIGH) && (val6 == HIGH) && (val2 == HIGH)) {
digitalWrite(Relay2, HIGH);
}
delay(10);

if ((val1 == HIGH) && (val5 == HIGH) && (val2 == HIGH)) {
digitalWrite(Relay2, LOW);
delay(Pot1val * 30);
digitalWrite(Relay3, HIGH);
}
delay(10);

if ((val1 == HIGH) && (val6 == HIGH) && (val2 == HIGH)) {
digitalWrite(Relay3, LOW);
digitalWrite(Relay1, LOW);
}
delay(10);

if ((val1 == HIGH) && (val6 == HIGH) && (val2 == LOW)) {
digitalWrite(Relay2, HIGH);
}
delay(10);

if ((val1 == HIGH) && (val4 == HIGH) && (val2 == LOW)) {
delay(Pot2val * 30);
digitalWrite(Relay4, HIGH);
} else if (val7 == HIGH) {
  digitalWrite(Relay4, LOW);
}
delay(10);

}

which tells you nothing if it does not work

if you change that to:

void loop() {
val1 = digitalRead(Sig1);
val2 = digitalRead(Sig2);
val4 = digitalRead(Sig4);
val5 = digitalRead(Sig5);
val6 = digitalRead(Sig6);
val7 = digitalRead(Sig7);
Pot1val = analogRead(Pot1);
Pot2val = analogRead(Pot2);

Serial.println("vals", val1, val 2, val3, val4, val5, val6, val7);

if ((val1 == HIGH) && (val6 == HIGH) && (val2 == LOW)) {
Serial.println("Relay 1 on");
digitalWrite(Relay1, HIGH);
}
delay(10);

( ...et cetera, et cetera, et cetera )

}

you have information available in the serial monitor about what goes into the Arduinos decision making process. you may have noticed that almost every sketch you see has:

Serial.begin(115200); in void setup()

that sets up the serial monitor. the number in the middle box at the bottom of the serial monitor must match the number in the parentheses. you can adjust either, but they must match

Confirm the voltage going to the Sig1-7 contacts are 5 volts.

Hi Geek Emeritus, thank you for the advice! We are going to add the Serial.println lines in now and see what the board is reading. We have tested the external 5V that we use as a signal, and it is 5V.

Thank you so much for all the info larryd, do you think our code could cause any clashes with each other? We would like each of the if statements to run in sequence after one another.

Here is the link to the 24VDC relays we are using to break and give signal to the Arduino Mega:
Rhomberg R5502 8 Pin Relay

Thank you both for all your help so far, we really do appreciate your time.

There maybe interference from the birds nest of wires that is causing your problems.

Confirm the coils on the Sig1-7 relays have kickback diodes.
These diodes absorb switching spikes when the Sig relays operate, 1N4007 would work.
Example:
D11 (across relay coil K5) protects Q3 in the circuit below.

You will need 1 diode for each Sig relay coil.

I may be blind, but, nothing stands out in the sketch that might cause what you are observing.

Proceed with trying to debug using Serial prints.

You can also try a ‘very basic’ sketch that controls one relay when a Sig contact is closed.
Then add a second relay, a third, a fourth etc.

You may have to reroute or shorten Arduino signal and power wires so they do not pick up noise.

Edit
What are these inputs?
HDL1
FDL2

Confirm your 24v power supply is not referenced to the Arduino circuit side.
i.e. GND of the 24V supply is ‘not’ connected to the Arduino GND.

BTW
The 5RL relay board relays should ‘not’ be powered by the Arduino on board regulator ! !