Hi, im making a hardware debounce for a button. I read about hardware debouncing and i made this debouncing circuit with a pulldown resistor.
5v GND
| |
| 47k resistor
|--0.1uf cap-------|
|---button---------|------Pin on a Multiplexer-------Arduino
Im not using a schmitt trigger inverter, because im not sure i need it, i read that arduino has inverters on every pin.
As i was testing it i pushed it around for 5-10 minutes and the button stopped working.
Then i found a tutorial for hardware debouncing, this one Switch Debouncing - The Lab Book Pages
It says that the fast discharging of the capacitor can burn the buttons legs and it should be discharged via R2. So i thought i have burned them up with my circuit because the capacitor is not discharging through another resistor.
So i wired up another button like the tutorial said using R1=47k R2= 10k C1=0.1uf and D1=1N4004 (without the inverter) giving me around 6ms until it reaches logic 1 and used this code
#include <AnalogMuxDeMux.h>
AnalogMux amux(13, 12, 11, A0); // Define Mux
#define NO_PINS 8
int lastbuttonState =1;
void setup()
{
pinMode (13, OUTPUT); // Selector pin
pinMode (12, OUTPUT); // Selector pin
pinMode (11, OUTPUT); // Selector pin
pinMode (A0, INPUT); // Mux Common OUTPUT
Serial.begin(9600);
}
void loop()
{
// Read the values from the button
int sw = amux.AnalogRead (1) / 1023;
if (sw != lastbuttonState)
{
if (sw == 0)
{
Serial.print("pressed");
Serial.println(sw * 127);
}
}
// Check to see if button is released
if (sw == 1 && lastbuttonState == 0)
{
Serial.print("depressed");
Serial.println(sw * 127);
}
lastbuttonState=sw;
}
The results in serial monitor for 1 press were
pressed0 /This is when i pressed it
depressed127 / Everything else from here is when i depressed it
pressed0
depressed127
pressed0
depressed127
pressed0
depressed127
Can anyone help me debounce it properly, tell me where my mistakes are and what should i do.
Do note im fairly new to Electronics. Thank you in advance.
PS. Im making hardware debounce, because im making a MIDI controller mixer and the built up software delay would eventually lead to big latency and it not responding on time.