ezButton Library - Single Button Events Example
|1||×||Arduino UNO or Genuino UNO|
|1||×||USB 2.0 cable type A/B|
Image is developed using Fritzing. Click to enlarge image
- Install ezButton library. See How To
- Connect Arduino to PC via USB cable
- Open Arduino IDE, select the right board and port
- On Arduino IDE, Go to File Examples ezButton 02.SingleButtonEvents example
- Click Upload button on Arduino IDE to upload code to Arduino
- Open Serial Monitor to see result:
- Press the button and then release
The button is pressed
The button is released
※ NOTE THAT:
Even you pressed and released the button only once, the output in Serial Monitor may show several pressed and release events. This is the normal behavior of the button. This behavior is called the “chattering phenomenon”. You can learn more in Arduino - Button Debounce tutorial .
To make it much easier, we can use the debouce function of this library. See Button debounce example with library .