analog inputs from vibration sensor

here is my code

void loop() {
 

 
  buttonState1 = analogRead(A4) ; //Reading statuses of the pins
  buttonState2 = analogRead(A5) ;
  buttonState3 = analogRead(A6) ;
  buttonState4 = analogRead(A7) ;
  buttonState5 = analogRead(A8) ;
  buttonState6 = analogRead(A9) ;
  buttonState7 = analogRead(A10) ;
  buttonState8 = analogRead(A11) ;
  buttonState9 = analogRead(A12) ;
 

  
  
  
  
  if ( (millis() - lastDebounceTime) > debounceDelay) {
   

      if (buttonState1 > SEN) {
        digitalWrite(LEDB1, HIGH);
       
        ledon1 = true;

        Serial.print("Top Left ");
        Serial.println(buttonState1);
        lastDebounceTime = millis();
        

      }

      if (buttonState2 > SEN) {
        digitalWrite(LEDB2, HIGH);
       
        ledon2 = true;

        Serial.print("Top Middle ");
        Serial.println(buttonState2);
        lastDebounceTime = millis();
      }

      if (buttonState3 > SEN) {
        digitalWrite(LEDB3, HIGH);
       
        ledon3 = true;

         Serial.print("Top right ");
        Serial.println(buttonState3);
        lastDebounceTime = millis();
      }

      if (buttonState4 > SEN) {
        digitalWrite(LEDB4, HIGH);
       
        ledon4 = true;

        Serial.print("Middle Left ");
        Serial.println(buttonState4);
        lastDebounceTime = millis();
      }

      if (buttonState5 > SEN) {
        digitalWrite(LEDB5, HIGH);
       
        ledon5 = true;

        Serial.print("Middle ");
        Serial.println(buttonState5);
        lastDebounceTime = millis();
      }

      if (buttonState6 > SEN) {
        digitalWrite(LEDB6, HIGH);
       
        ledon6 = true;

        Serial.print("Middle right ");
        Serial.println(buttonState6);
        lastDebounceTime = millis();
      }

      if (buttonState7 > SEN) {
        digitalWrite(LEDB7, HIGH);
       
        ledon7 = true;

        Serial.print("Bottom Left ");
        Serial.println(buttonState7);
        lastDebounceTime = millis();
      }

      if (buttonState8 > SEN) {
        digitalWrite(LEDB8, HIGH);
       
        ledon8 = true;

        Serial.print("Bottom Middle ");
        Serial.println(buttonState8);
        lastDebounceTime = millis();
      }

      if (buttonState9 > SEN) {
        digitalWrite(LEDB9, HIGH);

        ledon9 = true;

        Serial.print("Bottom right ");
        Serial.println(buttonState9);
        lastDebounceTime = millis();
      }


    
   
  


  }    

  
}

i am building an electronic hockey net

my debounceDelay is set for 1000

what i am doing is i have 9 squares with 9 vibration sensors(set at 125 trigger) when the square(top left) gets hit that LED lights up (top left) but i am running into the problem sometimes where if i hit say in this case middle both middle and middle right square will light up at the exact same time as you can see from the serial monitor info below....i can not use delays because the object of the game is to light up the 9 squares the fastest .... any idea what could help

17:34:44.062 -> Middle 348
17:34:44.062 -> Middle right 393

What do You want to show for a hit that is exactly on the line between 2 squares?

think of 9 square inside a hockey net and each square has its led and vibration sensor

What ever vibration trigger first ...so if it’s in between square 1 and square 2 ...square 1 should light first because it first in my program ...but I want only 1 to light up not both

The stop checking the other inputs when You have found a hit.

That’s what the denounce delay is suppose to do but the inputs “come in at the same time” witch I find it hard to believe

Find another solution. Put the input readings in a function that returns the code for the first square being hit, when it finds a hit.

The problem again is both input are saying there high(passed threshold) AT THE SAMMEEEEE TIME it’s driving me nuts !!!

some might think this is very easy to fix and would love to hear from someone that could help me out

i am building an electronic hockey net

my debounceDelay is set for 1000

what i am doing is i have 9 squares with 9 vibration sensors(set at 125 trigger) when the square(top left) gets hit that LED lights up (top left) but i am running into the problem sometimes where if i hit say in this case middle both middle and middle right square will light up at the exact same time as you can see from the serial monitor info below....i can not use delays because the object of the game is to light up the 9 squares the fastest .... any idea what could help

