PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Projects

Vending machine

HardBudget $25Python · gpiozero

A snack machine. The keypad: rows R1–R4 on GPIO5, 6, 13, 19, columns C1–C4 on GPIO12, 16, 20, 21 (layout 123A / 456B / 789C / *0#D). A coin button on GPIO26 (each press is a 50¢ coin), a servo flap on GPIO18 (5 V; 0.5 ms = 0°, 2.4 ms = 180°; 0° closed, 90° open) and a 16×2 LCD (I²C 0x27).

Snacks: key A costs $1.00, B $1.50, C $2.00.

  • Line 1 always shows the credit: Credit: $1.50.
  • A/B/C with enough credit: take the price off the credit, show Enjoy! on line 2, open the flap for 1 s, then close it.
  • A/B/C without enough credit: line 2 shows how much is missing, Need $1.00 more, and nothing is sold.
  • # gives the credit back: credit becomes $0.00 and line 2 shows Refund $0.50 (the amount returned).
  • A coin clears line 2.

The test drops a coin at 1.0 s and presses B at 1.6 s; drops coins at 2.5 and 3.0 s and presses B at 3.6 s; drops a coin at 6.0 s and presses # at 6.6 s.

More in Projects