0
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$
7
  • \$\begingroup\$ So I would need an individual resistor to all contacts? Can they be connected to a common ground? Also, do they have to have different resistances? \$\endgroup\$ Commented Aug 26, 2014 at 0:51
  • \$\begingroup\$ So I would need an individual resistor to all contacts? YES Can they be connected to a common ground? YES Also, do they have to have different resistances? NO \$\endgroup\$
    – MatsK
    Commented Aug 26, 2014 at 1:15
  • \$\begingroup\$ Just a final comment before I resolder the contacts, can one of you explain why this solution works? I think I understand it, but I kinda want confirmation. By having a resistor on each contact pad, does it insure that each pad raises the resistance a certain amount? So the Digital In can read if the voltage changed by a certain amount and only read for that pin? \$\endgroup\$ Commented Aug 26, 2014 at 1:34
  • \$\begingroup\$ The resistors prevent there from being a common node between all switches, thereby preventing them from all becoming the same voltage at the same time. \$\endgroup\$ Commented Aug 26, 2014 at 2:20
  • \$\begingroup\$ @nadjatee1996, if you look closely at the drawing, Digital2 is directly short-circuited to Digital3, and their short-circuited connection is pulled down via your resistor. If Digital3 is "actuated", +5V is delivered to the short-circuit between Digital2 and Digital3. \$\endgroup\$ Commented Aug 26, 2014 at 4:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.