There is a trick, called resistor ladders.
If you have a single wire going out to an Analog to Digital Converter with enough resolution and low enough noise and distortion, you can detect all switches separately, but simultaneously with a single wire.
Let's say, for example, you have 5 switches (because I'm lazy, and for more you only need to continue the pattern). You then need to make it so that the switches all add a different binary based voltage to the output wire, like so (Vcc is your supply):
- Switch 1: Vcc/2
- Switch 2: Vcc/4 (half Switch 1)
- Switch 3: Vcc/8 (half Switch 2)
- Switch 4: Vcc/16 (half Switch 3)
- Switch 5: Vcc/32 (half Switch 4)
Then if Switch 1 and 3 are on you get Vcc/2 + Vcc/8 = 5*Vcc/8 (= 20*Vcc/32). If Switch 1 and 5 are on you get Vcc/2 + Vcc/32 = 17*Vcc/32.
That you can achieve by implementing an R/2R network, they're very famous and pretty easy to make. Here's a Colin's Lab youtube movie about it as well (5 minutes).
With 5 switches it would look like this:
simulate this circuit – Schematic created using CircuitLab
Due to lack of time to really focus this morning, I failed to consider that an R-2R needs to be driven high and low on it's ladder legs.
So you will notice that I had to change to dual-throw switches for my initial idea of using an R-2R.
So sorry for that.
END OF EDIT
The Op-Amp is there to buffer the voltage into the ADC, because some ADCs present a low enough effective input resistance to influence the resistor network. The capacitor is to decrease switch noise.
As my time is limited, I'll leave finding out how an R-2R DAC works to your own research, since they are very, very well documented on the internet.
In stead, I will warn you that:
- You need an ADC that's more accurate than the lowest voltage change you make. I would estimate you need an ADC with at least 2 more bits of resolution than your number of switches. This also depends on some other qualities of the ADC, if it has high non-linearity or a lot of input noise, you'll need more extra bits to be sure about the switches that are on. For example if you have 8 switches, you could get a 10bit ADC.
- The resistors need to be high enough value that you don't notice the switch resistance, so 100 Ohm and 50 Ohm would be too low, since switches can over time become between 0.5 Ohm and 2 Ohm and that will influence even our 5 switch example system with such low resistances.
- The Op-Amp needs to be Rail-to-Rail input/output, or powered by a higher positive voltage and a negative voltage if it can't, or it will distort your signal heavily, causing you to not be able to see the differences any more.