How to wire a 4 position slide switch

Need help wiring a 4 position slide switch that is DP4P (Item # G-1138S-1110, G - Series Double Pole/Four Position (with Detent) Standard Slide Switch On CW Industries) to an arduino mega. I have two of these that I need to wire into the microcontroller; each 4 way slide switch will be used to select from 4 settings. I think I have an idea of how to wire but I am not sure how the wiring diagram would look.

Thanks,
Kuz

(deleted)

Measure it with a multimeter. Or write a short test sketch.

Connect one pin of the switch to ground, one other pin to an Arduino pin. Use pinMode(yourPin, INPUT_PULLUP). Write a program that switches the led on pin 13 on if the input pin is low and vice versa.

Repeat for all pins and deduce how to connect.

The switch has 5 terminals on each side. On the two poles, each position shorts adjacent pairs of terminals.

1 2 3 4 5
6 7 8 9 10

Position A: 1-2, 6-7
Position B: 2-3, 7-8
Position C: 3-4, 8-9
Position D: 4-5, 9-10

Connect Arduino Pin 4 (INPUT_PULLUP) to switch pins 2 and 3.
Connect Arduino Pin 5 (INPUT_PULLUP) to switch pin 7.
Connect switch pins 1, 4, 6, and 8 to Arduino Ground

The inputs will read HIGH (due to the internal pull-up) unless they are connected to Ground.

Pins 5 and 4 will read:
LOW LOW in Position A
LOW HIGH in Position B
HIGH LOW in Position C
HIGH HIGH in Position D

johnwasser:
The switch has 5 terminals on each side. On the two poles, each position shorts adjacent pairs of terminals.

1 2 3 4 5
6 7 8 9 10

Position A: 1-2, 6-7
Position B: 2-3, 7-8
Position C: 3-4, 8-9
Position D: 4-5, 9-10

Connect Arduino Pin 4 (INPUT_PULLUP) to switch pins 2 and 3.
Connect Arduino Pin 5 (INPUT_PULLUP) to switch pin 7.
Connect switch pins 1, 4, 6, and 8 to Arduino Ground

The inputs will read HIGH (due to the internal pull-up) unless they are connected to Ground.

Pins 5 and 4 will read:
LOW LOW in Position A
LOW HIGH in Position B
HIGH LOW in Position C
HIGH HIGH in Position D

That makes sense; I have one question for this response; do you wire any of the pins to the 5V supply? Why/Why not?

skuznarsky:
I have one question for this response; do you wire any of the pins to the 5V supply? Why/Why not?

No. Because it is not needed. The other pins are left unconnected.
The pull-up resistors built into the ATmega will cause the pins to read HIGH if they are not connected to Ground. The two states (HIGH=not connected to ground, and LOW=connected to ground) are sufficient to determine the position of the switch.
There are three switch pins that are not connected: 5, 9, and 10. If you connected +5V to pin 5 or pin 9 then some positions of the switch would short +5V to Ground and damage your board. You can safely connect +5V to pin 10 of the switch but it wouldn’t do anything useful.

Great, thank you so much for the help. I believe I can apply this type of strategy to my other slide switches and push buttons. This makes wiring so much easier.

Great advise JW.

Thanks,
Kuz

I also have a 2 way slide switch that is basically the same setup; it has 6 of the prongs on the bottom and is also a double pole. I think that I have to wire it with only 1 pin as below

1-2-3
4-5-6

Hook up 1 to pin 4 (turn on Pull-up resistor) and 2 to ground. With position A connecting 1-2 and 4-5 and position B connecting 2-3 and 5-6.

Position A and B will read the following for Pin 4

A=Low (connected to ground)
B=High (not connected to ground

Essentially pins 4,5,6 are not used.

Thanks,
Kuz

skuznarsky:
Hook up 1 to pin 4 (turn on Pull-up resistor) and 2 to ground. With position A connecting 1-2 and 4-5 and position B connecting 2-3 and 5-6.

Position A and B will read the following for Pin 4

A=Low (connected to ground)
B=High (not connected to ground

That should work as you describe..

@johnwasser; I was finally able to set up my Arduino and do some coding. The wiring that you described worked perfectly as you probably knew it would. I just wanted to give you a huge thank you for helping me out, it is much appreciated.

thanks,
scott