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

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

enter image description here


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

Please help me to connect this switch correctly.

  • \$\begingroup\$ it is a switch, similar to a pushbutton ... have you searched the web for tutorials? \$\endgroup\$
    – jsotola
    Feb 26, 2020 at 6:19
  • \$\begingroup\$ 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 \$\endgroup\$
    – Ibnelaiq
    Feb 26, 2020 at 6:20
  • \$\begingroup\$ You are likely connecting the switch incorrectly, so the switch is connecting vcc directly to ground \$\endgroup\$
    – BeB00
    Feb 26, 2020 at 6:27
  • \$\begingroup\$ 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 \$\endgroup\$
    – jsotola
    Feb 26, 2020 at 6:30
  • \$\begingroup\$ 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. \$\endgroup\$
    – Transistor
    Feb 26, 2020 at 7:21

1 Answer 1


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;


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.