1 Pole 12 Position Rotary Switch Wrapping/Looping Causing Error

I have a 1 pole 12 position non-shorting rotary switch that I’m trying to use for my Arduino application to select different functions based on what value I read.

I’m using eleven 10 K Ohm resistors connected in series between poles 1 through 12. There is no resistor connecting pole 1 and 12. Position 1 has 5V lead. Position 12 has GRND lead. The single pole is connected to my Analog 0 pin on my Arduino.

This is my code:

int switchPin = A0;    // select the input pin for the potentiometer
int switchValue = 0;  // variable to store the value coming from the sensor


void setup() {
   // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  switchValue = analogRead(switchPin);    
  Serial.println(switchValue);
  delay(1);        // delay in between reads for stability
}

I print out discrete values for all 12 positions going from position 1 to position 12: 1024, 910, 810, 710…0.

The error I get happens when I wrap/loop from position 12 to 1 OR position 1 to 12. When I switch between these two positions my Arduino stops printing in the Serial Monitor as if the board has shorted or reset. If I just sweep from position 1 to 12 and back to 1 everything is fine. I’ve checked my wiring with my multimeter and don’t see any obvious shorts.

Could this be a defective switch? Is there something obvious I’m doing wrong?

insultcomicdog: Could this be a defective switch?

Yes, it is obviously shorting!

Or did you put a capacitor across the common of the switch to "smooth it out"?

There is no capacitor attached to the GRND. Should there be?

A small update....I moved the 5V and GRND to completely different positions on the switch and am getting the same behaviour at new positions. The Arduino becomes unresponsive when moving from the position with 5V to the position with GRND. Which possibly rules out a short at the original positions.

Hi, it sounds like you have a "make before break" rather than a "break before make".

If you place a 1K resistor between pole 1 and 5V, this will current limit for just the switching time, it will change your other switch values, but it will get you out of a bind.

Tom...... :)

Thanks for the tips and diagram.

I tried putting a 1K resistor between 5V and GRND poles but still get the same behaviour.

After having this issue, I did learn about shorting vs non-shorting rotary switches and suspected mine was a shorting switch. When I took it back to the vendor he said it was non-shorting, but maybe he was wrong.

It's hard to tell what the contacts are doing because the wafers are so close together.

Hard to take pics but this is what I got.

I guess I'll see if I can buy another switch if I can't get this one to work.

One more small update....

I set my switch halfway between the 5V and GRND positions and used my multimeter to bridge the contacts that the switch's shorting contact touches, and they indicated a short...So I'm going to guess that it is indeed a shorting switch.

insultcomicdog: I tried putting a 1K resistor between 5V and GRND poles but still get the same behaviour.

Of course you did, because that was not what you were told to do!

What was suggested, was to put a 1k resistor (220 ohms would be more appropriate) between the pin to which you are connecting the 5V, and the actual 5V supply, so that nothing ever connects directly to the 5V.

It is blatantly obvious from looking at the design of your switch, that it is a "make-before-break" design. This is actually in order to to reduce wear on the wiper as it "hops" from one contact to the next.

Just wire the resistor in the correct place and you will have no further problems.

insultcomicdog: When I took it back to the vendor he said it was non-shorting, but maybe he was wrong.

:grinning: :roll_eyes: :grinning:

insultcomicdog: I guess I'll see if I can buy another switch if I can't get this one to work.

Total waste of time (unless you can find the proper type dlloyd has illustrated with the quality glass fibre wafers). It is the deliberate design of the switch.

Excellent pictures, by the way.

Hi, to put it another way, lift the 5V wire of number 1 terminal, and connect a 1K or 220R resistor to it, then connect the 5V to the other end of the resistor.

By the looks of the contacts in the really good pictures, it is "make before break".

Thanks.. Tom...... :)

Do you have a multimeter ? Have you tried measuring the continuity between the switch contacts ? Can you post a closeup photo of the BOTTOM of the switch ? This is a very simple issue to resolve with the proper tools.

raschemmel:
Do you have a multimeter ? Have you tried measuring the continuity between the switch contacts?

Did you read reply #7?

raschemmel:
Can you post a closeup photo of the BOTTOM of the switch ? This is a very simple issue to resolve with the proper tools.

Eyes?

The matter is no longer in question. The photos show conclusively that it is a “make-before-break” design. What benefit would another photo of the underneath of the switch offer?

What benefit would another photo of the underneath of the switch offer?

No comment. :smiley:

@Paul__B, @TomGeorge,

I finally got around to debugging this switch. Thanks for clarifying where to put the 1K resistor. Now that it's sitting between the 5V and the 1 positions I'm able to loop through my values without the Arduino resetting.

My values are a bit different but usable:

0
89
179
274
366
463
553
642
738
827
926
1016
0
90
185
271
370
459
552
650
737
830
920
1016

Paul__B: It is blatantly obvious from looking at the design of your switch, that it is a "make-before-break" design. This is actually in order to to reduce wear on the wiper as it "hops" from one contact to the next.

Before I got this switch working I bought some "non-shorting" switches from a different vendor on ebay:

http://www.ebay.ca/itm/220515815815?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649

BUT from what I can see in the pics, these look exactly like my "shorting" switch. Are these new switches "shorting" or "non-shorting"? I'm trying to confirm with the seller.

If these are in fact shorting switches, at least I have a work around now.

insultcomicdog:
Before I got this switch working I bought some “non-shorting” switches from a different vendor on eBay:

Hmmm. This vendor currently has 3,867 items catalogued, including face massagers, mountain bikes, kickboxing exercisers, a variety of electronic parts, a lot of electric guitar parts and accessories, and some really funny things.

insultcomicdog:
BUT from what I can see in the pics, these look exactly like my “shorting” switch. Are these new switches “shorting” or “non-shorting”?

They do look identical, don’t they? The critical part is that the “wiper” on this design of switch is under spring pressure to hold against the contacts. It must therefore transfer from one contact to the next by pressing equally on both, otherwise it would fall into the gap between. You will notice how the contacts are alternately splayed inwards and outwards at each end to provide two separate places to simultaneously hold the wiper as it transfers. The only other way would be to have an insulating “land” between the contacts, clearly the switch does not have this.

The classic “oak” switches have a different construction where the wiper is caught between two spring contacts at each position. The wiper does not need to be held between adjacent contacts, whether it is make-before-break or break-before-make depends only of the geometry of the wiper and spacing between the contacts.

insultcomicdog:
I’m trying to confirm with the seller.

Lotsa luck! :grin:

Noting their inventory, do you imagine they understand anything whatsoever about switches?

insultcomicdog:
If these are in fact shorting switches, at least I have a work around now.

Yep.

I am not convinced that analogRead() should ever give you the answer 1024

I am not convinced that analogRead() should ever give you the answer 1024

If it did, I think I would jump out of my seat ! (it would freak me out)

The classic "oak" switches

I'm pretty sure that's phenolic. Phenolic

Oak is the manufacturer not the material…see www.oakgrigsby.com/ Oak Grigsby has been bought by Electroswitch. Every GOOD guitar switch was an Oak… YMMV

R

Yeah, I knew that. I was just kidding...(no actually I didn't know that).