简体   繁体   中英

Switch connected to an Arduino not working in Tinkercad Circuits

See image: after terminating it rotates to 180 and back to 0 while staying rotating between 0 and 90. And nothing happen if I turn the switch. Don't know what I'm doing wrong. Oh, it could also be the program.在此处输入图像描述

Please Connect a resistor at pin 2 to ground so by default when switch is in off state low voltage is present at pin 2 and else condition is able to work.

Resistor value = 1 Kohm if you are having power rails in range of 0 - 5.5 Volts,

You can add a resistor from digital pin 2 to ground and have the other switch terminal connected to 5V, but the more elegant way would be to activate the internal pull-up resistor and connect the switch to the ground. This way you won't need any resistors. You can check Arduino's online tutorial by searching Arduino internal pullup on Google. Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM