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:2510 min
    Demo

    Bounce on the scope

    On the projector, set a single-shot falling-edge trigger at 500 µs/div and capture a few presses and releases so everyone sees what bounce looks like and how to read its length.

  4. 0:3520 min
    Measure

    Capture the bounce

    Students capture three presses or releases with the same trigger settings, record the longest bounce and choose a debounce time at least double it.

  5. 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.

  6. 1:1535 min
    Code Along

    Buttons and debounce

    Debounce the button is also set as homework, so it is fine to finish it after class.

  7. 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.