When a mechanical switch or button changes state, its metal contacts physically bounce, making and breaking contact several times over roughly 1-20 ms before settling. If you sample the input pin once at the moment of a press, you can register multiple transitions for a single physical press, causing double-counts or spurious events. Debouncing filters this out. In software the common approaches: sample periodically and only accept a new state after it's been stable for N consecutive reads (or N milliseconds), often structured as a small finite state machine (stable → maybe-changed → confirmed); or take a reading, then ignore further changes for a lockout window. Hardware debouncing uses an RC filter and/or a Schmitt-trigger input, or an SR latch for a SPDT switch. The software FSM approach is most common on MCUs because it costs nothing extra and is tunable. The key point is that a raw IDR read is not a reliable press detector for a mechanical contact, you must filter the bounce.
Embedded Systems Fundamentals · Interview question
What is switch bounce and how do you handle it?
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
GPIO: Digital I/O
Reading buttons and driving LEDs: configuring a pin's direction, push-pull vs open-drain outputs, pull-up/down inputs, and why a floating input reads noise.