Go Down

Topic: 24 position rotary switch to one Arduino input question (Read 220 times) previous topic - next topic

wilykat

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?

larryd

Should work.

Can add a 1uF from wiper to GND.



Similar to this, 100R not needed:



Remember 5v will vary some.


No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Wawa

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..

wilykat

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

Wawa

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..

MarkT

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.
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

david_2018

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.

wilykat

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. 

Go Up