# Connecting toggle switch to Arduino Uno

I am struggling to make a cockpit for my home-made flight simulation.

How can I connect this toggle switch to an Arduino Uno:

Tries:

I connected one end to "Ground" another to "VCC" and middle one to any analog pin. But it turns off the Arduino.

• it is a switch, similar to a pushbutton ... have you searched the web for tutorials? – jsotola Feb 26 '20 at 6:19
• Yes but nothing works. Please help me if it can be connected as similar to pushbuton and I want to get it's state 0 or 1 – Ibnelaiq Feb 26 '20 at 6:20
• You are likely connecting the switch incorrectly, so the switch is connecting vcc directly to ground – BeB00 Feb 26 '20 at 6:27
• nothing works is a meaningless description of a problem ... please update your post with a description of how you connected the switch, the code that you used, what you expected to happen and what actually did happen – jsotola Feb 26 '20 at 6:30
• Show a photo. You don't need an analog input. It's on/off so a digital input is all that is required. Again, describe what exactly happens when you toggle the switch. – Transistor Feb 26 '20 at 7:21

Arduino related question goes here: Arduino SE.

simulate this circuit – Schematic created using CircuitLab

#define switch 3

void setup(){
pinMode(switch, INPUT_PULLUP);
}

void loop(){
if(switch == LOW){
do this;
} else {
do that;
}
}


Edit:

• please tell me how I connect these 3 legs of toggle switch. I want the 0 or 1 from it – Ibnelaiq Feb 26 '20 at 8:46
• @AhmedAli see the edit. – ElectronSurf Feb 26 '20 at 9:42
• Thanks for helping – Ibnelaiq Feb 26 '20 at 9:47
• and will I have to connect 3 leg to vcc or not – Ibnelaiq Feb 26 '20 at 9:52
• No, don't connect the third leg to anything. – ElectronSurf Feb 26 '20 at 9:54