17:34:44.062 -> Middle 348
17:34:44.062 -> Middle right 393

void loop() {
 

 
  buttonState1 = analogRead(A4) ; //Reading statuses of the pins
  buttonState2 = analogRead(A5) ;
  buttonState3 = analogRead(A6) ;
  buttonState4 = analogRead(A7) ;
  buttonState5 = analogRead(A8) ;
  buttonState6 = analogRead(A9) ;
  buttonState7 = analogRead(A10) ;
  buttonState8 = analogRead(A11) ;
  buttonState9 = analogRead(A12) ;
 

 
 
 
 
  if ( (millis() - lastDebounceTime) > debounceDelay) {
   

      if (buttonState1 > SEN) {
        digitalWrite(LEDB1, HIGH);
       
        ledon1 = true;

        Serial.print("Top Left ");
        Serial.println(buttonState1);
        lastDebounceTime = millis();
       

      }

      if (buttonState2 > SEN) {
        digitalWrite(LEDB2, HIGH);
       
        ledon2 = true;

        Serial.print("Top Middle ");
        Serial.println(buttonState2);
        lastDebounceTime = millis();
      }

      if (buttonState3 > SEN) {
        digitalWrite(LEDB3, HIGH);
       
        ledon3 = true;

         Serial.print("Top right ");
        Serial.println(buttonState3);
        lastDebounceTime = millis();
      }

      if (buttonState4 > SEN) {
        digitalWrite(LEDB4, HIGH);
       
        ledon4 = true;

        Serial.print("Middle Left ");
        Serial.println(buttonState4);
        lastDebounceTime = millis();
      }

      if (buttonState5 > SEN) {
        digitalWrite(LEDB5, HIGH);
       
        ledon5 = true;

        Serial.print("Middle ");
        Serial.println(buttonState5);
        lastDebounceTime = millis();
      }

      if (buttonState6 > SEN) {
        digitalWrite(LEDB6, HIGH);
       
        ledon6 = true;

        Serial.print("Middle right ");
        Serial.println(buttonState6);
        lastDebounceTime = millis();
      }

      if (buttonState7 > SEN) {
        digitalWrite(LEDB7, HIGH);
       
        ledon7 = true;

        Serial.print("Bottom Left ");
        Serial.println(buttonState7);
        lastDebounceTime = millis();
      }

      if (buttonState8 > SEN) {
        digitalWrite(LEDB8, HIGH);
       
        ledon8 = true;

        Serial.print("Bottom Middle ");
        Serial.println(buttonState8);
        lastDebounceTime = millis();
      }

      if (buttonState9 > SEN) {
        digitalWrite(LEDB9, HIGH);

        ledon9 = true;

        Serial.print("Bottom right ");
        Serial.println(buttonState9);
        lastDebounceTime = millis();
      }


   
   
 


  }   

 
}

Is this a copy from another topic or duplicate posting?

I'm not entirely sure what you are asking but I think you are trying to do the debounce independently on each pin? Regardless, you can shrink you code way down by using arrays...

const byte buttonPin[] = { A4, A5, A6, A7, A8, A9, A10, A11, A12 };
const byte buttonCount = sizeof(buttonPin) / sizeof(buttonPin[0]);
const byte ledPin[buttonCount] = { 2, 3, 4, 5, 6, 7, 8, 9, 10 };
bool ledon[buttonCount];

const char * pinLabel[buttonCount] = {
  "Top Left ", "Top Middle ", "Top right ",
  "Middle Left ", "Middle ", "Middle right ",
  "Bottom Left ", "Bottom ", "Bottom right ",
};

unsigned int buttonState[buttonCount];
unsigned long lastDebounceTime[buttonCount];
const unsigned long debounceDelay = 1000;
const unsigned int SEN = 125;

void loop() {
  for ( int i = 0; i < buttonCount; ++i) {
    buttonState[i] = analogRead(buttonPin[i]) ; //Reading statuses of the pins

    if ( (millis() - lastDebounceTime[i]) > debounceDelay) {
      if (buttonState[i] > SEN) {
        digitalWrite(ledPin[i], HIGH);
        ledon[i] = true;
        Serial.print(pinLabel[i]);
        Serial.println(buttonState[i]);
        lastDebounceTime[i] = millis();
      }
    }
  }
}

You can also eliminate the buttonState array and ledon array if you don't use it elsewhere in your code. They can just be a single variable inside the for() loop.

@devanlynk

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.