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.
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.
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.
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?
Rookie2:
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.
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.
Grumpy_Mike:
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?
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.
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.
Put a 1K between the ground and the outer spair contact, put another between the spair outer contact and the +5. Remove the resistors from the middle contacts.
Note that as it is only a three position switch you will only be able to read three positions. The readings you will get will be 0, 512 and 1023, in fact the 512 will not be exactly that but somewhere close due to the tolerances on the resistors.