XiaoZhi AI + MCP Protocol + STM32: A Practical Voice-Controlled Smart Home Solution

XiaoZhi AI controls STM32 hardware devices via MCP protocol using voice commands
This project connects the XiaoZhi AI assistant to STM32 microcontrollers via MCP protocol, enabling users to control lights, fans, humidifiers, and stepper motors through natural language. The system uses a dual-STM32 architecture with one board handling AI instruction parsing and the other managing peripheral control, balancing real-time performance with stability. The project validates the feasibility of LLMs controlling physical hardware through standardized tool interfaces, providing a reproducible technical reference for AI+IoT integration.
Project Overview: XiaoZhi AI Dialogue-Controlled STM32 Hardware
Recently, a project on Bilibili that combines the XiaoZhi AI assistant with STM32 microcontrollers has attracted considerable attention. Using the MCP (Model Context Protocol), it builds a communication bridge between AI large language models and embedded hardware — users can control lights, fans, humidifiers, and stepper motors simply by speaking a natural language command. This is more than a technical demonstration; it showcases a real-world implementation path for AI+IoT integration.
From the demo video, the entire interaction process is remarkably smooth: when users tell XiaoZhi to "turn on the light" or "turn on the fan," the corresponding devices respond immediately; when they say "motor up," the stepper motor precisely executes the lifting action. This approach — combining a large language model's semantic understanding with STM32's precise control capabilities — provides an invaluable technical reference for DIY smart home projects.
Core Technical Architecture: How MCP Protocol Connects AI to Hardware
What is the MCP Protocol
MCP (Model Context Protocol) is an open protocol proposed by Anthropic in late 2024, providing large language models with a standardized tool-calling interface. In plain terms, MCP enables AI models to "take action" — not just generate text responses, but also invoke external tools and control hardware devices. In this project, the MCP protocol serves as the "translator" between XiaoZhi AI and STM32.
To understand MCP's value, you first need to understand the core problem it solves. Before MCP, every AI application that needed to interface with external tools required developers to write custom integration code for specific models, leading to a serious "M×N problem" — M AI models interfacing with N tools required M×N adaptation solutions. MCP simplifies this to "M+N" by defining a unified protocol specification: each model only needs to implement an MCP client once, and each tool only needs to implement an MCP server once, enabling arbitrary combinations. MCP's architecture consists of three layers: the Host (the host application, such as the XiaoZhi AI client) manages user interaction; the Client maintains a one-to-one connection with the server; and the Server exposes specific tool capabilities. In this project, STM32's control interfaces are encapsulated as tools provided by the MCP Server, and the AI model triggers hardware operations through standardized JSON-RPC calls. Currently, the MCP protocol has gained support from major AI vendors including OpenAI and Google DeepMind, and is becoming the de facto standard for AI tool invocation.
The workflow is as follows: after a user issues a voice command, XiaoZhi AI first understands the user's intent, then converts the command into structured control instructions via the MCP protocol, sends them to the STM32 main controller via serial communication, and finally the STM32 drives the corresponding peripherals to execute the action.
STM32 Dual-MCU Communication Architecture Design
The project employs a two-STM32 cooperative architecture — a noteworthy design choice. One board handles communication with the host machine (the device running XiaoZhi AI) and parses MCP instructions, while the other focuses on peripheral control and stepper motor driving.
STM32 is a series of 32-bit microcontrollers based on ARM Cortex-M cores, developed by STMicroelectronics. Since its launch in 2007, it has become one of the world's highest-shipping 32-bit MCU platforms, with cumulative shipments exceeding tens of billions of units. Compared to rapid-prototyping platforms like Arduino, STM32 offers significant advantages in performance, peripheral richness, and power consumption control: clock speeds range from 48MHz to 480MHz, with built-in hardware peripherals including rich timers, ADCs, and DMA controllers, capable of handling everything from simple GPIO control to complex real-time signal processing. It's precisely this "high performance ceiling, low cost floor" characteristic that makes STM32 the go-to chip for IoT projects and industrial control. In this project, using two STM32 boards rather than a single-chip solution fully leverages hardware timer resources to ensure precise stepper motor control.
This division-of-labor architecture offers several clear advantages:
- Real-time guarantees: Stepper motor pulse control has extremely strict timing requirements; a dedicated control chip avoids interference from communication tasks
- System stability: Even if the communication module encounters anomalies, the control end can maintain safe device states
- Strong scalability: When adding more peripherals later, only the control end needs expansion without affecting the communication architecture
Communication between the two STM32 boards typically uses UART (Universal Asynchronous Receiver/Transmitter) serial protocol. UART is one of the most fundamental and reliable communication methods in embedded systems, achieving full-duplex communication through TX (transmit) and RX (receive) signal lines without requiring a clock synchronization signal. In dual-MCU communication scenarios, developers typically design custom protocol frames: a fixed frame header (e.g., 0xAA 0x55) identifies the start of a data packet, followed by command bytes, data length, payload, and checksum bytes (e.g., CRC), with a frame tail marking the end. This design effectively handles data misalignment and noise interference in serial communication. Compared to synchronous protocols like SPI and I2C, UART's advantages include simpler wiring, stronger noise immunity, and longer communication distances, making it ideal for board-to-board communication. In this project, after MCP instructions are parsed, the communication board packages structured commands into serial data frames according to the custom protocol and sends them to the control board for execution.

