Source: https://mokxi.com/teachers/plans/inputs-in-depth
Updated: 2026-11-19

Lesson plan

# Buttons, encoders, keypads and touch lesson plan

Read people properly: button bounce on a scope and debouncing, clicks, double clicks and long presses, rotary encoders, matrix keypads, MPR121 touch and joysticks, then a retro game menu with a high score entry screen.

4 chapters, 7 lessons, about 6 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## Objectives and materials

### By the end, students can

- Bounce, debounce, and gestures from one button.
- Rotary encoders and matrix keypads.
- Capacitive pads and analog joysticks.
- A retro game menu with a high score entry screen.

### Materials for the whole unit

- Arduino Uno R3
- Capacitive touch, MPR121
- Character LCD with I2C backpack
- Full-size breadboard
- Half breadboard
- Keypad, 4x4
- LED x 8
- Oscilloscope
- Piezo speaker
- Pushbutton
- Relay module
- Resistor x 8
- RGB LED
- Rotary encoder, KY-040
- Thumb stick

Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.

Chapter 1. About 1 h 40 min

## Buttons

Bounce, debounce, and gestures from one button.

Lesson | Time | What students do

Bounce on the scope, and debounce One press, many edges: a scope on a bouncing pushbutton, an interrupt that counts every edge, and a debounce that waits for the contacts to settle before believing them. | 50 min

- Run it: count the edges
- See it on the scope
- Worse buttons
- Debounce in code
- Turn the debounce off
- Choosing a debounce

Long press and double click Three gestures from one button: a state machine that waits a moment to tell a click from a double click, and reports a long press while the button is still held. | 50 min

- Run it: one button, three gestures
- Why the click is late
- Hold it
- A state machine
- A quicker hold
- Gestures in real devices

### Materials

- Arduino Uno R3
- Half breadboard
- Oscilloscope
- Pushbutton

### Check for understanding

Each student finishes "Long press and double click" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Gestures in real devices".

Chapter 2. About 1 h 40 min

## Knobs and keys

Rotary encoders and matrix keypads.

Lesson | Time | What students do

Rotary encoders A knob that never ends: two contacts a quarter cycle apart, a state table that turns them into steps and a direction, interrupts so no step is missed, and bounce that the table shrugs off. | 50 min

- Run it: turn the knob
- Two square waves
- Bounce, shrugged off
- Interrupts catch every step
- The push switch
- Coarser steps

Matrix keypads Sixteen keys on eight pins: scanning rows and columns, pressed, held and released events from the Keypad library, two keys at once, and a door code typed into a buffer. | 50 min

- Run it: a door keypad
- Scanning
- Events: pressed, held, released
- Two keys at once
- Your own code
- Keypads in real devices

### Materials

- Arduino Uno R3
- Full-size breadboard
- Half breadboard
- Keypad, 4x4
- LED
- Relay module
- Resistor x 4
- RGB LED
- Rotary encoder, KY-040

### Check for understanding

Each student finishes "Matrix keypads" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Keypads in real devices".

Chapter 3. About 1 h 40 min

## Touch and sticks

Capacitive pads and analog joysticks.

Lesson | Time | What students do

MPR121 capacitive touch Twelve touch pads on one I2C chip: capacitance that drops when a finger comes near, a baseline that tracks it, thresholds that decide a touch, and a note for each pad. | 50 min

- Run it: touch pads
- A finger changes the capacitance
- A bitmask
- Released
- Less sensitive
- Touch in real devices

Joysticks Two potentiometers and a button that should feel right: centering at start-up, a dead zone, -100 to 100 per axis, direction events that repeat while held, and a fire button. | 50 min

- Run it: calibrate the middle
- A dead zone
- Push it right
- Fire
- A bigger dead zone
- Sticks in real devices

### Materials

- Arduino Uno R3
- Capacitive touch, MPR121
- Full-size breadboard
- Half breadboard
- LED x 8
- Piezo speaker
- Resistor x 8
- Thumb stick

### Check for understanding

Each student finishes "Joysticks" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Sticks in real devices".

Chapter 4. About 1 h

## Project

A retro game menu with a high score entry screen.

Lesson | Time | What students do

Project: a retro game menu A Star Blaster arcade menu on a 16x2 LCD and a rotary encoder: scroll and press, a sound toggle, a high score table in EEPROM, and initials dialed in letter by letter. | 60 min

- Run it: Star Blaster
- Scroll
- The high score table
- Play
- Dial your initials
- A better game
- Make it your menu

### Materials

- Arduino Uno R3
- Character LCD with I2C backpack
- Half breadboard
- LED
- Resistor
- Rotary encoder, KY-040

### Check for understanding

Each student finishes "Project: a retro game menu" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it your menu".

Your class

## Teach this unit as a class

Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.

The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
