debounce buttons with a analog pin?

The first image shows a very 'noisy/bouncy' falling edge, about 2ms in duration from a switch.
These are the bouncing transitions that are being discussed.
There would be similar pattern on the rising edge.

The second image shows a 1uF polarized capacitor placed across the switch.
Note, the pull-up resistor would be enable for this pin.

The third image shows the voltage transition after the capacitor addition.
The charging time has been slowed, but all bounces have been filtered out.

.

Thank you LarryD, for the explanation and the scope data.
I was feeling a bit silly for a while, slowing down the read response time that much compared to the debounce time..

Then i realized that the timeframe, a fraction of a second, and concluded that i wouldnt be able to detect the delay with my five senses regardless.. :slight_smile:

Its so amazing how things can act so differently on such different scales, like falling ants compared to falling elephants...

Thanks again everybody, for sharing ye´ol wizdom!

xarvox:
The plan is to use ISR´s to count the number of times it detects a button pressed, clearing the counter if button is released, and then use a number of if-statements, comparing each button press counter with predefined short/long-click durations.
If the counter is more than zero, the button is pressed.
I might eventually set the limit to 2 or something higher, in case i need a bit more signal filtering.

If you use debounce that works (the LOWER scope image in that post above) then you will not get more than one press for one release even while bouncing 20 times a millisecond, those are sparks not metal making and breaking contact, SPARKS. Heck, my button library does that and returns button state history as 1 value even with button arrays.

Button presses by humans are sssllloooowwwwwwwww to Arduino. There is zero need to use interrupts to keep up with debounced buttons. Even debouncing does not need an interrupt!

Is this a do-something-extreme project or do you just want it to work and maybe be able to do more later?

Would you like an easy to use button library with button array example sketch?

GoForSmoke;

My primary goal for pretty much ANY electronics project, is to further my own knowledge, learn as i go.
I have some learning difficulties, witch means i have trouble understanding textbooks.
I think it relates to the fact that i cannot ask questions about what im reading, im just supposed to absorb the knowledge, even if it collides with my intuition..

So im educating myself with a whole bunch of different projects, mostly relating to my main passion, my recumbent bicycle or my other main passion, music. :slight_smile:

So no, im not doing anything extreme, just playing around with the components so i can learn what they do. :slight_smile:

I have some libraries for buttons, some also allow for short/long/doubleclick and so on, but im not learning much by using others stuff, i want to know how to do it myself. :slight_smile:
Eventually i will write my own libraries, not because i have to, but because i want to learn how to.

Still, thank you for asking! :slight_smile:

Im currently working on a upgrade to my current light-controller (turn indicator and position lights) with a whole bunch of new features (brake lights, rally lights and trailer connector to name a few).
And since ive learned alot from the last version, ive been re-evaluating pretty much EVERYTHING relating to the project, trying to find better ways to do stuff.
..I wouldnt learn much by repeating myself now, would i? :wink:

A small update from my end;
I just finished building a protoboard, containing a arduino nano dip-socket, buttons, cap´s and LED´s (for sw testing) and its working like a charm!
I wouldnt want to show anyone the bottomside, but its barely noticeable under a layer of insulating tape. :slight_smile:

I couldnt find any caps with 1µf (labeled 105, right?), so i took the biggest one i could find below it, a 104, 0.1uf if im not mistaking?
In any way, its working just marvelously!

According to a online calculator, the cap should be filled to 3v (0.6*5v) in 4,5ms, (5v, 4k7 pullup) witch sounds just about spot on perfect to me. :slight_smile:

I expected to find that the ISR counter would add one for each program loop, but it turns out that interrupt is only triggered once per event.
I should have been able to guestimate that, but i cant be right all the time, it wouldnt be fun at all.. :slight_smile:
This means ive learned something today as well, so now i can go to bed. :wink:

Button bounce tester here: Button bounce tester -- test your button. - Project Guidance - Arduino Forum