Session 14: Buttons, bounce and edges
Learning outcomes
- Explain floating inputs and use INPUT_PULLUP
- Capture and measure contact bounce on the oscilloscope
- Debounce a button with millis() so one press counts once
- Act on the press edge and report changes on Serial without flooding
Kit and components
- Uno, push button, breadboard, jumpers
- Oscilloscope
Pre-reading about 25 min
Students read these on their phones before class. They are listed on the student Before class page.
Session plan
- 0:0010 minRecap
Quiz: outputs and tone()
- 0:1015 minDemo
A floating input
Set D2 to plain INPUT with a loose wire and print it quickly: the reading follows your hand. Switch to INPUT_PULLUP and it settles.
- 0:2530 minMeasure
Capture the bounce
Students set a single-shot falling-edge trigger at 500 µs/div and capture ten presses and releases, record the longest bounce and choose a debounce time at least double it.
- 0:5520 minBuild
Debounced press counter
Students upload the worked sketch with their own debounce time, then test 20 rapid presses and a held button.
- 1:1535 minCode Along
Buttons and debounce
- 1:5010 minWrap-up
Level versus edge
Checkpoint: ready to move on?
Students have a measured bounce time in their logbook, and their counter gives exactly 20 counts for 20 presses with nothing printed while the button is held.
Extension for fast finishers
Short press or long press (lesson challenge).
- Code Along 7.5: Short press or long press?DeeperLaptop
Catch-up path
Draw level and edge detection on a timing diagram before coding.
Homework and practice
Code Along 7.3 and 7.4.
Facilitator notes
- Show the single-shot trigger on your class scope model before students try it.
- Some tactile buttons barely bounce. If a student sees none, tap a jumper wire against GND instead.