Self-made Arduino pushbutton bank not working

arduinobuttonc

So I'm trying to make a 5 key keypad like circuit, but with increased tactile feel, so I forwent actual store bought pushbuttons. I rigged up keys with some aluminum foil and pieces of plastic and connected that to 5V. All of the buttons share this 5V. Then, I made some contact pads of aluminum foil that has one lead sandwiched between two layers. This lead had two wires, one that connected to one of the digital I/O's and one that connected to a resistor that then connected to ground. All of the contacts share the resistor( and therefore ground). So when the plastic piece connected with the sandwiched piece, it becomes a button. This works, I've tried it. What I can't fix is that if I only connect the pin for Digital 2, then push down any button, not just the one connected to pin 2, it registers a push.

enter image description here

Here is the code I use to check for presses :

int ledPin = 13; 
int val = 0;     

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);  
  for(int x = 2;x<6;x++){
  pinMode(x, INPUT);  
  }

}

void loop(){
  /*for(int x = 2;x<6;x++){
  val = digitalRead(x); 
  if (val == HIGH) {        
    digitalWrite(ledPin, LOW);  
    Serial.println(x);
  } else {
    digitalWrite(ledPin, HIGH);  
  }
  }*/
  if(digitalRead(2) == HIGH){
    Serial.println("2");
    digitalWrite(ledPin, LOW);  
  } else {
    digitalWrite(ledPin, HIGH);  
  }

}

The commented part was intended to check for all 5 connections, while the uncommented part only checks for pin 2.

Best Answer

You need to have a resistor per button. If you don't then any keypress will raise the common node to +5V and they will all register the keypress.