Arduino controlled popup headlamps

I am trying to get my pop headlamps to work with a 4 channel relay and a Arduino uno,
I don't know what i'm doing wrong, Any help would be appreciated.

const int buttonPin1 = 10; 
const int buttonPin2 = 11;
const int relayPin1 =  2;
const int relayPin2 =  3;  

// variables will change:
int buttonState1 = 0;      
int buttonState2 = 0;  

void setup() {
  // initialize the LED pin as an output:
  pinMode(relayPin1, OUTPUT);
  pinMode(relayPin2, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  Serial.begin(9600);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState1 == HIGH) {
    // Motor to up positon:
    Serial.println("UP");
    digitalWrite(relayPin1, HIGH);
    
  };
  if (buttonState2 == HIGH) {
    // Motor to down position:
     Serial.println("Down");
     digitalWrite(relayPin2, HIGH); 
     delay(1000);
  }
  else{
    digitalWrite(relayPin1,LOW);
    digitalWrite(relayPin2,LOW);
  }
    
  }

Helllo

Me too.
What is going wrong?
What do you expect?
What shall be happends?

The relays seem to do what ever they like, the switch does nothing.(in the photo i could only use buttons i'm using a center of rocker switch)
it could me my dodgy wires i got off aliexpress maybe ill go get some decent ones and try again.
I'm not sure if the codes is right i just pieced together bits and pieces from other projects i think i understand whats going on but i don't understand the "if" and "else" statements very well

Nice answer to look for a solution.
Didn´t you read my questions, did you?

Start by testing the relays and the buttons separately, in separate sketches, until you understand what you're doing.
Also, use "INPUT_PULLUP" instead of "INPUT" on the button pins a d connect the buttons/switch to the pin and GND instead of 5v.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.