While loop problem

My problem is only one button is working & the rest doesn't work. I 'm not good at English that's why I 'm giving some simulation picture to help you guys understand my problem. Thank you.

backup.txt (10.5 KB)

Programming section - post code, not video.

What is the state of a pin when the switch is not pressed? Without pullup or pulldown resistors, which you don't have, you can not be sure of the state of the pin.

There are internal pullup resistors that you could use.

PaulS:
What is the state of a pin when the switch is not pressed? Without pullup or pulldown resistors, which you don't have, you can not be sure of the state of the pin.

There are internal pullup resistors that you could use.

I did it now, but still doesn't work.

I did it now, but still doesn't work.

Ah well, the problem is on your end. Only you have any idea what you did.

What PaulS is saying, post your updated schematic and/or code.

I don't know how you got to 10k code without picking this up earlier. So I would suggest that you start with a simple sketch; something like

const int buttonPin8 = 8;      // the number of the pushbutton pin
const int buttonPin9 = 9;      // the number of the pushbutton pin
const int buttonPin10 = 10;    // the number of the pushbutton pin
const int buttonPin11 = 11;    // the number of the pushbutton pin

void setup()
{
  Serial.begin(57600);

  pinMode(buttonPin8, INPUT_PULLUP);
  pinMode(buttonPin9, INPUT_PULLUP);
  pinMode(buttonPin10, INPUT_PULLUP); 
  pinMode(buttonPin11, INPUT_PULLUP); 
}

void loop()
{
  Serial.println(getkey());
  // delay added for debounce
  delay(100);
  // delay added to slow down scrolling
  delay(1000);
}

int getkey()
{
  if( digitalRead(buttonPin8))
  {
    while( digitalRead(buttonPin8));
    return 1;  
  }
  else if(digitalRead(buttonPin9))
  {
    while( digitalRead(buttonPin9));
    return 2;
  }
  else if(digitalRead(buttonPin10))
  {
    while( digitalRead(buttonPin10));
    return 3;
  }
  else if(digitalRead(buttonPin11))
  {
    while( digitalRead(buttonPin11));
    return 4;
  }
  else
  {
    return 0;
  }  
}

And next take it from there.