An embedded machine learning proof-of-concept deploying a quantized neural network onto an STM32 NUCLEO F401RE microcontroller for real-time motor anomaly detection.
This project bridges hardware and machine learning by analyzing high-frequency mechanical vibrations to detect physical imbalances before catastrophic failure occurs, a core concept in industrial Predictive Maintenance (PdM).
- Microcontroller: STM32 Nucleo-64 (ARM Cortex-M core)
- Motor Driver: L298N Dual H-Bridge (interfacing the MCU logic with the high-current DC motor)
- Sensors: External vibration/motion sensor - MPU6050
- Communication: UART Serial Communication configured for high-throughput data streaming (460800 Baud Rate).
- Development Environment: STM32CubeIDE (C/C++)
- AI Middleware: Nano Edge AI Studio for converting and deploying the quantized neural network to the MCU.
- Model Architecture: Binary classifier trained on nominal and imbalanced mechanical states.
The model continuously evaluates real-time sensor telemetry against two established classifications:
- Class 1 (Nominal): High-frequency vibration of a balanced, healthy motor.
- Class 2 (Anomaly): Mechanical imbalance characterized by violent, out-of-distribution physical harmonics.
Note: The model strictly evaluates these two states. Out-of-distribution handling noise (e.g., manual sensor movement) may default to Class 1 due to low-frequency features failing to cross the Class 2 mathematical threshold.
Deploying AI on resource-constrained microcontrollers requires strict memory management.
- Memory Optimization: Floating-point operations for
printfvianewlib-nanowere explicitly bypassed. Instead of processing float arrays for classification probabilities, the output logic was streamlined into lightweight string literal transmission. - Performance: This prevented heap/stack overflow and reduced the binary footprint, ensuring the real-time inference loop executed without bottlenecking the 460800 baud UART transmission.
To train and validate the Edge AI model, a physical test rig was constructed:
- Sensor Coupling & Signal Integrity: The vibration sensor was mechanically coupled directly to the motor chassis using high-density foam mounting tape.
- Strict care was taken to compress the mounting interface and eliminate all air cavities, preventing signal attenuation and ensuring the high-fidelity transfer of physical motor harmonics to the sensor.
- Inducing the Anomaly: The "Imbalance" state (Class 2) was synthetically generated by attaching an asymmetric mass to the motor shaft, simulating a degraded rotor or damaged bearing in an industrial setting.
- Clone this repository to your local machine.
- Import the
.cproject/.projectfiles into an STM32CubeIDE workspace. - Ensure the target STM32 Nucleo board is connected.
- Build the project and flash the binary to the MCU.
- Open a serial monitor (e.g., TeraTerm, PuTTY) configured to 460800 baud.
- Observe the real-time terminal output classifying the physical motor state.