Source: https://mokxi.com/teachers/plans/build-vending-machine
Updated: 2026-11-11

Lesson plan

# Build a vending machine lesson plan

Build a real vending machine piece by piece: a keypad, a screen, coins and change, spirals, a drop sensor and service mode.

3 chapters, 6 lessons, about 5 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

- A keypad to choose with and a screen that talks back.
- Take money, turn a spiral, and make sure the item really fell.
- Four slots, stock counts, change for every price and a service code.

### Materials for the whole unit

- Arduino Uno R3
- Character LCD with I2C backpack
- Full-size breadboard
- Keypad, 4x4
- Limit switch, lever microswitch x 2
- Piezo speaker
- Vending machine cabinet

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

## The front panel

A keypad to choose with and a screen that talks back.

Lesson | Time | What students do

A keypad to choose with Start the vending machine with a 4x4 keypad: sixteen keys on eight pins, read by scanning rows and columns, and a selection like B2. | 50 min

- Sixteen keys, eight wires
- Press a key
- A letter and a number
- One key, once

A screen for prices Add a 16x2 LCD on an I2C backpack, so the machine can show prices, credit and messages with only two signal wires. | 50 min

- Two wires for a whole screen
- Run it
- Keys on the screen
- Clear, then print

### Materials

- Arduino Uno R3
- Character LCD with I2C backpack
- Full-size breadboard
- Keypad, 4x4

### Check for understanding

Each student finishes "A screen for prices" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Clear, then print".

Chapter 2. About 2 h 30 min

## Selling

Take money, turn a spiral, and make sure the item really fell.

Lesson | Time | What students do

Coins, bills and credit Add a coin switch and a bill switch, count credit in whole cents, and give a refund on the star key. | 50 min

- Stand-ins for a coin mech
- Drop in a quarter
- Money in cents
- Changed my mind

The first spiral Turn slot A1 with a continuous servo: pay, choose, and the spiral turns once and pushes the item off the end. | 50 min

- A servo that keeps turning
- Pay for A1
- Choose A1
- Change, and a doubt

Did it really drop Add an infrared beam across the bin, so the machine only takes your money when it sees the item fall, and tries again when it does not. | 50 min

- Snacks get stuck
- A sale that works
- A sale that sticks
- Measure the outcome

### Materials

- Arduino Uno R3
- Character LCD with I2C backpack
- Full-size breadboard
- Keypad, 4x4
- Limit switch, lever microswitch x 2
- Vending machine cabinet

### Check for understanding

Each student finishes "Did it really drop" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

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

Chapter 3. About 50 min

## The finished machine

Four slots, stock counts, change for every price and a service code.

Lesson | Time | What students do

Four slots and service mode Finish the machine with four spirals, a speaker, sold out counts, change for every price, and a code that opens service mode. | 50 min

- Three more spirals and a speaker
- Buy a B1 with change
- Service mode
- Your machine

### Materials

- Arduino Uno R3
- Character LCD with I2C backpack
- Full-size breadboard
- Keypad, 4x4
- Limit switch, lever microswitch x 2
- Piezo speaker
- Vending machine cabinet

### Check for understanding

Each student finishes "Four slots and service mode" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

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

Your class

## Teach this unit as a class

Start a class from this course and its 6 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.
