0
\$\begingroup\$

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

Tries:

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.

JRE
75k10 gold badges115 silver badges197 bronze badges
asked Feb 26, 2020 at 6:16
\$\endgroup\$
5
  • \$\begingroup\$ it is a switch, similar to a pushbutton ... have you searched the web for tutorials? \$\endgroup\$ Commented 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\$ Commented Feb 26, 2020 at 6:20
  • \$\begingroup\$ You are likely connecting the switch incorrectly, so the switch is connecting vcc directly to ground \$\endgroup\$ Commented 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\$ Commented 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\$ Commented Feb 26, 2020 at 7:21

1 Answer 1

3
\$\begingroup\$

Arduino related question goes here: Arduino SE.

schematic

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:

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.