Maryland, USA
Offline
Jr. Member
Karma: 0
Posts: 79
|
 |
« on: November 13, 2012, 01:27:26 pm » |
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  and I don't know (yet) how to use CAD software.
|
|
|
|
|
Logged
|
There are three kind of people in the world: Those who can count, and those who can't
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15320
Measurement changes behavior
|
 |
« Reply #1 on: November 13, 2012, 01:38:56 pm » |
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
Jr. Member
Karma: 0
Posts: 79
|
 |
« Reply #2 on: November 13, 2012, 02:11:20 pm » |
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
Brattain Member
Karma: 279
Posts: 15320
Measurement changes behavior
|
 |
« Reply #3 on: November 13, 2012, 02:38:30 pm » |
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
Jr. Member
Karma: 0
Posts: 79
|
 |
« Reply #4 on: November 13, 2012, 02:48:53 pm » |
Thanks!
|
|
|
|
|
Logged
|
There are three kind of people in the world: Those who can count, and those who can't
|
|
|
|
Offline
Full Member
Karma: 3
Posts: 230
|
 |
« Reply #5 on: November 13, 2012, 02:55:01 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Maryland, USA
Offline
Jr. Member
Karma: 0
Posts: 79
|
 |
« Reply #6 on: November 13, 2012, 03:32:20 pm » |
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
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #7 on: November 13, 2012, 03:46:09 pm » |
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
Full Member
Karma: 3
Posts: 230
|
 |
« Reply #8 on: November 13, 2012, 06:25:35 pm » |
Here some code to test 13 button wired up as I posted 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
Tesla Member
Karma: 73
Posts: 6631
Arduino rocks
|
 |
« Reply #9 on: November 13, 2012, 08:46:39 pm » |
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
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25566
Solder is electric glue
|
 |
« Reply #10 on: November 14, 2012, 03:35:57 am » |
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
Jr. Member
Karma: 0
Posts: 79
|
 |
« Reply #11 on: November 14, 2012, 07:46:01 am » |
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
Edison Member
Karma: 27
Posts: 1502
|
 |
« Reply #12 on: November 14, 2012, 08:19:05 am » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #13 on: November 14, 2012, 09:00:09 am » |
R-2R networks only work with SPDT switches, not SPST push buttons. Are you sure about that?  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
Brattain Member
Karma: 249
Posts: 16571
Available for Design & Build services
|
 |
« Reply #14 on: November 14, 2012, 09:12:33 am » |
Why did you start a whole new thread on this keyboard?
|
|
|
|
|
Logged
|
|
|
|
|
|