Button does not work?
Beginners usually get trouble when getting started with a button, pushbutton, switch using digitalRead() function.
To avoid this, beginners SHOULD pay attention to the following issues:
1. Floating input problem:
- Symptom: the reading value from the input pin is not matched with the button's pressing state.
- Cause: input pin is NOT used pull-up or pull-down resistor
- Solution: Use pull-up or pull-down resistor. See Arduino Button (with pull-up/pull-down)
2. Chattering phenomenon
It should be considered in only some application that needs to detect exactly number of the pressing.
- Symptom: Button is pressed once, but Arduino code detects several times.
- Cause: Due to mechanical and physical issues, the state of the button (or switch) is quickly toggled between LOW and HIGH several times
- Solution: Debounce. See Arduino - Button Debounce
Buy Arduino and Button
|1 × Arduino UNO Buy on Amazon|
|1 × USB 2.0 cable type A/B Buy on Amazon|
|1 × Button Buy on Amazon|
|1 × Breadboard Buy on Amazon|
|1 × Jumper Wires Buy on Amazon|