\$\begingroup\$
\$\endgroup\$
5
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.
Please help me to connect this switch correctly.
JRE
75k10 gold badges115 silver badges197 bronze badges
asked Feb 26, 2020 at 6:16
1 Answer 1
\$\begingroup\$
\$\endgroup\$
5
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
-
\$\begingroup\$ please tell me how I connect these 3 legs of toggle switch. I want the 0 or 1 from it \$\endgroup\$Ibnelaiq– Ibnelaiq2020年02月26日 08:46:26 +00:00Commented Feb 26, 2020 at 8:46
-
1\$\begingroup\$ @AhmedAli see the edit. \$\endgroup\$ElectronSurf– ElectronSurf2020年02月26日 09:42:26 +00:00Commented Feb 26, 2020 at 9:42
-
\$\begingroup\$ Thanks for helping \$\endgroup\$Ibnelaiq– Ibnelaiq2020年02月26日 09:47:29 +00:00Commented Feb 26, 2020 at 9:47
-
\$\begingroup\$ and will I have to connect 3 leg to
vcc
or not \$\endgroup\$Ibnelaiq– Ibnelaiq2020年02月26日 09:52:36 +00:00Commented Feb 26, 2020 at 9:52 -
1\$\begingroup\$ No, don't connect the third leg to anything. \$\endgroup\$ElectronSurf– ElectronSurf2020年02月26日 09:54:54 +00:00Commented Feb 26, 2020 at 9:54
lang-c
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\$