How can I use a toggle switch with Arduino ?

Using the code above in Reply 1 from MarkT, connect the center pin to ground and connect one of the other two pins to pin 2 of the Arduino. Done.

Which of the outer pins on the switch that you connect to, depends on which one of the toggle switch positions you wish to be closed. Flip it one way, the center pin is connected to the outer pin on the opposite side.

Here is an illustration of why toggle switches generally seem to work backwards as compared to slide switches: