I recently bought a heap of these switches – small DPDT toggle buttons – for $0.07 ea.
These switches are not that large, the on vs off height difference is only about a millimetre, and I hate to think what the ‘rated cycles’ or debounce graph looks like.Regardless of their shortcomings, the prospect of having some silly project use literally THOUSANDS of switches on the cheap is enticing.
…but how to read them all?
The Problem
First of all, forget ‘one I/O per switch’, it will not scale well.
The most common method to wire up many switches is in a matrix.
Each row uses an I/O, each column uses an I/O, and pressing the switch connects that row and column together.
16 switches need 8 I/O, 64 switches need 16 I/O, it scales well. (and with a demux on one side, even fewer are needed)
However, switches are only simple electrical devices. When a switch is closed current can freely flow in either direction. If only one or two are closed, the patterns are unique. As soon as three or more switches are closed, a simple matrix can no longer read the switches with certainty. For example, there is no way to distinguish between these five switch states:
The matrix option will not be able to read all the switches.
The Not-So-Great Solution
This is a common problem faced by designers. What is the common solution?
A diode can be placed next to each switch to allow current only in one direction.
“What’s wrong with that?” Well, every switch needs a diode.
So now there are twice as many parts on the board, and you’ve got to find space for them, pay for them, solder them in…not great at all.
Other Solutions?
What other options are there?