This project implements a real-time predictive maintenance system on STM32 microcontrollers using Zephyr RTOS and TensorFlow Lite for Microcontrollers. The system collects sensor data, performs on-device anomaly detection, and enables early equipment failure prediction to minimize unplanned downtime.
🏭 Factory Method Pattern for modular creation of machines and sensors
⏱ Real-time data logging on STM32 with Zephyr RTOS
🔍 On-device anomaly detection using TensorFlow Lite for Microcontrollers
⚡ Early failure prediction to reduce unplanned downtime
⚙️ Machine-Sensor Configuration
Each industrial machine is equipped with specific sensors for predictive maintenance:
1️⃣ AIR_COMPRESSOR
📊 Temperature: 60-100°C
• 📏 Pressure: 72-145 psi
• 📳 Vibration: 0.5-2.0 mm/s
Monitors overheating, pressure fluctuations, and mechanical wear
2️⃣ STEAM_BOILER
📊 Temperature: 150-250°C
• 📏 Pressure: 87-360 psi
Tracks thermal efficiency and safety thresholds
3️⃣ ELECTRIC_MOTOR
📊 Temperature: 60-105°C
Winding insulation safety range
🧩 Factory Structure
┌────────────────────┐
│ SensorFactory │ ← Abstract Creator
└────────────────────┘
▲
│
┌─────────────────┴─────────────────┐
│ │
┌─────────────────┐ ┌──────────────────┐
│ createSensor() │ │ Machine Creation │
└─────────────────┘ └──────────────────┘
Creates sensor objects Uses factory to build
(Temp, Pressure, Vibration) complete machines
💡Usage Example
// Create a machine by providing the name and TYPE
MachineHandle handle = create_machine("Compressor1", AIR_COMPRESSOR);
// Set and read sensor values
set_sensor_value(handle, "Temperature", 42.5f);
float temp = get_sensor_value(handle, "Temperature");
// Clean up
destroy_machine(handle);
[📡 Sensors] → [💻 STM32 (Zephyr RTOS)] → [🧠 TensorFlow Lite] → [⚠️ Anomaly Detection] → [📊 Logging/DFU]
⎔ VS Code - Primary IDE for STM32 firmware development
• Extensions: Cortex-Debug, Zephyr IDE, CMake Tools
⎔ Zephyr RTOS - Real-time operating system for resource-constrained devices
⎔ Tensflow Lite for MCUs - On-device ML inference (quantized models)
⎔ CMake - Build system for Zephyr projects
⎔ dfu-utils - Firmware updates via USB DFU protocol
📁 Data-Logger-Predictive-Maintenance/
│── 📁 src/ (Core application source)
│ ├── 📄 main.c (Zephyr application entry point)
│ ├── 📄 sensor.cpp / .h (Sensor base class + implementations)
│ ├── 📄 sensor_wrapper.cpp / .h (C-compatible sensor interface)
│ ├── 📄 tflite_wrapper.cpp / .h (TensorFlow Lite inference interface)
│ ├── 📄 autoencoder_model.cc / .h (Embedded ML model definition)
│── 📁 CMakeLists.txt/ (Build system configuration)
│── 📁 prj.conf/ (Zephyr kernel config)
│── 📁 sample.yaml/
│── 📁 tflite-micro/
│ ├── 📄 tensorflow/
│ │ ├── 📄 lite (TensorFlow Lite for Microcontrollers)
│── 📁 data/
│ ├── 📄 simulated_data.py (Sensor data simulator)
│ ├── 📄 simulated_data.zip (Compressed simulated sensor data)
│ ├── 📄 autoencoder.tflite (Quantized TF Lite model)
│ ├── 📄 simulated_data
│ │ ├── 📄 machine_1 (Machine type 1: Air Compressor)
│ │ │ ├── 📄 machine_1_temp.csv (Temp sensor values)
│ │ │ ├── 📄 machine_1_pressure.csv (Pressure sensor values)
│ │ │ ├── 📄 machine_1_vibration.csv (Vibration sensor values)
│ │ ├── 📄 machine_2 (Machine type 2: Steam Boiler)
│ │ │ ├── 📄 machine_2_temp.csv (Temp sensor values)
│ │ │ ├── 📄 machine_2_pressure.csv (Pressure sensor values)
│ │ ├── 📄 machine_3 (Machine type 3: Electric Motor)
│ │ │ ├── 📄 machine_3_temp.csv (Temp sensor values)
│── 📄 README.md (Documentation)