I'm prototyping with a bunch of no name mechanical button mini-switches and SAM D21 microcontroller (Adafruit Feather M0). The switch is connected directly between the ground and the input pin #19 (PB02 of ATSAMD21G18) without any debouncing circuitry #19. This Arduino test program:
constexpr int BUTTON = 19;
void setup()
{
pinMode(BUTTON, INPUT_PULLUP);
}
void loop()
{
Serial << digitalRead(BUTTON) << ", " << micros() << "\n";
}
produces a log of clean transitions without a single bounce, e.g.
1, 8891998
1, 8892101
1, 8892197
1, 8892362
0, 8892468
0, 8892569
0, 8892668
0, 8892764
....
0, 9063951
0, 9064048
0, 9064145
0, 9064305
1, 9064401
1, 9064507
1, 9064610
1, 9064706
Pin PB02
is read more often than every 0.1ms, which seems sufficient to catch mechanical switch bounce. Is there some hardware filtering involved here? Unfortunately, I don't have a scope handy to capture the signal.
Here is a picture of the switch:
EDIT
There are several answers blaming serial port latency for missing the bounce. This is incorrect. I'm logging timestamps of each measurement, which are better than 4μs accurate. See https://www.arduino.cc/en/pmwiki.php%3Fn%3DReference/Micros for description of micros()
function, specifically: "On 16 MHz Arduino boards (e.g. Duemilanove and Nano), this function has a resolution of four microseconds".
EDIT'
Picture of the test setup, as requested (tiny switch on the left):
Best Answer
Not every electromechanical contact exhibits bounces, and if it does, not always every single time you activate it. Moreover, some switches bounce only on one "edge" of the signal, i.e. only when closed or open. And other switches' bounces are so quick that they are not detectable by common MCUs. You need a scope to capture that behavior.
The variations could be astounding.
An interesting article about debouncing from embedded guru Jack Ganssle shows you some empirical data.
Excerpts (emphasis mine):
[...]
[...]
Bottom line: always assume switches will bounce and implement a conservative debouncing strategy (HW, SW or even both for maximum reliability).
If you really need to optimize things, you have to characterize your switch with sound statistical methods (never trust the manufacturer, unless you have a legal guarantee), so that you can choose the optimum debouncing strategy/parameters.