When a mechanical switch is pressed or released, it undergoes a brief period of rapid physical bouncing before settling into a stable position. This phenomenon is known as "switch bounce" and occurs due to the mechanical nature of the switch's contacts coming into contact or moving apart. The bounce typically lasts for a few milliseconds but can vary depending on the specific switch.
The switch bounce creates multiple false transitions or rapid toggling of the switch state, even though the user only intended to perform a single press or release action. This happens because during the bouncing period, the electrical contacts inside the switch make and break contact rapidly and intermittently.
Here's what happens during a switch press:
Initial state: The switch is open (OFF), and there is no electrical continuity between its contacts.
Pressing the switch: When the user applies force to the switch to close it (turn it ON), the contacts come into contact with each other. However, due to the mechanical properties of the switch, they don't make a solid, stable connection immediately.
Bouncing: Instead, the contacts bounce off each other several times in rapid succession. This rapid movement results in intermittent connections being made and broken. As a result, the electrical state of the switch rapidly toggles between open and closed states several times in a short span of time.
Settling: After a few milliseconds, the mechanical bouncing stops, and the contacts finally settle into a stable, closed position (ON state).
The same bouncing phenomenon occurs when the user releases the switch (opens it). The contacts bounce off each other multiple times before settling into the stable open position (OFF state).
The problem with switch bounce is that electronic circuits and microcontrollers that read the state of the switch can't respond instantaneously to such rapid changes in the switch state. As a result, the circuitry may detect multiple false transitions during the bouncing period, interpreting them as multiple presses or releases of the switch.
Switch debouncing is essential to avoid these false transitions. It involves adding hardware or software measures to eliminate the effects of switch bounce and ensure that the circuit interprets a single press or release correctly. Common debouncing techniques include using hardware components like capacitors, resistors, and Schmitt triggers, or using software algorithms to filter out false transitions caused by switch bounce.