Go Down

Topic: How to read more Buttons than pins avaliable? (Read 2 times) previous topic - next topic

lukeskymuh

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?

 

IngHooch

I guess using two shift register like the 74hc595 and four buttons. But I'm a pretty NooB with electronics  :smiley-red:
The brightest flame burns quickest

AWOL

"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.

scottyjr

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

robtillaart

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 -

Rob Tillaart

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

radiogurus

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.

dc42

Wire your buttons in a 3x4 matrix, then use the keypad driver to read them. See http://www.arduino.cc/playground/Code/Keypad.
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.

Nick Gammon


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.
http://www.gammon.com.au/electronics

Grumpy_Mike

Quote
(no analog in or output is left).

Arduinos do not have analogue outputs.
Or even analog outputs.

Nick Gammon

http://www.gammon.com.au/electronics

lukeskymuh

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.


Nick Gammon

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.
http://www.gammon.com.au/electronics

Techone

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


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

Grumpy_Mike

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.

funkyguy4000

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.
Accelerate to 88 miles per hour.

Go Up