Troubling problem more lines in the coded added, then less power?

Hello experts

I have this weird problem with my relay project

I have 9 different inputs, they are supposed to turn on and off either one or both of the relays

However...

When I add more functions than two in the programming, the relays will not activate, and will instead just emit light from the status LEDS

It is a "standard" dual LED relay board, and in itself i works well

if I only have one function in the code, then there is no problem, if i add a function more, the "click" from the relays are dimmer

if I add even more (more than two), the relays will not even give a "click" sound but just emit a dim light from the status LEDS

It should be said, I have very little programming skills, and because of the problem escalates, depending of lines of code the I will assume the problem is in the coding

The circuit is quite large, but all input/outputs have been tried individually to rule out a bad or floating input/output with no problem, several power supply's have also been tried, with no different result

I really need some help, thank you

I do hope I have put this under the right segment

There are right now 4 of what I describe as functions

They are called "knap" it means button in danish, and that also will explain if my english writing might be a little off

const int LEDPin1 = 5; 
const int relayPin1 = 2; 
const int relayPin2 = 11; 
const int buttonPin1 = A0;
const int buttonPin2 = A1;
const int buttonPin3 = A2;
const int buttonPin4 = A3;
const int buttonPin5 = A4;
const int buttonPin6 = A5;



int buttonState = 0;

void setup() {

  pinMode(relayPin1, OUTPUT);  
  pinMode(relayPin2, OUTPUT);   
  pinMode(buttonPin1, INPUT); 
  pinMode(buttonPin2, INPUT); 
  pinMode(buttonPin3, INPUT); 
  pinMode(buttonPin4, INPUT);  
  pinMode(buttonPin5, INPUT); 
  pinMode(buttonPin6, INPUT); 

}

void loop() {

//Motorstart
  buttonState = digitalRead(buttonPin4); 

  if (buttonState == HIGH) {        
    digitalWrite(relayPin1, LOW);        
    digitalWrite(relayPin2, LOW);       
    digitalWrite(LEDPin1, HIGH);    
  }
  else {

    digitalWrite(relayPin1, HIGH);        
    digitalWrite(relayPin2, HIGH);          
    digitalWrite(LEDPin1, LOW);         
  }
//Motorstart

//Knap 1
  buttonState = digitalRead(buttonPin1); 

  if (buttonState == HIGH) {           
    digitalWrite(relayPin1, LOW);         
    digitalWrite(relayPin2, LOW);         
  }
  else {

    digitalWrite(relayPin1, HIGH);         
    digitalWrite(relayPin2, HIGH);        
  }
//Knap 1

//Knap 2
  buttonState = digitalRead(buttonPin2); 

  if (buttonState == HIGH) {           
    digitalWrite(relayPin1, LOW);           
    digitalWrite(relayPin2, LOW);           
  }
  else {

    digitalWrite(relayPin1, HIGH);          
    digitalWrite(relayPin2, HIGH);          
  }
//Knap 2

//Knap 3
  buttonState = digitalRead(buttonPin3); 

  if (buttonState == HIGH) {           
    digitalWrite(relayPin1, LOW);         
    digitalWrite(relayPin2, LOW);       
  }
  else {

    digitalWrite(relayPin1, HIGH);          
    digitalWrite(relayPin2, HIGH);         
  }
//Knap 3

//Knap 4
  buttonState = digitalRead(buttonPin4); 

  if (buttonState == HIGH) {           
    digitalWrite(relayPin1, LOW);       
    digitalWrite(relayPin2, LOW);     
  }
  else {

    digitalWrite(relayPin1, HIGH);        
    digitalWrite(relayPin2, HIGH);        
  }
//Knap 4

}

What are the secifications of the power supply for the relay coils?

How are the buttons wired?

Please post a schematic showing all components and power supplies.

You only have one buttonState although you have many buttonPin1/2/3 etc.

So buttonState is being updated a gazillion times a second as it loop()s, and relays can't keep up.

Quick fix is to use buttonState1/2/3 etc.

Longer term fix is use arrays.

Hello Thank you for your answers

@ twinkleyan
unfortunately I do not have the competence to set it up as arrays, and it did not help my situation with the buttonstate change.

However i have found a solution using a NPN to assist the dual relay, and what I can google, there seems to be som issues with these cheap relay modules, especially the dual

@groundFungus
The buttons where wired with ground goingto the one connectoer, and the other connector has the wire for input, and a 10k resistor to VCC (5V)
And I have used a USB connection as power supply, a Boost converter, and also a PSU from a computer, used as a standalone PSU, så it should not be a power issue. I have got it working now, but with a resistor

Again, thank you for your contribution for a solution

Time to learn arrays, its pretty straightforward.