Week 3 · Functions, Outputs & Buttons

Session 14: Buttons, bounce and edges

Teach & build120 minLesson 10: Digital Inputs, Pull-Ups & Debouncing

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.

  1. Lesson 10: Floating inputs
  2. Lesson 10: Contact bounce
  3. Lesson 10: Edge detection
  4. Theory Reference: Edge detection

Session plan

  1. 0:0010 min
    Recap

    Quiz: outputs and tone()

  2. 0:1015 min
    Demo

    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.

  3. 0:2530 min
    Measure

    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.

  4. 0:5520 min
    Build

    Debounced press counter

    Students upload the worked sketch with their own debounce time, then test 20 rapid presses and a held button.

  5. 1:1535 min
  6. 1:5010 min
    Wrap-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).

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.