Electronic – 6 Buttons, 2 Wires, 1 Microcontroller

buttonmicrocontrollermultiplexer

First off I should probably mention that I'm a beginner when it comes to electronics.

I am planning on adding some buttons to a controller but have limited space for wires. Only 2 of the wires I have will fit (3 with a little modification perhaps). I would like at least 6 buttons (2 groups of 3) to connect to the microcontroller using only these wires. There are plenty of digital and analogue pins available.

What are my best options? I've read about multiplexing and using an analog pin with resistors on the buttons to give each its own voltage but they both only allow one button to be pressed at a time. Ideally I want to be able to push at least two buttons at the same time (one from each group).

Best Answer

The standard technique used in old CD player wired remote controls and such uses a series string of resistors. The resistors are chosen to give approximately equal voltage drop change for each unique button press.

schematic

simulate this circuit – Schematic created using CircuitLab

Note that this connection scheme does not allow any illegal values to be fed to the A/D converter. If more than one button is pressed, the top button has priority and the remaining buttons are ignored.

Note that the resistor values shown are NOT optimal. Calculating those resistor values is left as an exercise for the student .

[Edit]

Original poster wants two independent sets of 3- buttons each. That is also fairly easy but the downside is that this now takes TWO lines from the microcontroller instead of only one line plus ground.

schematic

simulate this circuit

In use, set one of the I/O pins HI, then read the voltage on the other pin. Then reverse the two pins: set the other pin HI, read the voltage on the first pin.

You need to take the diode voltage drop into account when calculating the resistor values to achieve the desired voltages. The upside of this is that you are looking for only 3 (4) discrete voltage levels - that makes your threshold voltages have a LOT of leeway and still give you accurate button press detection.

Again - resistor values are NOT optimum. Ask for help if you need assistance in calculating them.