The short answer
A mechanical contact can make and break several times while settling. Give the input a defined idle level, then debounce if the application needs one event per physical action.
On this page
One action need not produce one edge
A mechanical switch does not necessarily move from open to closed in one perfect transition. Its contacts can touch, separate, and touch again before settling, producing multiple electrical edges. The exact timing and shape depend on the switch, how it is pressed, and the circuit; a drawn trace is only illustrative, not a promised waveform for a particular product. A counter that increments on every falling edge might count one physical press several times. The release transition can bounce too, so a press-only fix does not automatically handle release.
Give open and closed states valid voltages
Consider a switch between a digital input and ground, with a pull-up to an allowed 3.3 V supply. Open should read high and closed should read low, assuming both levels meet the input's data-sheet thresholds. Without the pull-up, an open switch can leave the pin floating, which is not the same diagnosis as bouncing contacts. Inspect the actual switch pin pairs, shared ground, input ratings, and resistor before interpreting an observed event stream. Do not connect a 5 V switch signal to a 3.3 V-only input without checking its limits.
Worked example: an event counter
Imagine a low-voltage button that ideally gives one falling edge when pressed. A possible bouncing sequence is high → low → high → low → high → low, then a stable low. A naive falling-edge counter would record three events from that one press. This sequence is a teaching example, not a measured signature or specified bounce duration. If the application instead samples slowly, it might miss intermediate edges, but relying on chance sampling is not a reliable debounce design. Define what counts as an event: first stable press, first stable release, or both.
Accept a state only after it stays put
One software strategy keeps the last accepted state and notes when the raw input last changed. On each sample, restart a settling timer if raw input changes; accept a new state only after it has remained unchanged for a chosen interval. Then emit a press event only on a stable high-to-low transition. Choose the interval by measuring representative switches and meeting your response-time requirements; there is no universal magic delay. A fixed pause after a first edge can hide some bounce, but may suppress fast intentional actions and does not by itself solve release handling or input noise.
Filter before the digital input when appropriate
An RC network can smooth brief contact changes, but the resulting voltage passes through an intermediate range. Use an input with suitable hysteresis or a Schmitt-trigger stage where the design requires a clean transition, and size the resistor and capacitor against the manufacturer's input thresholds and leakage. A dedicated debouncer or a properly wired changeover-switch latch is another option. A capacitor placed without checking input ratings, startup state, or discharge path is not an automatic cure. Hardware and software can complement one another; neither makes a faulty contact or broken ground safe.
Distinguish bounce from wiring faults
If the input changes repeatedly only around a deliberate press or release, bounce is plausible. If it changes while untouched, verify the bias resistor, ground, and breadboard contacts first. If it never changes, check switch pin orientation and continuity with power off. On safe isolated low-voltage hardware, an appropriately rated scope or logic analyzer can show sampled transitions, but instrument bandwidth and trigger settings matter; a diagram or one capture cannot characterize every switch. Test both pressing and releasing under representative conditions before selecting a debounce policy.
- Confirm defined open and closed voltage levels.
- Record whether extra events occur only near transitions.
- Test the chosen filter for missed intentional presses and false repeat events.
Sources and further reading
Diagrams are simplified teaching illustrations, not measured results or construction plans. See how these guides are prepared.