Go Down

### Topic: Rotary switch as stepped potentiometer into analog in....? (Read 3082 times)previous topic - next topic

#### kriista

##### Jun 09, 2011, 05:23 pm
I plan on using a 12 position rotary switch into one of the analog in pins (I'm using 6 of these things, so that would gobble a TON of digital pins). I plan on just connecting resistors across the pins to make a ladder sort of thing.

Has anyone done something like this? What value resistors did you use? Increasing in value, or all the same?
Code to recognize all the positions?

#### Grumpy_Mike

#1
##### Jun 09, 2011, 05:32 pm
There is a limit to how many switches you can have at the same time on an analogue input port. This depends on the accuracy of your resistors and the accuracy of the A/D. The A/D is only 10 bits so you won't be able to exceed this, you might if you are lucky be able to get 8 switches to read but more likely 6.
The other problem is lack of speed, reading the A/D is quite slow and you will miss pulses if you are too fast turning them.
Quote
Increasing in value, or all the same?

It depends on what sort of D/A you want to implement, a binary weighted adder or an R/2R ladder, each has it's own advantages / disadvantages.

#### MarkT

#2
##### Jun 09, 2011, 11:18 pm
I would go for as simple as possible - 1k resistors between each contact.  Then its easy to convert the ADC input to a switch-position number, and this in turn can be converted to any function you want, linear or otherwise.    For a 12 position switch that comes to 11k in total which is less than 0.5mA per switch which isn't too wasteful.

One issue is that as the switch moves the wiper might be floating briefly (or simultaneously connected to two neighbouring contacts).  The code will have to identify and reject such 'bad' values.  Reduce the 'floating input' problem by a capacitor of 0.1uF or so between the wiper and ground.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### kriista

#3
##### Jun 10, 2011, 01:05 amLast Edit: Jun 10, 2011, 01:28 am by kriista Reason: 1
I think the kind available locally (maplin) are "break before make" rotary switches, so it would be floating between connections.

Wouldn't that be as easy as making it look for specific ranges only, with the 'floating' ones would give a lower (or is it higher?) value than what it expects for each step.

I guess resolution could be a problem too, I hadn't thought of that.

I suppose it could be a stepped rotary encoder, but I wanted something with absolute positions that I can label and get to easily. Are there encoders that have hard stops at either end?

I should also say that the function of these things will be to switch modes of operation on something, so I won't be going back and forth on them quickly or often, it's just the simplest way I could think of to assign a specific function (1 of 12) to six different inputs.

If I knew enough I could do it with a push to select rotary encoder and a multisegment display, but that's considerably beyond my understanding at the moment.

#### Grumpy_Mike

#4
##### Jun 10, 2011, 09:42 am
Sorry I think I mis understood what sort of switch you had. I it was a rotory encoder. If it is just anrotorynswitch then you don't have to worry about the combination of switches as only one will be on at one time. Therefor you can just have a chain of 12 resistors with the switch shorting out further up the chain each time.

#### kriista

#5
##### Jun 11, 2011, 12:36 am
So I'm having a hard time visualizing how this would be connected. 5v going to central pin of 12position switch, then 1k resistors across each pin. An analog pin connected to the 12th pin (or does ground go there?). Where does ground (or analog in) go?

I guess what's the 'wiper' in a 1 to 12 rotary switch?

Oh wait, so pin1 is 5v, pin12 is ground, and the central pin is the analog in, with a .1 cap going from the central pin to pin12/ground to slow the switching rate. Can I go with a bigger value to avoid 'floating' problems altogether? I don't need to switch fast at all, and my hardware skills are much better than my software skills.

I would go for as simple as possible - 1k resistors between each contact.  Then its easy to convert the ADC input to a switch-position number, and this in turn can be converted to any function you want, linear or otherwise.    For a 12 position switch that comes to 11k in total which is less than 0.5mA per switch which isn't too wasteful.

One issue is that as the switch moves the wiper might be floating briefly (or simultaneously connected to two neighbouring contacts).  The code will have to identify and reject such 'bad' values.  Reduce the 'floating input' problem by a capacitor of 0.1uF or so between the wiper and ground.

#### Grumpy_Mike

#6
##### Jun 11, 2011, 10:43 am
The so called floating problem will not be an issue, even without an external capacitor the internal capacitance will take cair of it.

#### kriista

#7
##### Jun 16, 2011, 02:50 am
I found some stepped potentiometers at mouser:

http://www.mouser.com/ProductDetail/Alpha-Taiwan/RV16AF-10-15R1-B10K-OD/?qs=sGAEpiMZZMtxdMMi52izypa54xBHd143Grr7SNwnp5A%3d

Would this be the same as using a rotary switch? (11 detents = 12 positions?)

These are cheaper than 12 position switches is why I'm asking.

#### Grumpy_Mike

#8
##### Jun 16, 2011, 09:07 am
I have not come across that type before but it looks like it will do fine.

#### kriista

#9
##### Jun 16, 2011, 10:42 am
So does "11 detents" mean there are 11, 12, or 13 positions? I'm always terrible that understanding that kind of thing.

#### Grumpy_Mike

#10
##### Jun 16, 2011, 06:24 pm
My guess is 11 clicks, giving 12 different values.

#### kriista

#11
##### Jun 16, 2011, 10:25 pm
The datasheet is a bit confusing as well as it says 11 positions (which would imply 11 positions) where mouser says 11 detents (which would imply 12 positions).

I think I might bite the bullet and try to go for an LCD display + encoders/buttons to try to wrangle all the information (rather than 6 rotary switches, 4 potentiometers, and 2 toggle switches).

It's a bit scary as I've not done LCD stuff before, and nothing will work until I figure that part out (whereas with switches/pots, I can add functionality to the code one switch/pot at a time).

I made this thread here about the woe-is:

http://arduino.cc/forum/index.php/topic,64192.0.html

#### cowasaki

#12
##### Jun 22, 2011, 12:18 am
Why would you want to do this?

Is it in order to select one of 20 options or something similar?  If so then this would be easier, you could just use a 5K pot and then use:

selection = ((current value of pot)/1024*(number of options))

If this is what you want then let me know as I have written a menu system based on this very principal and would be happy to let you have code to demonstrate it but this give an idea:

Code: [Select]
`#define menuitems 9#define menusensor A0int menuentry;int lastmenuentry;void setup() {  Serial.begin(9600);}void loop() {    lastmenuentry = menuentry;    while (menuentry == lastmenuentry){      int sensorValue = analogRead(menusensor);      menuentry = sensorValue * menuitems/1024;    }    Serial.println(menuentry, DEC);  }`

#### kriista

#13
##### Jun 22, 2011, 01:10 am
It would essentially be that, but the steps would help differentiate positions.

I've sense migrated my idea over to an LCD system as there's so many individual parameters to control anyways.

Go Up

Please enter a valid email to subscribe

### Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy