Using 4+ Momentary push buttons w/ relays

While I assume this may be, but a simple oversight in my attempt at coding this(I'll plead ignorance here); I've scoured through this forum & on the web and have found little guidance as to a solution -- for the shear fact I don't entirely know what I'm looking for. Attached is a video that might better illustrate my problem.

At first I imagined it might be some form of a hardware issue on my part. However, the first of my four buttons works just fine, it sets the relay pin to HIGH when pressed and LOW when released.(I currently have the NC/NO contacts reversed so it isn't constantly buzzing) When the other buttons are pressed, the relays switch between HIGH/LOW very quickly - each other button does this at its own rate. It sounds like a broken keyboard.

After a bit of digging, the term 'debouncing' kept coming up to these sort of button related issues. Now.. I've read over explantations of this a hand full of times and can mostly grasp what is happening with the physical button, but all of the 'debouncing' code solutions I've found fail to include an explanation I can understand on how to implement it, in this type of project.

I apologize if this is yet another post to something that has already been covered, but I'm not certain what the issue even is at this point.

const int buttonPin_1 = 1;     // the number of the pushbutton pin
const int buttonPin_2 = 4;
const int buttonPin_3 = 7;
const int buttonPin_4 = 10;

const int Light_1 =  2;    // Relay 2 pin
const int Light_2 = 5;     // Relay 4 pin
const int Light_3 = 8;     // Relay 5 pin
const int Light_4 = 11;     // Relay 7 pin


// variables will change:
boolean buttonState = LOW;         // variable for reading the pushbutton status
boolean buttonState2 = LOW;        //variable for reading the second buttons state
boolean buttonState3 = LOW;
boolean buttonState4 = LOW;


void setup() {
  // initialize the LED pin as an output:
  pinMode(Light_1, OUTPUT);
  pinMode(Light_2, OUTPUT);
  pinMode(Light_3, OUTPUT);
  pinMode(Light_4, OUTPUT);
  
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin_1, INPUT);
  pinMode(buttonPin_2, INPUT);
  pinMode(buttonPin_3, INPUT);
  pinMode(buttonPin_4, INPUT);
}

void loop() {
  
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin_1);
  buttonState2 = digitalRead(buttonPin_2);
  buttonState3 = digitalRead(buttonPin_3);
  buttonState4 = digitalRead(buttonPin_4);

  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  // Light 1
  
  if (buttonState == HIGH) {
    // turn relay on:
    digitalWrite(Light_1, HIGH);
  }
  else {
    // turn relay off:
    digitalWrite(Light_1, LOW);
  }


  
  // Light 2
    if (buttonState2 == HIGH) {
    // turn relay 2 on:
    digitalWrite(Light_2, HIGH);
  }
  else {
    // turn relay off:
    digitalWrite(Light_2, LOW);


   // Light 3
     if (buttonState3 == HIGH) {
    // turn relay 3 on:
    digitalWrite(Light_3, HIGH);
  }
  else {
    // turn turn off:
    digitalWrite(Light_3, LOW);
  }


  // Light 4
    if (buttonState4 == HIGH) {
    // turn relay 4 on:
    digitalWrite(Light_4, HIGH);
  }
  else {
    // turn relay off:
    digitalWrite(Light_4, LOW);
  }
}
}

Demonstration*

You don't mention your wiring - what are the buttons connected to make them go high & low?
Generally you use the internal pullups and wire the buttons to connect to Gnd when pressed:

These can all be byte, not int
const int buttonPin_1 = 1; // the number of the pushbutton pin

Enable internal pullup:
pinMode(buttonPin_1, INPUT_PULLUP);

