It is recommended to first read through the Pull Resistors page. Switches are common in MCU applications as an interface for making further decisions as per embedded software. There are numerous mechanical switch designs, each of which serves a specific application. This page focuses on managing mechanical switches interfaced with an MCU. The pull-up resistor schematic found on the Pull Resistors page is also used on this page, as shown in Figure 1, to demonstrate the effect of switch “bounce.” When the switch is ON, the ideal input to the pin of the MCU is shown in Figure 2. As explained on the Logic Levels page, a signal cannot be ideal.


Figure 3 represents a non-ideal input to a pin of an MCU, as measured by an oscilloscope.

Despite the switch being pressed only once, there is at least one noticeable voltage spike (noise) after the voltage on the pin falls from 3.3V to 0V. These spikes, i.e., “bounces,” pass the HIGH logic threshold (VIH(min)), which is undesirable and leads to erratic behaviour in a separate circuit that is controlled by the pin’s logic state. Each time the switch is pressed, a different profile on the oscilloscope can be observed. In some cases, there is almost no noticeable noise.
When the plunger (A) of a switch is pressed against the contacts (C), the contact dome closes the open circuit between the outer contacts and the middle contact, as shown in Figure 4.

When the switch is released, the stored elastic energy in the contact dome causes it to rapidly flex upwards and downwards, coming into contact with the contacts a number of times, until there is no more stored energy. The housing (B) of the switch holds all the parts of the switch together. There are two methods to minimise noise: software or hardware de-bouncing. Hardware de-bouncing is more effective yet more costly with additional components and circuit footprint, while software de-bouncing is less effective yet cost-free with no additional components and circuit footprint.