Relay staying on despite code saying to be off

So I am building a lift system using an Adafruit metro mini. It's supposed to turn some relays on and off when a button is held down depending on the limit switch. Relay1 turns on and stays on for some reason. Relay11 turns on when the limit switch is pressed.

const int buttonInput = 1;
const int relay1Output = 2;
const int relay11Output = 3;
const int relay2Output = 4;
const int relay22Output = 5;
const int limitInput = 6;
const int limit2Input = 7;

void setup() {
    pinMode(buttonInput, INPUT_PULLUP);
    pinMode(relay1Output, OUTPUT);
    pinMode(relay11Output, OUTPUT);
    pinMode(relay2Output, OUTPUT);
    pinMode(relay22Output, OUTPUT);
    pinMode(limitInput, INPUT_PULLUP);
    pinMode(limit2Input, INPUT_PULLUP);
}

void loop() {
   if(digitalRead(buttonInput) == HIGH; digitalRead(limit2Input) == LOW){ 
   digitalWrite(relay1Output, HIGH);
   digitalWrite(relay11Output, HIGH);
   digitalWrite(relay2Output, LOW);
   digitalWrite(relay22Output, LOW);
   delay(5000);
} else {
   digitalWrite(relay2Output, LOW);
   digitalWrite(relay22Output, LOW);
   digitalWrite(relay1Output, LOW);
   digitalWrite(relay11Output, LOW);
}
   if(digitalRead(buttonInput) == HIGH; digitalRead(limitInput) == LOW){
   digitalWrite(relay2Output, HIGH);
   digitalWrite(relay22Output, HIGH);
   digitalWrite(relay1Output, LOW);
   digitalWrite(relay11Output, LOW);
   delay(5000);
} else {
   digitalWrite(relay2Output, LOW);
   digitalWrite(relay22Output, LOW);
   digitalWrite(relay1Output, LOW);
   digitalWrite(relay11Output, LOW);
}
}
if(digitalRead(buttonInput) == HIGH; digitalRead(limit2Input) == LOW)

Unusual location for a semicolon

   if(digitalRead(buttonInput) == HIGH; digitalRead(limit2Input) == LOW){
   if(digitalRead(buttonInput) == HIGH; digitalRead(limitInput) == LOW){

What are these lines supposed to do ?
What do they actually do ?

HINT : I see no logical or operator in either of them

“ despite code saying to be off”

Always, always blame yourself. :slight_smile:

TheMemberFormerlyKnownAsAWOL:

if(digitalRead(buttonInput) == HIGH; digitalRead(limit2Input) == LOW)

Unusual location for a semicolon

they used to be commas but changed after i saw some reference code with them to see if it was that.

UKHeliBob:

   if(digitalRead(buttonInput) == HIGH; digitalRead(limit2Input) == LOW){
   if(digitalRead(buttonInput) == HIGH; digitalRead(limitInput) == LOW){

What are these lines supposed to do ?
What do they actually do ?

HINT : I see no logical or operator in either of them

it's basically supposed to activate two relays if a button is pressed and a limit switch isn't down.

Try this:

if((digitalRead(buttonInput) == HIGH) && (digitalRead(limit2Input) == LOW){  // both pins are as desired?
// take your action
}
else {
// do nothing - or something else
}

Fix your other similar line also.

That kind of helped. When I click the limit switches it changes the relay. But the wrong one. If limit 2 is pressed, it turns relay 1 and 2 on. If I click limit 1 it turns relay 11 and relay 22 on. Relay 11 and 1 should go on at the same time and vice-versa. It ignores the button. If i click the button, an led flashes orange.

it's basically supposed to activate two relays if a button is pressed and a limit switch isn't down.

I have highlighted the magic word

In the serial monitor it shows 0 for the button until i click, then it shows backwards ? For the limit switch 1 it shows 0 at first and then 1 after i click. But it stays 1. If i click the second limit switch I get 0 until I release. It shouldn't even display the second limit switch.

All relays are on now when nothing is pressed but when i pressed the corresponding limit switch they work as intended. They are ignoring the button for some reason.

So fix up the logic now that you see how the syntax should be.

So the button reads 1 when it should be 0 due to the pullup so I adjusted it. It now works. Thanks for the help.