Go Down

Topic: Arduino and six positions rotary switch (Read 18976 times) previous topic - next topic


Got a simple question about this:

Will I need to use 1 arduino port for every pin in the switch?
Is there any other way to handle them?

I just realized there are like 7 of these switches in my project so I would need a dedicated board just for them.  :~

Thanks in advance.


You can use shift registers or port expanders to get more pins.

Or you can add resistors and feed each switch into an analogue input so that changing the switch contact puts a different voltage into the analogue input.


Thanks mike I will do some research about what you suggest.


What are the switches used for, and you really need them to be rotary switches?

If your project includes a display (or could usefully include one) that you can use to display the values selected by the switches, then consider using rotary encoders instead. A single rotary encoder needs 2 pins to interface it to an Arduino. If you have more than one of them, you can multiplex them and save on pins. For example, 4 rotary encoders = 4 + 2 pins plus 8 small signal diodes. You can typically share the multiplex pins with other devices (such as the display).

Also, do you really need 7 of them? Many rotary encoders include a push button (that is, you can press the knob as well as turn it). I use the push button for selecting which value the encoder changes. When it is pressed, I adjust the cursor on the display to show which value it is controlling. This allows you to use a single rotary encoder to control several different parameters.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.


Hi Dc, I'm planning to recreate the systems of a plane, the rotary switches are present there, so I guess yes, I need them.
If I control severals systems with a single switch it wouldn't be realistic.

Thanks for your inputs.


Dec 21, 2012, 01:06 am Last Edit: Dec 21, 2012, 03:15 am by Rookie2 Reason: 1
found this mike post

Just thought of another way to do what you are after last night. Put 1K resistors between each of the pins, with the last connected to ground and the last on the other end connected to +5V. Then take the common and connect it to an analogue input and read the voltage.

It sounds like the easier way but i'm getting hard time figuring how to wire it.
Can somebody provide a schematic please?

This is one of the switches, a 4 positions one


Dec 21, 2012, 01:07 am Last Edit: Dec 21, 2012, 03:16 pm by PeterH Reason: 1

Will I need to use 1 arduino port for every pin in the switch?

No. All you need is to wire up a resister ladder so that each switch position generates a different voltage, and read the value using an analog input. So that's one analog input per rotary switch, rather than one digital input per switch position.

ETA: Too slow - this is the same as Grumpy Mike's solution.


Another way is to use a 8 bit priority encoder chip with take your 6 discreet switch position outputs and encode them into a 3 bit binary value that you can then wire to just 3 arduino digital input pins.







@Lefty Thank you, this seems to be out of my scope tho, as I'm just starting.

I'll be using the Mike Method which is the same what PeterH suggests.
I just need a little help on how to wire it.


You can wire it in several ways.
One way is to attach the center point to the analogue input with a 4K7 , that is four point seven K, to ground. Then each switch position has a resistor wired to it with the other end to +5V. The value of these resistors are all different and give a diffrent voltage due to potential divid action. The values are not critical, so start off with something like 22K and come down each position.

The other way uses all the same value and has 8 resistors in seriese between the supplies, say all at 1k. Then each node is connected to a diffrent switch position and the common is connected to the analogue input.


The other way uses all the same value and has 8 resistors in seriese between the supplies, say all at 1k. Then each node is connected to a diffrent switch position and the common is connected to the analogue input.

Ok thank you again, ill go this way
My switch (the 4p one) looks just like this

The 4 contacts in the middle is the common pole right?
Also how do I determine which of the outer contacts must I connect with the resistors?

I still don't get how this thing works  :smiley-red:


That is a four pole four way switch. Yes the center connections are the common ones. The way to tell what outer connection it connects to is to measure the resistance or continuity with a meter. You can get a cheap meter for less than $10 from a thrift shop.

For how it works google potential divider.


I own a multimeter and I know how to use it, will do some test and will let you guys know.

Again thanks a million.


This is where i get continuity (it's a 3 pos switch not 4 my bad)

Position 1

Position 2

Position 3

All them

So, could this be the right way to wire it?


Yes but you only need one set of resistors, that is two of them, there is no need to have something connected to each pole.
You also need to connect each end of the chain to power and ground.

Go Up