Working on Debounce / Interrupts on Switch with MCU
Switch are standard input to any electronic projects. Tactile switch works well in a PCB also can be used on a solderless breadboard. Switch are normally open or disconnected and when the push button is pressed are momentarily closed. Tactile switch are everywhere and they are especially popular in DIY electronics and microcontroller boards because they are well suited to act as a boot option or reset switch. Particularly, momentary switches are switches that don’t save their state you depress the switch. Below are the illustration that covers the purpose of the switch together with the microcontroller.
Interrupts are very useful feature in the microprocessor. Interrupts allows you to run a program while still being able to react to asynchronous input externally. Example below will demonstrate the uses of interrupt together with denouncing.
Tactile switch / Push Button generates open/close transition when pressed, due to a mechanical issue: these transitions may read a multiple press in a very short time. Without debouncing, pressing the push button once may generate an unpredictable results or noise. As you can see the code below its uses milis() function to keep track the time passed since the push button was pressed.
intLedOutput=12;// Define as LED Output Pin 12 you can change this to 13 if you dont what pin 12 as output indictor
intSensorPin=2;// Define as Sensor Pin Input
intValue;// Define as variable
voidsetup()
{
pinMode(LedOutput,OUTPUT);//Set as LED output
pinMode(SensorPin,INPUT);//Set as photo interrupter sensor output interface
}
voidloop()
{
Value=digitalRead(SensorPin);// Set as sensor read SensorPin
if(Value==HIGH)//If value is equal to HIGH estate then turn LED output = high
{
digitalWrite(LedOutput,HIGH);// Set ledoutput to HIGH or ON
}
else
{
digitalWrite(LedOutput,LOW);// Set landoutput to LOW or OFF
}
}
Source Code / Sketch Code for Debounce & Interrupt
The code below will demonstration how to use debounce on the Arduino micro-controller using push button. When button press it will stay HIGH State if press again it will stay at LOW State.
We use cookie to provide you the best possible experience, this site uses cookies and by continuing to use the site you agree that we can save them on your device. Cookies are small text files which are placed on your computer and which remember your preference / some details of your visit. Our cookies don’t collect any personal information. For information, please read our Privacy Statement and Cookie Policy , which also explains how to disable this option in your browser. Cookie SettingsACCEPT
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are as essential for the working of basic functionalit...
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.