Switch Bounce
Switch bounce is the uncontrolled making and breaking of an electrical contact that occurs when closing a switch. It is usually due to the intermittent and random opening of closed contacts when they collide with each other. The term contact chatter also defines switch bounce, which is when the contacts make and break the electrical connection before coming to a final rest.
The bounce effect is undesirable because a digital system could interpret each bounce as a genuine switch depression thereby interpreting multiple depressions. Therefore, if you had a counting system that relied on a closing switch, then the counting will not be smooth, but rather random.
The term debouncing refers to solutions that eliminate this bounce effect. In engineering, there are two approaches, which can involve either hardware such as a latch and capacitors, or software with the introduction of delay loops. Due to the random nature of the bounce effect, a software solution is usually more reliable than a hardware solution, because the programmer can take information from multiple places to determine if the switch closed. It is also the cheaper solution eliminating the need to include additional hardware.
Whether you use one approach, or the other, or both depends upon how critical the application is. If the switch releases nuclear tipped cruise missiles, then you might want to include both approaches. However if it is a peanut counter for the local zoo which feeds monkeys, then just a cheap software solution could work.
Simple Solution
A bounce buffer is usually a hardware solution consisting of an electronic circuit that eliminates the undesired bounce, which occurs with mechanical contacts. A simple buffer might consist of a capacitor across the switch and a NOT gate as shown above.
If we had a switch connected to a machine that periodically closed it, then a very simple solution would be to use a capacitor across the switch. The capacitor charges through the resistor, which takes time therefore producing only one input pulse. The capacitor also holds the input low whilst the switch bounces.
T=R×C
Therefore, C=T/R
Using an oscilloscope, we can measure the period T, and since we know the value of the resistor R, we just have to substitute it into the above formula to find a value for a suitable capacitor.