Voice Control Testing: From Turning On Lights to Motor Elevation
Device Activation: Lighting Up the Whole House with One Sentence
From the demonstration, users sequentially issue commands like "turn on the light," "turn on the fan," "turn on the humidifier," and "motor up." XiaoZhi AI not only accurately recognizes each command but also provides natural voice feedback: "I've turned on the lights, fan, and humidifier for you. The motor has also started rising. Everything is ready — just let me know what's next."

Notably, the AI assistant proactively summarizes the status after completing a set of operations and waits for the next instruction — an interaction experience far superior to the traditional one-by-one confirmation model. Traditional smart home systems typically use keyword matching or intent slot-filling to parse user commands, processing and confirming each command independently without contextual awareness. In contrast, large language model-driven interaction naturally possesses multi-turn dialogue understanding and state aggregation capabilities, able to interpret multiple consecutive commands as a single complete operational intent and provide a unified status report after all executions are complete. This is the core value of AI-empowered IoT interaction experiences.
Device Deactivation: Precise Voice Command Response
The shutdown process is equally smooth. When users say "turn off the light," "turn off the fan," "turn off the humidifier," and "motor down," all devices respond in sequence. XiaoZhi replies: "I've turned off the lights, fan, and humidifier for you. The motor has also started descending. Everything is quiet now — need me to do anything else?"

Finally, when the user says "Okay, thanks, you're dismissed," XiaoZhi politely replies "Goodbye." The entire interaction process is natural and fluid, with virtually no perceptible latency.

