An embedded vending machine system built on STM32F103C8T6 microcontroller for selling game skins. The system features LCD display, keypad input, ultrasonic sensor detection, and admin management capabilities.
- Overview
- Features
- Hardware Requirements
- Hardware Demo
- Project Structure
- Getting Started
- Usage
- Authors
- References
This project implements a complete vending machine system designed for selling in-game skins. Built using STM32 HAL libraries, it provides an interactive user interface via I2C LCD display and matrix keypad, with ultrasonic sensor for customer detection. The system includes inventory management, payment processing, and an admin mode for configuration.
- User Interface: 16x2 LCD display with I2C interface
- Input System: 4x4 matrix keypad for user interaction
- Customer Detection: HC-SR04 ultrasonic sensor for presence detection
- Inventory Management: Track quantity and price for multiple items (game skins)
- Payment Processing: Calculate totals and handle payment input
- Admin Mode: Secure access for adjusting inventory and prices
- State Machine Architecture: Robust FSM-based control flow
- Error Handling: Out-of-stock notifications, quantity limits, payment validation
- Microcontroller: STM32F103C8T6 (Blue Pill)
- Display: 16x2 LCD with I2C adapter (PCF8574)
- Input: 4x4 Matrix Keypad
- Sensor: HC-SR04 Ultrasonic Distance Sensor
- Programmer: ST-Link V2 or compatible
- Power Supply: 5V USB or external power
Below are images of the actual hardware setup showing all components connected on a breadboard:
Complete hardware setup with labeled components
Controlling the system via keypad and monitoring output on LCD
The system demonstrates:
- Blue Pill (STM32F103C8T6): Main microcontroller mounted on breadboard
- 16x2 LCD Display: Shows user interface and product information
- 4x4 Matrix Keypad: User input for product selection and payment
- HC-SR04 Ultrasonic Sensor: Customer detection at the bottom
- ST-Link V2: Programming and debugging interface
- Breadboard: Prototyping platform with organized wiring
- Power Supply: 5V adapter for stable operation
The ultrasonic sensor at the bottom detects customer presence and automatically powers on the system when someone approaches the vending machine.
VendingMachine/
โโโ LCD_TEST.ioc # STM32CubeMX project configuration
โโโ STM32F103C8TX_FLASH.ld # Linker script
โโโ .cproject # Eclipse CDT project file
โโโ .mxproject # CubeMX project file
โโโ .project # Eclipse project file
โ
โโโ Core/
โ โโโ Inc/ # Header files
โ โ โโโ main.h # Main header file
โ โ โโโ fsm_vm.h # Finite State Machine definitions
โ โ โโโ store.h # Inventory management
โ โ โโโ ADMIN.h # Admin mode functions
โ โ โโโ keypad.h # Keypad driver
โ โ โโโ sensor.h # Ultrasonic sensor driver
โ โ โโโ tv_lcd_i2c.h # LCD I2C driver
โ โ โโโ i2c.h # I2C peripheral configuration
โ โ โโโ timer.h # Timer utilities
โ โ โโโ stm32f1xx_hal_conf.h # HAL configuration
โ โ โโโ stm32f1xx_it.h # Interrupt handlers
โ โ
โ โโโ Src/ # Source files
โ โ โโโ main.c # Main program entry
โ โ โโโ fsm_vm.c # FSM implementation
โ โ โโโ store.c # Inventory management implementation
โ โ โโโ ADMIN.c # Admin mode implementation
โ โ โโโ keypad.c # Keypad driver implementation
โ โ โโโ sensor.c # Sensor driver implementation
โ โ โโโ tv_lcd_i2c.c # LCD driver implementation
โ โ โโโ i2c.c # I2C peripheral implementation
โ โ โโโ timer.c # Timer implementation
โ โ โโโ stm32f1xx_hal_msp.c # HAL MSP initialization
โ โ โโโ stm32f1xx_it.c # Interrupt service routines
โ โ โโโ system_stm32f1xx.c # System initialization
โ โ โโโ syscalls.c # System call stubs
โ โ โโโ sysmem.c # Memory management
โ โ
โ โโโ Startup/
โ โโโ startup_stm32f103c8tx.s # Startup assembly code
โ
โโโ Drivers/
โ โโโ CMSIS/ # ARM CMSIS libraries
โ โ โโโ Device/ST/ # STM32 device-specific files
โ โ โโโ Include/ # CMSIS core headers
โ โ
โ โโโ STM32F1xx_HAL_Driver/ # STM32F1 HAL drivers
โ โโโ Inc/ # HAL header files
โ โโโ Src/ # HAL source files
โ
โโโ Debug/ # Build output directory
โโโ LCD_TEST.hex.asm # Disassembly output
โโโ LCD_TEST.list # Linker list file
โโโ makefile # Auto-generated makefile
โโโ Core/Src/ # Compiled object files
-
STM32CubeIDE (version 1.10.0 or later)
- Download from: https://www.st.com/en/development-tools/stm32cubeide.html
-
ST-Link Drivers
- Included with STM32CubeIDE or download separately from ST website
git clone <repository-url>
cd VendingMachineMethod 1: Import Existing Project
- Open STM32CubeIDE
- Go to
FileโOpen Projects from File System... - Click
Directoryand select theVendingMachinefolder - Click
Finish
Method 2: Import from .project file
- Open STM32CubeIDE
- Go to
FileโImport... - Select
GeneralโExisting Projects into Workspace - Click
Browseand select theVendingMachinefolder - Check the project name and click
Finish
The project is pre-configured, but you can modify settings via:
- Open
LCD_TEST.iocfile in STM32CubeMX - Adjust pin configurations, peripherals, or clock settings
- Click
Generate Codeif changes are made
- In STM32CubeIDE, right-click on the project
- Select
Build Projector pressCtrl+B - Wait for compilation to complete (check Console for results)
Hardware Connections:
- Connect ST-Link programmer to STM32F103C8T6:
- SWDIO โ SWDIO
- SWCLK โ SWCLK
- GND โ GND
- 3.3V โ 3.3V
Upload Firmware:
- Connect ST-Link to your computer via USB
- In STM32CubeIDE, click
RunโDebugorRunโRun - The firmware will be flashed automatically
- VCC โ 5V
- GND โ GND
- SDA โ PB7 (I2C1_SDA)
- SCL โ PB6 (I2C1_SCL)
- Connect columns and rows to GPIO pins as configured in keypad.h
- VCC โ 5V
- GND โ GND
- TRIG โ GPIO Output Pin
- ECHO โ GPIO Input Pin (Timer Input Capture)
- Idle State: System waits for customer detection via ultrasonic sensor
- Welcome Screen: Displays greeting message when customer is detected
- Product Selection: Use keypad to enter product ID (game skin)
- Quantity Selection: Enter desired quantity
- Payment: System displays total, customer enters payment amount
- Completion: System displays thank you message and dispenses item
- Press admin key combination on keypad (configured in ADMIN.c)
- Enter admin password
- Available options:
- View inventory
- Adjust product quantities
- Update product prices
- Exit admin mode
INIT โ WAIT_SENSOR โ WELCOME_SECTION โ CHOOSING_SKIN โ DISPLAY_INFO
โ CHOOSING_QUANTITY โ PAYMENT_SHOW_TOTAL โ PAYMENT_INPUT โ THANKS
Error states handle: out-of-stock, quantity errors, payment errors, and timeouts.
- Nguyen Hung Thinh - Project Development
- Le The Loc - Project Development
- Tran Doan Hoang Lam - FSM Design & Implementation
Institution: Ho Chi Minh City University of Technology (HCMUT)
Last Updated: December 20, 2025
- STMicroelectronics - HAL Drivers and CMSIS
- STM32CubeMX - Code generation and configuration tool
- ARM CMSIS - Cortex Microcontroller Software Interface Standard
- STM32CubeProgrammer - Firmware flashing tool
- STM32F103C8T6 Microcontroller (Blue Pill)
- HC-SR04 Ultrasonic Sensor Module
- PCF8574 I2C LCD Adapter
- 16x2 Character LCD Display
- 4x4 Matrix Keypad
This project is part of an academic assignment at Ho Chi Minh City University of Technology.
