Date : August 19, 2021
Hey, this is Shaunak !
When we are working with tactile switches integrated in an Embedded System, being a programmer, we often face the switch debouncing issue which is happens due to the mechanical contact of the switch debouncing and hence it becomes very tedious at times to read the switch input properly for taking any action in the code.
I wanted to overcome this challenge, so I took up an Arduino Nano Board, a tactile switch and a Mini USB to USB Type B Cable that can connect my Arduino Nano to the PC.
Here is the Connection Diagram that I used :
As a part of testing points to be checked, I decided the following procedure :
LED is Off at start up.
1st Switch press: LED blinks at frequency of 0.5 Hz.
2nd Switch press: LED blinks at frequency of 1 Hz.
3rd Switch press: LED blinks at frequency of 2 Hz.
4th Switch press: LED turns off. Reset the Switch Press Counter.
Repeat.
Click/Tap Here to go through the Arduino Project. There is a file called "Switch_LED_Blink.rar" inside the shared folder. Unrar it and you will find the project folder.
Click/Tap Here to go through the code only. The code has comment on every line that almost makes it self explanatory.
Some points to be noted :
Timer interrupt interval is 10 us
Switch based Digital Input Pin is taken as Pin 3 of Arduino Nano as it can be used as interrupt pin.
Pin 3 mode is set as INPUT_PULLUP as it has to detect Ground on Switch Press.
Switch based Digital Input Interrupt is set to the mode "FALLING" means it will invoke as soon as the Switch is pressed and connects the Input Pin 3 of Arduino Nano to Ground.
Pin 13 of the Arduino Nano Board is selected as the OUTPUT Pin to drive the LED. It is selected because the On-Board LED is connected to it.
Here is working video of this project :