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.
