Elevator Control System using STM32 MCU
Published:
🤖 AI Disclosure: For transparency, the content of this page was partially or mainly created with AI assistance tools.
From Model to Metal: MBD for Embedded Control
Model-Based Design is the standard for safety-critical embedded systems — the idea that a validated simulation model should be the authoritative source for deployed firmware, not a parallel artifact. This project applied that methodology end-to-end: designing a three-floor elevator control system in MATLAB /Simulink , generating production C++ from the model using Embedded Coder , and deploying directly to an STM32 microcontroller .
The result is a system where the model and the hardware share the same logic by construction, and where validation at the model level directly transfers to confidence in the deployed system.
System Design
Control Logic in Simulink
- The elevator serves three floors, each equipped with up and down call buttons plus floor sensors. The <a href=”/skills/?tag=Simulink”
- class=”cv-skill-tag”
- data-skill=”Simulink”>Simulink</a>
- model captures the full <a href=”/skills/?tag=state+machine”
- class=”cv-skill-tag”
- data-skill=”state machine”>state machine</a>
- idle, moving up, moving down, door open/close sequences, and priority queuing for simultaneous call requests.
Signal interfaces were configured in STM32CubeMX , defining the GPIO mappings for buttons and floor sensors before importing them as driver blocks into Simulink . This keeps the hardware abstraction layer clean and the model portable.
Code Generation via Embedded Coder
With the model validated at the simulation level, Embedded Coder generated optimized C++ directly from the Simulink diagram. The generated code is structured, readable, and traceable back to specific model blocks — a key property for any system where you need to explain a behavior or trace a fault.
The generated code was compiled and flashed to the STM32 using Keil μVision .
Validation: MIL and HIL
Model-in-the-Loop (MIL)
MIL testing ran the control logic entirely within Simulink , using validation blocks to simulate button presses, floor arrivals, and edge cases (simultaneous calls, direction changes mid-travel). Passing MIL establishes that the model logic is correct before any hardware is involved.
Hardware-in-the-Loop (HIL)
HIL testing connected the deployed STM32 back into the Simulink environment — the microcontroller runs its generated code while Simulink simulates the physical elevator plant. This catches timing issues, interrupt latency, and hardware-specific behavior that MIL cannot surface. Manual testing on the physical rig provided the final validation layer.
Outcome
- Designed a complete elevator control state machine in MATLAB/Simulink, handling multi-floor call queuing, priority resolution, and door sequencing.
- Configured STM32CubeMX signal interfaces and integrated them as Simulink driver blocks, maintaining a clean hardware abstraction.
- Generated production C++ from the validated model using Embedded Coder; compiled and deployed to STM32 via Keil μVision.
- Validated correctness through the full MBD testing stack: MIL simulation, HIL with physical MCU, and manual functional testing on the rig.
Demo video: youtu.be/rMcJRmVd3Ds
