Connecting up a Toggle Switch

I have a bought a toggle switch like the following :

Now I'm having a problem as regards how to connect this up to my Arduino.
As you can see, it has 6 legs; so which legs should I solder wires to and how should i connect the wires to Arduino ?

it has 6 legs; so which legs should I solder wires to and how should i connect the wires to Arduino ?

So that makes it a DPDT (double pole, double throw) switch.
It really is two switches (poles) in one package, but with only one activating lever.

So you only need to be concern with one pole (three terminals in a row). The center terminal of a pole can be wired to ground. Either of the other 2 pins (in that row) can then be wired to an Arduino digital input pin. The remaining 4 pins are not needed if you just need a switchable input for an Arduino digital input pin.

Then your sketch could include the following:

int ledPin = 13; // LED connected to digital pin 13
int SwitchPin = 2; // Switch connected to digital pin 2
int val = 0; // variable to store the read value

void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(SwitchPin, INPUT); // sets the digital pin 2 as input
digitalWrite(SwitchPin, HIGH); // turn on pullup resistor for switch
}

void loop()
{
val = digitalRead(SwitchPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the switch's value
}

Lefty

Excellent, exactly what I was looking for.
thanks retrolefty!

/me

you ever get your lcd working good? im playin with the 4 bit mode now ;). waiting on my new gps shield and unit from adafruit! cant wait to start playing with it :wink: