Rotary switch with readadc

Captain Haddock

Senior Member
Am I right in thinking that with a 12 position rotary switch I can link the pins with 11x 910ohm resistors and get a nice clean readadc result by putting 0V and 5V to each end of the resistor chain and taking the reading from the selector pin?
I've not dabbled with this stuff for quite a while so brain has faded big time.
 

oracacle

Senior Member
sound about right. the actual term you are looking for is resistor ladder. there is a fair bit on here about them, loads on the net in general.
 

hippy

Senior Member
That should work okay. The only issue may be that the wiper may disconnect from the switch whilst it is being turned but you can have your software check that the result is stable, something like ...
Code:
Do
  ReadAdc ROTARY_POT, b0
  b1 = b0 Min 10 - 10
  b2 = b0 + 10 Max 255
  Pause 10
  ReadAdc ROTARY_POT, b0
Loop Until b0 >= b1 And b0 <= b2
 

AllyCat

Senior Member
Hi,
get a nice clean readadc result by putting 0V and 5V to each end of the resistor chain
It depends how you define "clean", but even with a set of "matched" resistors (which could be any value up to at least several kohms each), there may be some "dither" between adjacent ADC values.

Even with a "perfect" set of resistors, the ADC values would be typically: 0 , 23 , ... 115 , 139 , .. 255 , so it might be better to alter the resistor at the top or bottom of the ladder (or add one between supply or ground) to get closer to a "clean" set of (say) : 0 , 24 , 48 , .... 240 , 255 . Or making the bottom resistor about 50% larger to give a set of values around: 0 , 33 , 55 , 77 , ... 231 , 255 (Vcc) which will truncate nicely when dividing by 22 to give a very reliable 0 .... 11.

Cheers, Alan.
 

Captain Haddock

Senior Member
That's no problem as I can go for a range for each option if only to allow for a little corrosion changing resistances in the system (it's going to be on a boat so corrosion at some level is bound to happen), it's for a wiper timer setup so most of the changes of position will be within a timed loop anyway.
I did one controller with a guitar killpot as the switch with the push action for the washer but want to do a new version as at sea the spray is nearly always mostly one side and the lee side always gets the washers blown off the screen so I end up with dry salt being scraped over the screen, I am having new glass fitted so it seems a good time to split the wipers so only one side at a time gets washed and a single wipe and avoid the abraision, the rotary switch will be for intermittant timing for inland running only, the washer will be done by a mom-off-mom switch with a single wipe after the wash.
 

erco

Senior Member
Ha, I just did this exactly in a20M2 project. 1K resistor ladder worked fine on this rotary switch, but per hippy this non-shorting switch gets funky in transition. His software solution is prolly fine, but I went the hardware route and put a 10uF electrolytic filter cap between the wiper & ground. Problem solved.
 

Attachments

1968neil

Senior Member
I used a potentiometer with click positions a while back and still working well to this day.

Here's a link to the discussion :


regards
Neil
 
Last edited:

Captain Haddock

Senior Member
Ha, I just did this exactly in a20M2 project. 1K resistor ladder worked fine on this rotary switch, but per hippy this non-shorting switch gets funky in transition. His software solution is prolly fine, but I went the hardware route and put a 10uF electrolytic filter cap between the wiper & ground. Problem solved.
Thanks for the cap on the wiper idea, that switch looks exactly the same as the one I have.
 
Top