Pages: [1] 2   Go Down
Author Topic: How to read more Buttons than pins avaliable?  (Read 1803 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

pobably the solution is already posted in the forum but I couldn't find it.

I have 10 buttons but only 7 digital Pins (no analog in or output is left). They will not be pressed at the same time.

It should be possible to code these buttons onto 4 pins (16 possible combinations) or even in serial.
I thought about using diods to code them. But maybe there is a nicer solution. What would you use? Maybe a shift register or some kind of IC?

Do you have an recomendation or example?

 
Logged

Firenze, Italy
Offline Offline
Full Member
***
Karma: 0
Posts: 104
Dislessia portami via
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess using two shift register like the 74hc595 and four buttons. But I'm a pretty NooB with electronics  smiley-red
Logged

The brightest flame burns quickest

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26250
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

3 x 4 matrix?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pottstown, PA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A very simple solution is to use a voltage divider. Switches (buttons) are connected to points on the divider and the voltage on the output of the switch is read using analogRead. That value is mapped to a value of the number of switches you have then switch case is used for control.

A helpful previous post:http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1226896251

- Scotty
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13676
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

additional pins via I2C e.g. - http://macetech.com/store/index.php?main_page=product_info&cPath=4&products_id=23 -

cheapest is AWOL's suggestion: - http://arduino.cc/playground/Main/KeypadTutorial -

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, a matrix would be easy and it will work. Just create a simple truth table for your pins and have the Arduino read the pins as inputs( of course).
If the input pins equal X then it must be button X that was pressed.
BCD basically. I'm doing it with a dip switch right now on a project I built. It reads the dip switch and determines a fixed time for a timing cycle.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6614
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Wire your buttons in a 3x4 matrix, then use the keypad driver to read them. See http://www.arduino.cc/playground/Code/Keypad.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 481
Posts: 18742
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A very simple solution is to use a voltage divider. Switches (buttons) are connected to points on the divider and the voltage on the output of the switch is read using analogRead.

 -->

... (no analog in or output is left).



Similar to the suggestion about the shift register you can use a port expander for around $5:

http://www.gammon.com.au/forum/?id=10945

Also the keypad idea should work.
Logged


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

Quote
(no analog in or output is left).
Arduinos do not have analogue outputs.
Or even analog outputs.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 481
Posts: 18742
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't forget analogWrite Mike.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 25
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow thank you guys!
Does anyone have a example how to use a shift register?
This matrix thing sounds greate. I think this is what I'm gona use.

@Nick: Ok. I mean an PWM output. Sry for my bad wording.

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 481
Posts: 18742
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Shift register for output:

http://www.gammon.com.au/forum/?id=11518

I don't have an input example but I'm sure a search will show one up.
Logged


Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does anyone have a example how to use a shift register?

Yes. Here : http://www.arduino.cc/en/Tutorial/ShiftIn
Logged

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

Quote
Don't forget analogWrite Mike.
I have not, it dosn't change the fact that analogWrite produces a digital output not an analogue one.


OP - if you use the shift out tutorial then don't fit the capacitor on the latch pin. That is an error, but no one will change it.
Logged

Wisconsin
Offline Offline
Edison Member
*
Karma: 4
Posts: 1001
I LOVE THIS STUFF!!!!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just use a demultiplexer!

the way they work is you hook up the switches to the demultiplexer and then you hook that up to the arduino (or whatever is controlling it) and then when you press a button, the demux spits out what pin that the signal is coming from.  And then just use software to chose the proper path for the switch using if statements.
Logged

Accelerate to 88 miles per hour.

Pages: [1] 2   Go Up
Jump to: