Hello,
I have a question in regards to interlocking relays. I am looking for program 3 relays and some how interlock them. Meaning when Relay 1 is "ON" Relay 2, and Relay 3 must remain "OFF" until Relay 1 is switched "OFF". After Relay 1 status is "OFF" the program can check to see which of the remaining Relays needs to be turned "ON", at which point the remaining two relays must be "OFF". What is happening now is that multiple relays want to turn "ON" at the same time. This causes the relay board to make all kinds of weird sounds. The code is posted below:
const int ValueHigh1 = 100; // high value for turning Relay 1 off
const int ValueLow1 = 20; // low value for turning Relay 1 on
const int VlaueHigh2 = 90; // high value for turning Relay 2 off
const int ValueLow2 = 30; // low value for turning Relay 2 on
const int VlaueHigh3 = 75; // high value for turning Relay 3 off
const int ValueLow3 = 45; // low value for turning Relay 3 on
int R1=4; //digital pin for relay 1
int R2=5; //digital pin for relay 2
int R3=6; //digital pin for relay 3
void setup() {
//INITIALIZING RELAY STATES:
digitalWrite(R1,LOW); // OFF
pinMode(R1, OUTPUT);
digitalWrite(R2,LOW); // OFF
pinMode(R2, OUTPUT);
digitalWrite(R3,LOW); // OFF
pinMode(R3, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if ( R1 > ValueHigh1) { //sensor values inversed so when hit low turn on
digitalWrite(R1, HIGH); //on
digitalWrite(R2,LOW); //off
digitalWrite(R3,LOW); //off
}
if (R1 <= ValueLow1) {
digitalWrite(R1,LOW); //off
}
if ( R2 > ValueHigh2) { //sensor values inversed so when hit low turn on
digitalWrite(R2, HIGH); //on
digitalWrite(R1,LOW); //off
digitalWrite(R3,LOW); //off
}
if (R2 <= ValueLow2) {
digitalWrite(R2,LOW); //off
}
if ( R3 > ValueHigh3) { //sensor values inversed so when hit low turn on
digitalWrite(R3, HIGH); //on
digitalWrite(R1,LOW); //off
digitalWrite(R2,LOW); //off
}
if (R3 <= ValueLow3) {
digitalWrite(R3,LOW); //off
}
}
Please note that I am not using any kind of delay function or loop because i want this to be continuous. Furthermore, R1,R2, and R3 have "ValueHigh" and "ValueLow" values that overlap. Simply changing these values will not solve the problem, because those values must overlap for the project. I am seeking help for the "interlocking" feature/code if one exists. Or any ideas on how to tackle this problem.
Note: I also tried using "and" conditions within my "if" statement. For example, if ( (R1 > ValueHigh1 ) && (R2==LOW) && (R3==LOW) ) then execute desired function. Problem here is it never goes into any of the "if" loops when written as such because there are times when "ValueHigh1" , "ValueHigh2", and "ValueHigh3" are all reached at the same time causing all Relay status' to be HIGH.
