How to read more Buttons than pins avaliable?

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?

I guess using two shift register like the 74hc595 and four buttons. But I'm a pretty NooB with electronics :blush:

3 x 4 matrix?

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

additional pins via I2C e.g. - Centipede Shield V2 - Macetech Electronics Store -

cheapest is AWOL's suggestion: - Arduino Playground - HomePage -

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.

Wire your buttons in a 3x4 matrix, then use the keypad driver to read them. See Arduino Playground - HomePage.

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.

-->

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


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

Also the keypad idea should work.

(no analog in or output is left).

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

Don't forget analogWrite Mike.

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.

Shift register for output:

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

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

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

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.

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.

Grumpy_Mike:

Don't forget analogWrite Mike.

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

Little jest there. :slight_smile:

Wait AnalogWrite makes a digitalOut? hahah uhhhh what? WHY?
Thats so misleading! So the arduino is only capable of reading analog inputs but can't drive anything that is analog.
wow

funkyguy4000:
Wait AnalogWrite makes a digitalOut? hahah uhhhh what? WHY?
Thats so misleading! So the arduino is only capable of reading analog inputs but can't drive anything that is analog.
wow

AnalogWrite outputs PWM signal. You can convert PWM to real analog output by adding a low pass filter. As I have seen someone here suggesting, analogWrite should really be called pwmWrite.

Hm, I never knew that.
Learn something knew each day.

here is an epic song that is totally unrelated
www.youtube.com/watch?v=eQWG8BVeryU&ob=av2e

Hm, I never knew that. Learn something knew each day.

Useful resource regarding digital nature of analogWrite here