Deep Dive into Technical Highlights
Why Precise Stepper Motor Control is Challenging
Among all controlled peripherals, the stepper motor presents the highest control difficulty. Unlike simple on/off control (toggling lights, fans, and humidifiers), stepper motors require precise pulse signals to control speed and displacement. The project implements control in two directions — "up" and "down" — meaning the STM32 end needs to handle direction signals, pulse frequency, acceleration/deceleration curves, and multiple other parameters.
A stepper motor works by converting electrical pulse signals into precise angular displacement — for each pulse received, the motor rotor rotates by a fixed angle (called the "step angle," commonly 1.8°, meaning 200 pulses per revolution). The key to speed control lies in pulse frequency: higher frequency means faster speed. However, stepper motors cannot instantaneously accelerate from standstill to high speed; otherwise, "step loss" occurs (the motor can't keep up with the pulse rhythm, causing position loss). Therefore, practical control must incorporate acceleration/deceleration curves: common trapezoidal curves linearly change pulse frequency during startup and shutdown phases, while smoother S-curve profiles further reduce mechanical vibration and noise. Additionally, modern stepper motor drivers widely support microstepping technology, subdividing one full step angle into multiple microsteps (e.g., 16x, 32x subdivision), dramatically improving positioning accuracy and operational smoothness without changing the motor. These control algorithms require STM32's hardware timers to output pulse signals with microsecond-level precision — this is the fundamental reason the project uses a dedicated MCU specifically for motor control. Any interrupt delay from communication tasks could disrupt pulse timing and cause step loss.
The ability to achieve stepper motor direction control through natural language demonstrates that the MCP protocol's instruction parsing layer features well-designed abstraction — mapping users' vague semantics ("up") to precise hardware control parameters.
MCP Protocol's Application Prospects in the Embedded Domain
The MCP protocol was originally designed primarily for software tool invocation scenarios (such as file operations, database queries, etc.), but this project extends it into the embedded hardware control domain — a forward-looking experiment. It validates a key insight: large language models don't need to "understand" low-level hardware protocols; they only need standardized tool interface descriptions to achieve control over the physical world.
The value of this paradigm is that, in the future, any embedded developer can integrate their hardware devices into the AI ecosystem by writing MCP tool description files, without needing deep knowledge of LLM internals. Specifically, MCP tool description files use JSON Schema format to define each tool's name, functional description, input parameters, and return values. For example, a light control tool might be described as: tool name "control_light," with parameters including "action" (values: on/off) and "brightness" (integer 0-100). After receiving a user command, the LLM automatically selects the appropriate tool and fills in parameters based on these descriptions — the entire process requires no model knowledge of GPIO level toggling or PWM duty cycles. This "decoupling of semantic layer from control layer" design philosophy aligns with the interface abstraction principles in software engineering, dramatically lowering the technical barrier to AI-hardware integration.
Developer Practice Guide: AI+IoT Entry Path
This project provides developers interested in AI+IoT with a clear learning path:
- Protocol Layer: Learn the MCP protocol specification; understand tool definition and invocation mechanisms
- Communication Layer: Master serial communication (UART) and custom protocol design
- Control Layer: Become familiar with STM32 peripheral driver development including GPIO, timers, and PWM
- Integration Layer: Connect AI voice interaction with hardware control; handle exceptions and status feedback
From an industry trend perspective, the convergence of AI and IoT (AIoT) is entering an accelerated development phase. Multiple market research firms predict the global AIoT market will exceed $100 billion by 2028. In the smart home domain, the CSA Alliance's Matter protocol is unifying interoperability standards between different brand devices, while large language models provide these devices with unprecedented natural language interaction capabilities. Meanwhile, rapid advances in edge AI inference technology (such as the proliferation of NPU chips and maturation of model quantization techniques) are pushing AI inference capabilities from the cloud down to local devices. This means future AI+IoT systems may no longer depend on cloud-based LLMs, instead completing semantic understanding and decision-making locally for lower latency and better privacy protection. While this project currently relies on cloud AI services, its clear architectural separation of "protocol layer - communication layer - control layer" leaves ample room for future migration to edge AI solutions.
As the MCP protocol ecosystem continues to mature and open-source AI assistant projects flourish, the barrier to entry for such "AI-driven hardware" projects will continue to decrease. It's foreseeable that in the near future, controlling all smart devices in your home with natural language will no longer be science fiction, but a weekend project achievable by any embedded enthusiast.
Key Takeaways
- The project connects XiaoZhi AI assistant to STM32 microcontrollers via MCP protocol, enabling natural language control of lights, fans, humidifiers, and stepper motors
- A dual-STM32 communication architecture is employed, with one board handling AI instruction parsing and the other focusing on peripheral control, balancing real-time performance with stability
- Stepper motor direction control (up/down) demonstrates MCP protocol's ability to map vague semantics to precise hardware parameters
- MCP protocol's extension from software tool invocation to embedded hardware control proves that LLMs can manipulate the physical world through standardized interfaces
- The project provides a reproducible technical pathway for AI+IoT integration, lowering the development barrier for DIY smart home projects
Related articles
TutorialsChatGPT Plus Subscription Guide: Are GPT-5.5, image-2, and Codex Worth the Upgrade?
A detailed look at ChatGPT Plus features — GPT-5.5, image-2, and Codex — with a Plus vs Pro comparison and a complete step-by-step subscription guide for users outside the US.
TutorialsHarness AI Engineering in Practice: Using Claude Code to Master Enterprise-Level E-Commerce Development
Deep dive into Harness AI Engineering: master enterprise e-commerce development with Claude Code using the Rules, Skills, Wiki, and Changes framework.
TutorialsCursor + Codex Dual-IDE Collaboration: A Practical Methodology for Open-Source Project Customization
A complete methodology for open-source project customization based on real-world experience, detailing the Cursor+Codex dual-IDE workflow, seven-stage process, MVP validation, and AI source code reading techniques.