Test for low/button pressed:
if (buttonState == LOW) {

Finally, what are you using for relays? Most 5V relays need more coil current than an Arduino pin can supply.
Do you have a diode across the relay coils as well to dissipate coil generated current when the Arduino current stops flowing?

Also, you forgot a closing bracket at the end of the Light2 'else' section:-

// Light 2
    if (buttonState2 == HIGH) {
    // turn relay 2 on:
    digitalWrite(Light_2, HIGH);
  }
  else {
    // turn relay off:
    digitalWrite(Light_2, LOW);


   // Light 3

I've made the changes to my sketch so that it now reads -- *as seen below, however
I am still running into the same problem. I am not currently using a diode between the relays(basic 8x module 10A max 'Songle') and the board.

Attached are a few images and a crude schematic. Thank you for the help.

const byte buttonPin_1 = 1;     // the number of the pushbutton pin
const byte buttonPin_2 = 4;
const byte buttonPin_3 = 7;
const byte buttonPin_4 = 10;

const int Light_1 =  2;    // Relay 2 pin
const int Light_2 = 5;     // Relay 4 pin
const int Light_3 = 8;     // Relay 5 pin
const int Light_4 = 11;     // Relay 7 pin


// variables will change:
int buttonState = LOW;         // variable for reading the pushbutton status
int buttonState2 = LOW;        //variable for reading the second button state
int buttonState3 = LOW;
int buttonState4 = LOW;


void setup() {
  // initialize the LED pin as an output:
  pinMode(Light_1, OUTPUT);
  pinMode(Light_2, OUTPUT);
  pinMode(Light_3, OUTPUT);
  pinMode(Light_4, OUTPUT);
  
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin_1, INPUT_PULLUP);
  pinMode(buttonPin_2, INPUT_PULLUP);
  pinMode(buttonPin_3, INPUT_PULLUP);
  pinMode(buttonPin_4, INPUT_PULLUP);
}

void loop() {
  
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin_1);
  buttonState2 = digitalRead(buttonPin_2);
  buttonState3 = digitalRead(buttonPin_3);
  buttonState4 = digitalRead(buttonPin_4);

  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  // Light 1
  
  if (buttonState == LOW) {
    // turn LED on:
    digitalWrite(Light_1, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(Light_1, LOW);
  }


  
  // Light 2
    if (buttonState2 == LOW) {
    // turn LED on:
    digitalWrite(Light_2, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(Light_2, LOW);
  }

   // Light 3
     if (buttonState3 == LOW) {
    // turn LED on:
    digitalWrite(Light_3, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(Light_3, LOW);
  }


  // Light 4
    if (buttonState4 == LOW) {
    // turn LED on:
    digitalWrite(Light_4, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(Light_4, LOW);
  }
}

More images

That code looks like it should work.

What voltage is that little regulator that feeds the Vin pin of your Arduino?
And it's hard to see - is it a switching regulator, or a linear type?

One side of your switch is connected to ground. The other side is connected to a digital pin. This would work great IF you enabled the internal pullup resistor. Since you didn't, digitalRead() flips a coin to see if your switch is pressed.

(Not really, but you have a floating pin, which confuses the hell out of digitalRead()).

Turn the pullup resistors on by using INPUT_PULLUP as the mode.

PaulS:
One side of your switch is connected to ground. The other side is connected to a digital pin. This would work great IF you enabled the internal pullup resistor. Since you didn't, digitalRead() flips a coin to see if your switch is pressed.

(Not really, but you have a floating pin, which confuses the hell out of digitalRead()).

Turn the pullup resistors on by using INPUT_PULLUP as the mode.

In the second version of his sketch, (reply #3), after CrossRoads' suggestion, he'd fixed that problem:-

// initialize the pushbutton pin as an input:
  pinMode(buttonPin_1, INPUT_PULLUP);
  pinMode(buttonPin_2, INPUT_PULLUP);
  pinMode(buttonPin_3, INPUT_PULLUP);
  pinMode(buttonPin_4, INPUT_PULLUP);

Everything else in the code looks OK, so I was wondering if he was supplying the Vin pin with 5V.

I'm using an L7809 regulator which is supplying the Arudino with a constant 9.06V The Relay board(Also realized that this module has internal diodes) is supplied via the 5V output of the Arduino

Regulator
http://www.amazon.com/gp/product/B00X7C64OE?psc=1&redirect=true&ref_=oh_aui_detailpage_o00_s03

I've found a debouncing solution that I imagine might work, but I'm still struggling on implementing this into my own code. I previously had assigned 4 different button states for the 4 buttons. dlloyd's code setup up the bytes & variables a bit different than mine, however my confusion is in the loop functions and callling upon the buttonstate(s).

Any idea how I might work this debouncing solution into my code? I've been struggling with this part of it for a while. All help is greatly appreciated.

referencing a previous post
(Debounce multiple push buttons, switches, relays or digital signals - Programming Questions - Arduino Forum)

Posters code reads

// constants
const byte buttons[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // inputs
const byte qty = sizeof(buttons);
const byte led = 13;

// variables
byte buttonState[qty];
byte buttonRead[qty];
unsigned long microsStart;

void setup() {
 pinMode(led, OUTPUT);
 for (int i = 0; i < qty; i++)
 {
   pinMode(buttons[i], INPUT_PULLUP);
   buttonState[i] = 0xFF;
   buttonRead[i] = 1;
 }
}

void loop() {
 buttonFilter();
 // your code starts here
 digitalWrite(led, buttonRead[0]); // debounced and filtered status of pin 2
}

void buttonFilter(void)
{
 if (micros() - microsStart >= 2000) // minimum interval between bounces = 2 ms
 {
   for (int i = 0; i < qty; i++)
   {
     buttonState[i] = (buttonState[i] << 1) | digitalRead(buttons[i]); // shift and read
     if ((buttonState[i] & B11111) == B01111) // if rising and high for 3 stable reads
     {
       buttonRead[i] = 1;
     }
     if ((buttonState[i] & B11111) == B10000) // if falling and low for 3 stable reads
     {
       buttonRead[i] = 0;
     }
   }
 }
 microsStart = micros();
}

my clueless attempt is as follows.

//constants
const byte buttons[4] = {1, 4, 7, 10}; //inputs
const byte qty = sizeof(buttons);
const byte led = 13; 

const int Light_1 =  2;    // Relay 2 pin
const int Light_2 = 5;     // Relay 4 pin
const int Light_3 = 8;     // Relay 5 pin
const int Light_4 = 11;     // Relay 7 pin


// variables will change:
byte buttonState[qty];
byte buttonRead[qty];
unsigned long microsStart;


void setup() {

   pinMode(led, OUTPUT);
 for (int i = 0; i < qty; i++)
 {
   pinMode(buttons[i], INPUT_PULLUP);
   buttonState[i] = 0xFF;
   buttonRead[i] = 1;
 }


  // initialize the LED pin as an output:
  pinMode(Light_1, OUTPUT);
  pinMode(Light_2, OUTPUT);
  pinMode(Light_3, OUTPUT);
  pinMode(Light_4, OUTPUT);
  

}
void loop() {
  buttonFilter();
  digitalWrite(led, buttonRead[0]);//debounced and filtered status of pin 2



  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  // Light 1
  
  if (buttonState == HIGH) {
    // turn relay on:
    digitalWrite(Light_1, HIGH);
  }
  else {
    // turn relay off:
    digitalWrite(Light_1, LOW);
  }


  
  // Light 2
    if (buttonState[qty] == HIGH) {
    // turn relay 2 on:
    digitalWrite(Light_2, HIGH);
  }
  else {
    // turn relay off:
    digitalWrite(Light_2, LOW);
  }

   // Light 3
     if (buttonState[qty] == HIGH) {
    // turn relay 3 on:
    digitalWrite(Light_3, HIGH);
  }
  else {
    // turn turn off:
    digitalWrite(Light_3, LOW);
  }


  // Light 4
    if (buttonState[qty] == HIGH) {
    // turn relay 4 on:
    digitalWrite(Light_4, HIGH);
  }
  else {
    // turn relay off:
    digitalWrite(Light_4, LOW);
  }
}

void buttonFilter(void)

{
 if (micros() - microsStart >= 2000) // minimum interval between bounces = 2 ms
 {
   for (int i = 0; i < qty; i++)
   {
     buttonState[i] = (buttonState[i] << 1) | digitalRead(buttons[i]); // shift and read
     if ((buttonState[i] & B11111) == B01111) // if rising and high for 3 stable reads
     {
       buttonRead[i] = 1;
     }
     if ((buttonState[i] & B11111) == B10000) // if falling and low for 3 stable reads
     {
       buttonRead[i] = 0;
     }
   }
 }
 microsStart = micros();
}
const byte buttons[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // inputs

Those are not buttons. They are pin numbers where switches might be attached (though why you have 10 values when you talk about 4 momentary (contact) push button (switches) is a mystery).

Using names that make sense will make programming so much easier.

const int Light_1 =  2;    // Relay 2 pin
const int Light_2 = 5;     // Relay 4 pin
const int Light_3 = 8;     // Relay 5 pin
const int Light_4 = 11;     // Relay 7 pin

Are these pin numbers? Are there relays or lights connected to the pins?

Why do you have an array for the switches but not an array for the lights/relays/whatever-the-hell-is-attached? See the comment above about meaningful names.

byte buttonState[qty];
byte buttonRead[qty];

Are those current states? Previous states? See the comment above about meaningful names.

  if (buttonState == HIGH) {

What does it mean to say "if the array is HIGH"?

    if (buttonState[qty] == HIGH) {

The valid index values range from 0 to 3 when qty is 4. Checking the memory location after the end of the array doesn't make sense.

Doing that by copying and pasting code, instead of using a for loop, doesn't make sense.