# 24 position rotary switch to one Arduino input question

Would this work correctly: the wiper is connected to Arduino's analog pin, each of the contact has 1k resistor from one to next one with the first and last contact connected to GND and VCC. When the switch is all the way to one side, the input would be at 0v (analog value 0) for position 1 to 5v (analog value 1023) for position 24, and each step should be about 0.24v and roughly 48 in analog read. The entire resistor chain from GND to 5v would be 23k and shouldn't cause 5v to drop

Sound about right or is there a limit to Arduino and multiple contacts to one input? Also I remember coming across about using capacitor to improve read response, any info on this?

Should work.

Can add a 1uF from wiper to GND.

Similar to this, 100R not needed:

Remember 5v will vary some.

wilykat: Also I remember coming across about using capacitor to improve read response, any info on this?

The capacitor will keep the voltage on the analogue pin the same during the time the contact is between two positions. I guess 100n is more than enough. Leo..

Ok ty! So it should be fine with 24 position switch.

wilykat: Ok ty! So it should be fine with 24 position switch.

Use 1% metalfilm resistors, and measure/select them (remove outliers) before you solder them onto the switch. Just in case.. Leo..

Your switch is just a potentiometer with discrete values and switching transients, you can treat like any other pot, but wait till two consecutive readings are close in value to de-bounce.

Variation of the 5v should not be a problem if you supply the voltage from the Arduino board, since the analog reference is the same source.

In my experience, if the resistors come from the same lot, even low tolerance resistors are fairly consistent in value, unless you are using ancient carbon composition (does anyone still make those?).

The only limit on number of switch contacts would be the ability to reliably discern the difference in voltage between contacts.

Check your math, I get a slightly lower voltage per step. Need to think about it a while, but with integer math I think you could add 1/2 of a step to the analog reading then divide by the step value to get the contact number, instead of comparing values.

What about using map? Mapping the whole 1023 range to just 24 steps? That'd skip the need to compare the value and the software debounce check would probably be easier.