r/ArduinoProjects • u/Nearby-Budget-5520 • Apr 21 '23
what happened hear
when i touch jumper wire this happened closing circuit without grounding/circuit loop and sending keystroke how is this possible. i am testing simple one pushbutton keyboard code.
2
u/Prudent-Strain937 Apr 21 '23
Set the pin mode to pull-up.
https://docs.arduino.cc/tutorials/generic/digital-input-pullup
2
u/tipppo Apr 21 '23
Classic case of "floating input". When an input pin is not somehow pulled to 5V or GND it will pick up electrical noise from the air. You need to add either a pulldown resistor between the input and GND, a pullup resistor from the input to 5V, or declare the pin as pinMode(buttonpin, INPUT_PULLUP); to use the Ardunio's built in pullup resistor. If you use pullup then you need to reverse your logic. Either: if (!buttonState == HIGH) (add a "!") or if (buttonState == LOW)
2
1
u/Nearby-Budget-5520 Apr 21 '23