Switch On Off 2 Push buttons and 2 Relays

I'm trying to start a simple input output for Arduino to get input from a push button and light up 12V LEDs through relay board.

I have hooked everything up, the first relay work just fine (1 press light goes on and off when press again). when I connect the second relay, something went wrong it seem like stateButton2 is always high which cause the second LED to goes on and off by itself.

I'm quite sure that I have wired everything correctly as I swap the input pin once to another work fine.

Here is the code that I had, any advise would be highly appreciated.

/* sketch 
turn on light using relay and button
*/
int pinButton1 = 13;
int pinButton2 = 12;

int Relay1 = 2;
int Relay2 = 4;

int stateRelay1 = LOW;
int stateButton1;
int stateRelay2 = LOW;
int stateButton2;
int previous = LOW;
long time = 100;
long debounce = 300;

void setup() {
  pinMode(pinButton1, INPUT);
  pinMode(Relay1, OUTPUT);
  pinMode(pinButton2, INPUT);
  pinMode(Relay2, OUTPUT);
}
void loop() {
  stateButton1 = digitalRead(pinButton1);  
  if(stateButton1 == HIGH && previous == LOW && millis() - time > debounce) {
    if(stateRelay1 == HIGH)
      stateRelay1 = LOW; 
     else 
       stateRelay1 = HIGH; 
    
    time = millis();
  }
  
  digitalWrite(Relay1, stateRelay1);
  previous = stateButton1;
  
  stateButton2 = digitalRead(pinButton2);  
  if(stateButton2 == HIGH && previous == LOW && millis() - time > debounce) {
    if(stateRelay2 == HIGH)
      stateRelay2 = LOW; 
     else 
       stateRelay2 = HIGH; 
    
    time = millis();
  }
  digitalWrite(Relay2, stateRelay2);
  previous = stateButton2;
  
}

Remove your relays and deal with your pushbutton switches. Apparently, you have a switch on pin 13 and pin 12. Does your code work if you only have one switch that is connected to pin 13? Does your code work if you only have one switch that is connected to pin 12?

Learn to how to do troubleshooting.

First of all, thanks ieee488

I removed relays, then only one switch works on connected pin 13, that mean I have missed out something in the code.

samone3113: First of all, thanks ieee488

I removed relays, then only one switch works on connected pin 13, that mean I have missed out something in the code.

Take this opportunity to learn how to debug your own code.