Identify the change in switch states using a single wire system

Say I have 10 switches which will be automatically tripped at any time. The switches are supplied with the constant voltage(Say 5v). So the conventional way for identifying the trip is by connecting each switch to the GPIO's of uC and monitoring their voltage levels.

I want to know is there is any other simple way to identify this problem. Below is the sample circuit diagram (only for understanding)

simulate this circuit – Schematic created using CircuitLab

• You need to supply more information. What is the system? What voltage at the inputs? AC or DC? What current? Are we detecting 1 of 10 switched or multiples? Can we add diodes in series with each switch? Are the switches normally open as shown in your "schematic"? Put all the information in your question and not in the comments. – Transistor Jun 15 '16 at 5:12
• In my answer I made the assumptions that your question meant to include the 1-wire statement seen in your title. If that's right, please add a little bit of information like that to your question (there's an edit button under your question). – Asmyldof Jun 15 '16 at 5:55
• Yes your assumption is correct @Asmyldof. this is the answer i was searching for. – Honeybee Jun 15 '16 at 5:59
• Glad I could help. – Asmyldof Jun 15 '16 at 6:01

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

EDIT:

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:

1. 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.
2. 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.
3. 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.
• I might be having the simple question .. but solve this for the equivalent circuit.. the circuit in my question – Honeybee Jun 15 '16 at 6:46
• in the circuit i have SW2 in ON state .. what is the equivalent resistance. – Honeybee Jun 15 '16 at 6:47
• This circuit will NOT work as shown, with SPST switches. When using an R-2R network as a voltage DAC, the digital inputs need to be driven with voltage sources, which means that you would have to use SPDT switches that connect each node to either Vcc or Gnd. See this question for additional information. – Dave Tweed Jun 15 '16 at 11:42
• @DaveTweed You are right. Will fix soon. My apologies to the all of the interwebs. – Asmyldof Jun 15 '16 at 14:09
• @Honeybee unfortunately I had to make a change to my post. For now the quickest is changing the switches, but I'm happy to think up a better solution later. – Asmyldof Jun 15 '16 at 19:41

The simplest solution would be to use binary-weighted resistors. For 10 switches, you need a 1024:1 range, so I would pick resistors in the range of 100Ω through 100kΩ.

If you want one end of each switch connected to ground, put a resistor in series with each switch, and then connect them all to your signal line. Feed the line with a voltage source and measure the current that flows.

Alternatively, you could connect all of the switches in series, in which case, you would put a resistor in parallel with each switch. Feed the circuit with a constant current and measure the voltage.

In either case, you'll get a measurement that uniquely identifies the combination of switches that are closed. Note that the measurement must be made with enough resolution to allow for variations that are due to component tolerances and other errors such as drift and noise. Note also that the precision of the resistors will need to be on the order of 0.1% for a 10-switch system.