Hi Everyone
I was wondering if some of you could offer some advice on debouncing a switch with hardware. From what I have read online there seems to be a couple ways that are very similar.
1.) Button goes to LOW when pressed
2.) Button goes to HIGH when pressed.
I was wondering which is preferred, and if there are pros and cons to each way.
Wiring the button for active-HIGH or active-LOW doesn't have anything to do with debouncing.
The discussion linked below about how to program a button is good. The main opinions are that having a lot of accessible+5V nodes in the system makes it easier to short out and damage things, and that the PULLUP_INTERNAL is simpler to wire while also being more protective.
Nice picture, but I’m having trouble following it. I usually use a low-pass filter for buttons and a Schmitt trigger gate, like a 74HC14, as the input interface. You can use this circuit without the extra IC if you prefer—it will work almost as well. R2 and C1 are the primary debounce components.
I always switch on the low side if the switch isn’t in the same enclosure as the processor. Ground tends to pick up less noise, and I size the pull-up resistor to push about 1 mA through the switch.
Thanks everyone for the comments. As someone who is new to Arduino and programing, it's great to hear the different ways that can be used to accomplish as task.
I have used a resistor and capacitor with and without the Schmitt trigger, however I did not notice any difference when with regards to bounce. Perhaps that is due to the fact that my projects are pretty basic compared to some of the projects I have seen on here.
Thanks Pete
Usually only one edge is relevant. In this figure the input goes low when pressing the button. When the button is released the capacitor will be charged. If bouncing occurs when the capacitor hasn’t reached the threshold voltage, it will be discharged, but it’s invisible for the input. The RC-time (resistance multiplied by the capacitance) needs to be chosen to accommodate the bounce time of the switch.
The internal pullup in the UNO is approximately 35kΩ. A capacitor of 1μF will result in a debounce time of 35milliseconds.