Reading many button inputs

Hello,

What's the easiest way to read a lot of button inputs? I need to read 12 buttons, output to an LED for each button, and have room for a serial output and hopefully an Xport.

Thanks!

look at the Cassius punching bag project-- they use 4067 multiplexer chips to read over a hundred inputs on a few pins. That takes care of multiple inputs. Don't forget to use the appropriate pull-up or pull-down resistors for the switches.

D

For 12 buttons, you can use a matrix configuration to read them off of 7 pins with no extra components.

Or you can use a different resistor on each button to read all 12 from a single analog input.

Didn't think of that one, thanks!

Or you can use a different resistor on each button to read all 12 from a single analog input.

You have got to use the right resistor values to make sure you can distinguish between one button and two others being simultaneously held down.

In order to do this you need to arrange the resistors in a R / 2R arrangement just like a D/A converter. Due to resolution and noise you will probably be able to read only 5 or 6 buttons per analogue input. But you will be able to tell if any combination of buttons is held down and what that combination is.

Say, I wonder if tri-state multiplexing would work on Arduino inputs? LEDkit.biz: Principle of Tristate Multiplexing

Isn't tristate multiplexing the same as charlieplexing ? Anyway, maybe some MAX6818 (Octal, CMOS Switch Debouncers) will help ya. http://www.maxim-ic.com/quick_view2.cfm/qv_pk/1896 This way, you can avoid to debounce the switch in the software. Got to check the datasheet a bit more, but I think you can add a 74HC165 behind that to have a 8 parralel-in > Serial-out chip and drive your buttons with few wires.

Isn't tristate multiplexing the same as charlieplexing ? Anyway, maybe some MAX6818 (Octal, CMOS Switch Debouncers) will help ya.

Yes, it is Charlieplexing, but both names are commonly used. And it will not help with inputs.

You have got to use the right resistor values to make sure you can distinguish between one button and two others being simultaneously held down.

That's pretty obvious ;)

I actually posted here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1207703351/1#1 a couple of months ago where I estimated 4-5 digital inputs per pin. If the situation only allows one button press at a time and can just ignore multiple pushes, a dozen buttons will be easy with careful selection of resistors.

Oracle, I think that the MAX6818 can be helpful, otherwise it wouldn't even exist ^^. In this case, "lots" mean 12 buttons, but when you work on higher scales, it can be useful to use it instead of the software debounce solution. Let's say you have 256 buttons, with a bouncing time of 10ms... If you want to have multiple inputs & almost no lag, the software debounce will be tricky. If you do it hardware, you can free the arduino from having to compute measure time between 2 states for each button. In addition, the MAX6818 have a pin that change state whenever a button press (or release) is detected. Really useful for avoiding listening to 8 input pins on each loop...

Or you could use two 4051 multiplexers (dirt chap) to control an 8 by 8 matrix of switches, if you don't need to be able to press multiple switches at the same time.

http://www.arduino.cc/playground/Learning/4051

If "a lot" is 12 then how about using a MCP23016 I2C expander. This gives 16 inputs at a cost of just 2 Arduino pins (clock & data). It also has an output that signals if any input has changed state. (one extra pin cost) That can be used to trigger an interrupt routine or be read in a poling loop to free the processor from having to constantly multiplex inputs. That way you only read the I2C bus when you need to.

Hum, nice chip, 16x8 buttons on the same I2C line... ^^

Oracle, I think that the MAX6818 can be helpful, otherwise it wouldn't even exist ^^.

Sorry, poor quoting on my part. I meant Charlieplexing will not help with reading many inputs.

But giving that more thought, it might actually help. What if I connected every IO through a week pull-up to Vcc, then put in a button between every possible pair of inputs? I could scan the buttons by setting them all as inputs, then one at a time set them as outputs, bring them low, and see if any of the inputs read low. I should be able to read n(n-1)/2 switches off n IO lines.

Yeah, I don't see why that wouldn't work, and you can even get by using the I/O lines' internal pull-ups, so all you need are the buttons.

  • Ben

Yeah, I don't see why that wouldn't work, and you can even get by using the I/O lines' internal pull-ups, so all you need are the buttons.

  • Ben

Has that been done before or did I just invent a new technique? :)

http://www.arduino.cc/en/Tutorial/TwoSwitchesOnePin