12 Position switch using 1 pin?

Would it be feasible to take a 12 position rotary style switch, and solder a different value resistor to each pole, and then connect them all to 1 pin on the arduino? Each position of the switch would have a different value. I have read in the past that the arduino can read resistance, would this be a viable option for reducing pin usage?

(deleted)

Yeah.

It's pretty common - you see it in cheap crap electronics for control panels all the time. They put a pullup on the chip's one ADC line, and each button grounds the line through a different value resistor.

spycatcher2k:
Yes - Different value resistors for each pin, with a 2nd resistor to complete a voltage divider.

Thanks for your reply, do you know of a good guide for this sort of thing? I did a google search, but I'm not sure exactly what I'm looking at, as physical inputs into arduino is a new thing to me. I've done a lot with receiving data from vehicle simulators and sending that data to arduino via serial and handling it with shift lights and gear indicators, but inputs are generally new to me.

Thanks.

Maybe do it with the same value resistor.

rotary_as_pot.JPG

rotary_as_pot2.JPG

It's a simple application of ohm's law, on each switch setting, that switch's specific resistor and the shared pullup are acting as a "voltage divider".

I've seen a few guides go by on these forums over the past year, usually described like using one analog pin to read multiple buttons. For the most part though, it's the kind of thing you can derive from ohm's law pretty easily.

justone:
Maybe do it with the same value resistor.

That's a rather different topology, sometimes termed a resistor ladder. In that case they put one end on ground, the other end on supply, and measure the voltage of the wiper (basically, using it like a pot).

DrAzzy:
It's a simple application of ohm's law, on each switch setting, that switch's specific resistor and the shared pullup are acting as a "voltage divider".

I've seen a few guides go by on these forums over the past year, usually described like using one analog pin to read multiple buttons. For the most part though, it's the kind of thing you can derive from ohm's law pretty easily.

Would the best way to find out the value of each pin be to hook up a serial monitor and have it do something like:

value1 = analogRead();
Serial.write(value1);

After you get the measured values (As you note above) make sure you don't look for exactly those but a range for each so when things drift a little you still hit your marks.

-jim lee

jimLee:
After you get the measured values (As you note above) make sure you don't look for exactly those but a range for each so when things drift a little you still hit your marks.

-jim lee

Good call. I guess the only other question would be; how much difference should there be in resisters?

google worked for me,

http://svglobe.com/arduino/in_analog.html

With the resistor ladder approach you can use resistors of one lot, whose values typically differ not much - often by less than 1%. The voltage ranges are evenly spaced, and proportional to the supply voltage, so that the readings of one position should not differ by more than 2.

When different resistor values are used, their tolerance can result in uneven and very narrow voltage ranges. In most cases you'll have to measure all the ranges, and add according constants to your code. Much more complicated than the resistor ladder approach.

Also consider that the rotary switch will bounce, so that a number of sequentially measured values should be within the range of a specific position.