Pages: [1] 2   Go Down
Author Topic: Help on momentary push switches in series.  (Read 1177 times)
0 Members and 1 Guest are viewing this topic.
Maryland, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
  I am building a 13 keys jeyboard, the keys being momentary push switches).

The keyboard is not going to be close to Arduino so I want to cut down on the amount of wires going back and fort from him (Arduino).

I came up with two possibilities (see picture)
The one above should work at rest (nothing pushed) but I fear that if you close any switch, all pins will go high. Am I correct?

The second one should work but I am using 13 resistors in parallel. Do I need to increase the resistance of each 13 times? That is using 13 120 K resistors (not sure if I have 130 K) ?

Also, Arduino need to be able to sense the pressing of any combination of buttons (up to 10 at a time, for a standard 10-fingered player).

Your comments will be greatly appreciated.

Thanks

Thot

P.S. Sorry for the quality, I am not Forrest Mims III  smiley and I don't know (yet) how to use CAD software.



* Multiple Push Buttons.jpg (270.1 KB, 1323x1748 - viewed 33 times.)
Logged

There are three kind of people in the world: Those who can count, and those who can't

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


The top circuit is incorrect, pushing any button will set all the input pins to HIGH. The second is correct, however I would use much lower resistor values from say 10k to 50k ohms. However the simplest method to wire up buttons is to turn on the internal pull-up resistors in your sketch software for each pin you are using and wire a ground to the other side of each of the switches. So in your sketch, reading a LOW means that button is being pressed and reading a HIGH means it's not being pressed. That way you need no external resistors and just one common ground wire to one side of all the buttons and of course one wire each between each button and it's arduino digital input pin. That should clean up your external wiring some.

PS: your switches are not being wired in series, they create four independent parallel paths for the four input pins. You just are taking advantage of the fact that those switches have additional terminals that are wired together to allow you to daisy chain either a +5vdc or a ground bus on one side for ease of wiring.

Lefty
« Last Edit: November 13, 2012, 01:46:19 pm by retrolefty » Logged

Maryland, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

However the simplest method to wire up buttons is to turn on the internal pull-up resistors in your sketch software for each pin you are using and wire a ground to the other side of each of the switches.

Thanks for the quick reply!

I came across this before but I am confused as how it works and how to turn on the internal pull up resistor
Can you give or point me to an example?

Thanks
Logged

There are three kind of people in the world: Those who can count, and those who can't

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

However the simplest method to wire up buttons is to turn on the internal pull-up resistors in your sketch software for each pin you are using and wire a ground to the other side of each of the switches.

Thanks for the quick reply!

I came across this before but I am confused as how it works and how to turn on the internal pull up resistor
Can you give or point me to an example?

Thanks


Sure. The latest arduino IDE has made it even simpler. In your setup function code just have a mode statement for each input pin you will be using as so:

pinMode(pin#, INPUT_PULLUP);

Lefty
Logged

Maryland, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!
Logged

There are three kind of people in the world: Those who can count, and those who can't

Offline Offline
Sr. Member
****
Karma: 3
Posts: 263
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here a simple way to add 13 buttons all resistors are 220 ohm you'll only need Ground  and a A0 pin
and there code that works with the idea in the Playground


* 13uttons.PNG (11.31 KB, 349x338 - viewed 28 times.)
Logged

Maryland, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That's an interesting idea!

The node on top is connected to +5, right?
Then the circuit acts as a voltage divider with each switch press bypassing a resistor and decreasing the total resistance.
But if the resistors have all the same value, can the program tell which button is pressed or only how many are pressed?
What's the value of the capacitor?

And, can you post the link to the playground article?

Thanks

Logged

There are three kind of people in the world: Those who can count, and those who can't

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should think of R2R type networks and imaging your buttons are pins outputing to that R2R network.

This can uniquely determine which buttons are pushed.
Logged

Offline Offline
Sr. Member
****
Karma: 3
Posts: 263
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here some code to test 13 button wired up as I posted 

Code:
const int keyMin = 0;      // Keymin, discovered through experiment
const int keyMax = 1023;    // keymax, discovered through experiment
void setup() {
  Serial.begin(9600);
}
void loop() {
  // read the sensor:
  int key = analogRead(A0);
  // map the sensor range to a range of four options:
  int keyValue = map(key, keyMin, keyMax, 0, 3);

  // do something different depending on the
  // range value:
  switch (keyValue) {
  case 0:    // your hand is on the sensor
    Serial.println("button1");
    break;
  case 1:    // your hand is close to the sensor
    Serial.println("button2");
    break;
  case 2:    // your hand is a few inches from the sensor
    Serial.println("button3");
    break;
  case 3:    // your hand is nowhere near the sensor
    Serial.println("button4t");
    break;
    case 4:    // your hand is nowhere near the sensor
    Serial.println("button5");
    break;
case 5:    // your hand is nowhere near the sensor
    Serial.println("button6");
    break;
case 6:    // your hand is nowhere near the sensor
    Serial.println("button7");
    break;
case 7:    // your hand is nowhere near the sensor
    Serial.println("button8");
    break;
case 8:    // your hand is nowhere near the sensor
    Serial.println("button9");
    break;
case 9:    // your hand is nowhere near the sensor
    Serial.println("button10");
    break;
case 10:    // your hand is nowhere near the sensor
    Serial.println("button11");
    break;
case 11:    // your hand is nowhere near the sensor
    Serial.println("button12");
    break;
case 12:    // your hand is nowhere near the sensor
    Serial.println("button13");
    break;

  }
  delay(1);        // delay in between reads for stability
}


Logged

0
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12717
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You should think of R2R type networks and imaging your buttons are pins outputing to that R2R network.

This can uniquely determine which buttons are pushed.


Doesn't work - R-2R networks only work with SPDT switches, not SPST push buttons.
Logged

[ I won't respond to messages, use the forum please ]

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here a simple way to add 13 buttons all resistors are 220 ohm you'll only need Ground  and a A0 pin
and there code that works with the idea in the Playground

That circuit can tell if one switch is presses and tell which one is being presses. However it can not cope with multiple switches being presses which is what the OP wanted.
Logged

Maryland, USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 79
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That's what I thought.
And I came to the conclusion that with a resolution of 1024 on the ADC in theory you could wire up the circuit to implement a binary progression for 12 buttons  (No button =0, button 1=1 button 2=2, button 3=4, button 4=8 etc.), in practice, that is unfeasible as the difference between button presses will be only 1 value, or 0.00488 V (e.g. buttons 1,2,3 pressed = 7 [0.034 V] ; button 4 only = 8 [0.039 V]) which even with very tight tolerance resistors will be sensitive to tiny supply voltage fluctuations.

If someone can prove my logic wrong and give me an example of such a circuit I will be very happy.

Incidentally, I read a long time ago that the very first digital computers designs were based on the decimal system (the most intuitive to us humans) but they never got to work in practice because of the unreliability of detecting those differences in voltage. The binary system was eventually used because it's much easier to detect No-voltage/voltage.

I feel like I re-discovered the wheel.
 
Logged

There are three kind of people in the world: Those who can count, and those who can't

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3091
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you do not have the 13 Arduino pins available, PISO shift registers were invented for your problem. Forget about the analog trick in your case.
µC is about serializing the physical world to handle it in a sequential processor smiley-wink
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
R-2R networks only work with SPDT switches, not SPST push buttons.

Are you sure about that? smiley

With a r2r type button, you can read multiple buttons from one pin, and you can detect simultaneous presses as well.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why did you start a whole new thread on this keyboard?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1] 2   Go Up
Jump to: