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.

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.

LessonTimeWhat students do
A keypad to choose withStart 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
  1. Sixteen keys, eight wires
  2. Press a key
  3. A letter and a number
  4. One key, once
A screen for pricesAdd a 16x2 LCD on an I2C backpack, so the machine can show prices, credit and messages with only two signal wires.50 min
  1. Two wires for a whole screen
  2. Run it
  3. Keys on the screen
  4. 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.

LessonTimeWhat students do
Coins, bills and creditAdd a coin switch and a bill switch, count credit in whole cents, and give a refund on the star key.50 min
  1. Stand-ins for a coin mech
  2. Drop in a quarter
  3. Money in cents
  4. Changed my mind
The first spiralTurn slot A1 with a continuous servo: pay, choose, and the spiral turns once and pushes the item off the end.50 min
  1. A servo that keeps turning
  2. Pay for A1
  3. Choose A1
  4. Change, and a doubt
Did it really dropAdd 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
  1. Snacks get stuck
  2. A sale that works
  3. A sale that sticks
  4. 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.

LessonTimeWhat students do
Four slots and service modeFinish the machine with four spirals, a speaker, sold out counts, change for every price, and a code that opens service mode.50 min
  1. Three more spirals and a speaker
  2. Buy a B1 with change
  3. Service mode
  4. 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.