Electronic – arduino – More than one button in the same pin

analogarduino

I'm doing some project and I'm using Arduino to prototype, I have to use 10 pushbuttons (along with more things) and I don't have enough pins.

One solution I could think of is to use the analog pins and use each of them for two push buttons, something like this:

schematic

simulate this circuit – Schematic created using CircuitLab

That way I can read the pin A0 and know which of them is being pushed by looking if the voltage is 5V or half of that.

Is this a good idea? The different push buttons are NEVER supposed to be pushed at the same time, which is the only problem I can think off.

Are there better ways?

Best Answer

Why waste multiple analog pins for two switches each, when you could do any number of buttons on a single analog pin?

Two ways of doing it. One is in series, the other is parallel.

enter image description here

enter image description here

This is how some car steering wheel audio controls are. And how some of the older ipod inline controllers work.

Depending on the resistors you use, if you need multiple buttons pressed at the same time, and how sensitive your analog in is, you could have all 10 buttons on a single pin.