1. System Architecture Pipeline
How an ARM Cortex-M4 microcontroller turns raw mechanical motor shaking into actionable predictive maintenance alerts.
High-Speed 3-Axis Vibration Capture
The rigidly mounted ADXL345 streams X, Y, and Z acceleration at 1600 Hz over high-speed SPI1, capturing both low-frequency rotor wobble and high-frequency bearing impacts.
On-Chip FFT & DSP (Cortex-M4 FPU)
The 180 MHz STM32F446RE uses its hardware Floating-Point Unit and CMSIS-DSP instructions to compute RMS velocity (ISO 10816) and 0–800 Hz FFT frequency signatures in milliseconds.
Unsupervised Anomaly AI
Using NanoEdge AI Studio, press the blue B1 button (PC13) to learn the motor's healthy baseline on-device—then continuously compute a 0–100% Similarity & Health Score.
Local OLED/Tower Alert & Wi-Fi MQTT
Displays live Health Score on the SSD1306 OLED, switches the 3-color industrial stack LEDs + buzzer, and sends compact JSON fault packets via ESP-01S USART1 to a factory dashboard.
2. Interactive Real Wiring Schematic (STM32 Nucleo-F446RE)
Toggle any subsystem below to trace SPI1, dedicated I2C1 (D14/D15), USART1 Wi-Fi, industrial stack LEDs, and power rails.
Hardware Safety & Pinout Caution (Important for STM32 Nucleo-F446RE)
- The Nucleo-F446RE A4/A5 I2C Trap: Unlike an Arduino UNO, the STM32 Nucleo-F446RE does NOT route hardware I2C1 to
A4/A5by default! Hardware I2C1 is mapped to D14 (PB9 = SDA) and D15 (PB8 = SCL) at the top-right Arduino header. Wiring the OLED to A4/A5 will result in a blank screen. - 3.3V Logic & 8 mA/Pin GPIO Limit: Although some STM32 pins are 5V-tolerant for inputs, always power the ADXL345, OLED, and ESP-01S at 3.3V. Use 220Ω resistors on all LEDs to stay safely within STM32's recommended 8 mA/pin continuous draw, and place a 100–470 μF decoupling capacitor (or external 3.3V LDO) on the ESP-01S 3.3V rail to handle Wi-Fi transmit current spikes.
- Rigid Sensor Mounting on Motor Casing: Never attach the ADXL345 with foam tape or loose zip-ties—soft materials act as a mechanical low-pass filter that absorbs high-frequency bearing vibrations! Mount the sensor rigidly to the motor bearing housing using a neodymium magnet base, epoxy, or threaded stud.
3. Complete Pinout Mapping Table & Bill of Materials
Reference both Arduino Uno V3 header names and native STM32 GPIO names when wiring and configuring STM32duino.
| Component | Module Pin | Arduino Header | STM32 GPIO | Wire Color | Circuit Function |
|---|---|---|---|---|---|
| ADXL345 Sensor | VCC / GND | 3V3 / GND | Power | Red / Black | 3.3V clean supply |
| ADXL345 Sensor | SCL (SCK) / SDO (MISO) | D13 / D12 | PA5 / PA6 | Blue / Purple | SPI1 Clock & Data Out (1600 Hz) |
| ADXL345 Sensor | SDA (MOSI) / CS | D11 / D10 | PA7 / PB6 | Teal / Orange | SPI1 Data In & Chip Select |
| 0.96" SSD1306 OLED | SCL / SDA | D15 / D14 | PB8 / PB9 | Amber / Blue | Dedicated I2C1 Display Bus (0x3C) |
| ESP-01S Wi-Fi Bridge | RX / TX | D8 / D2 | PA9 / PA10 | Green / Cyan | USART1 Telemetry (115200 baud) |
| Industrial Stack LEDs | Green / Amber / Red | D9 / D6 / D7 | PC7 / PB10 / PA8 | Grn / Amb / Red | Status Tower (via 220Ω resistors) |
| 3.3V Active Buzzer | + (Pos) / − (Neg) | D4 / GND | PB5 / GND | Purple / Black | Audible Zone C/D Fault Alarm |
| Onboard User Button | B1 (Blue Button) | Onboard | PC13 | Internal | Triggers On-Device AI Learning Mode |
Bill of Materials (BOM)
| Component | Recommended Part / Spec | Qty | Approx. Cost (INR / USD) |
|---|---|---|---|
| Microcontroller Board | STM32 Nucleo-F446RE (180 MHz Cortex-M4F, ST-LINK onboard) | 1 | ₹1,450 / $17.00 |
| Vibration Sensor | ADXL345 3-Axis Digital Accelerometer Breakout (SPI/I2C) | 1 | ₹220 / $2.60 |
| OLED Display | 0.96" I2C OLED Display (SSD1306, 128×64) | 1 | ₹210 / $2.50 |
| Wi-Fi Telemetry Module | ESP-01S (ESP8266) + 3.3V Regulator Adapter Board | 1 | ₹220 / $2.60 |
| Stack Indicators & Mounting | Green/Amber/Red LEDs, 3×220Ω Resistors, 3.3V Buzzer, Magnet Base | 1 set | ₹300 / $3.30 |
| Estimated Total Project Cost (Lab Motor Prototype) | ₹2,400 / $28.00 | ||
4. Interactive Live Motor Vibration & FFT AI Simulator
Select a mechanical fault scenario or drag the RPM, Load, and Fault Severity sliders to observe 3-axis waveforms, 1X/2X/3X FFT harmonic peaks, ISO 10816 severity zones, and NanoEdge AI Health Scores in real time.
RMS: 0.14 g (1.1 mm/s)
ISO 10816: ZONE A (GOOD)
5. 4-Step NanoEdge AI Studio / STM32Cube.AI Workflow
Train an unsupervised anomaly detector using only healthy motor vibration—no need to destroy a real motor to collect failure data.
Log Healthy Baseline Buffers
Flash the starter sketch below and stream 100+ buffers of 256×3-axis samples (768 values/row) over USB Serial while your lab motor runs smoothly across normal speeds and loads.
Benchmark in NanoEdge AI Studio
Select STM32 Nucleo-F446RE and 3-Axis Accelerometer in NanoEdge AI Studio (free for ST boards). Import your normal dataset plus a few simulated-fault clips (e.g., light tap or weight on shaft) to benchmark the best ML library.
Export Static C Library (.a)
Compile and download the optimized libneai.a + NanoEdgeAI.h package (typically <12 KB Flash, <4 KB RAM) and drop it into your STM32CubeIDE or STM32duino project folder.
On-Device Learning via B1 (PC13)
Mount the unit on any new factory motor, press the blue B1 button (PC13) for 2 seconds to run neai_anomalydetection_learn() for 30 cycles, and immediately start live health monitoring.
6. Copy-Ready Arduino (STM32duino) Starter Code
Install the STM32 MCU based boards core in Arduino IDE, select Nucleo-64 → Nucleo F446RE, and install Adafruit ADXL345 and Adafruit SSD1306.
// ============================================================================
// Smart Industrial Motor Predictive Maintenance via Vibration AI
// Board: STM32 Nucleo-F446RE (180 MHz Cortex-M4F)
// ADXL345 SPI1: SCK=PA5(D13), MISO=PA6(D12), MOSI=PA7(D11), CS=PB6(D10)
// SSD1306 OLED I2C1: SDA=PB9(D14), SCL=PB8(D15) [NOT A4/A5!]
// ESP-01S USART1: TX=PA9(D8), RX=PA10(D2) | Learn Button: PC13 (B1)
// Stack LEDs: GRN=PC7(D9), AMB=PB10(D6), RED=PA8(D7) | Buzzer: PB5(D4)
// ============================================================================
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <math.h>
// #include "NanoEdgeAI.h" // Uncomment after exporting library from NanoEdge AI Studio
// Pin Definitions (STM32 Native Pin Names)
#define ADXL_CS_PIN PB6 // D10
#define LED_GREEN_PIN PC7 // D9
#define LED_AMBER_PIN PB10 // D6
#define LED_RED_PIN PA8 // D7
#define BUZZER_PIN PB5 // D4
#define BTN_LEARN_PIN PC13 // Onboard Blue User Button B1 (Active LOW)
#define SAMPLES 256
#define AXES 3
#define SAMPLE_PERIOD_US 625 // 1 / 1600 Hz = 625 microseconds
// Dedicated Hardware Peripherals
HardwareSerial SerialWiFi(PA10, PA9); // USART1: RX=PA10(D2), TX=PA9(D8)
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(PA5, PA6, PA7, ADXL_CS_PIN, 12345);
Adafruit_SSD1306 display(128, 64, &Wire, -1);
float vibBuffer[SAMPLES * AXES];
float baselineRmsG = 0.15; // Updated automatically when B1 Learn Button is pressed
void captureVibrationBuffer(float &rmsOut) {
double sumSq = 0.0;
uint32_t nextMicros = micros();
for (int i = 0; i < SAMPLES; i++) {
while ((int32_t)(micros() - nextMicros) < 0) { /* 1600 Hz pacing */ }
nextMicros += SAMPLE_PERIOD_US;
sensors_event_t ev;
accel.getEvent(&ev);
float gx = ev.acceleration.x / 9.80665;
float gy = ev.acceleration.y / 9.80665;
float gz = (ev.acceleration.z / 9.80665) - 1.0; // Remove 1g gravity
vibBuffer[i * 3 + 0] = gx;
vibBuffer[i * 3 + 1] = gy;
vibBuffer[i * 3 + 2] = gz;
sumSq += (gx * gx + gy * gy + gz * gz);
}
rmsOut = sqrt(sumSq / (SAMPLES * AXES));
}
void setStackLight(int healthScore) {
if (healthScore >= 80) {
digitalWrite(LED_GREEN_PIN, HIGH);
digitalWrite(LED_AMBER_PIN, LOW);
digitalWrite(LED_RED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
} else if (healthScore >= 50) {
digitalWrite(LED_GREEN_PIN, LOW);
digitalWrite(LED_AMBER_PIN, HIGH);
digitalWrite(LED_RED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
} else {
digitalWrite(LED_GREEN_PIN, LOW);
digitalWrite(LED_AMBER_PIN, LOW);
digitalWrite(LED_RED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
}
}
void setup() {
Serial.begin(115200); // ST-LINK USB Debug & NanoEdge Data Logger
SerialWiFi.begin(115200); // ESP-01S MQTT Bridge on USART1
pinMode(LED_GREEN_PIN, OUTPUT);
pinMode(LED_AMBER_PIN, OUTPUT);
pinMode(LED_RED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(BTN_LEARN_PIN, INPUT_PULLUP);
// Initialize I2C1 on D14 (PB9=SDA) & D15 (PB8=SCL)
Wire.setSDA(PB9);
Wire.setSCL(PB8);
Wire.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextColor(SSD1306_WHITE);
// Initialize ADXL345 over SPI1 at 1600 Hz Output Data Rate
if (!accel.begin()) {
Serial.println("ERROR: ADXL345 SPI1 not detected! Check D10-D13.");
while (1) delay(500);
}
accel.setRange(ADXL345_RANGE_8_G);
accel.setDataRate(ADXL345_DATARATE_1600_HZ);
// neai_anomalydetection_init(); // Initialize NanoEdge AI here
Serial.println("STM32 Motor Vibration AI Ready. Press B1 (PC13) to learn baseline.");
}
void loop() {
float rmsG = 0.0;
captureVibrationBuffer(rmsG);
// 1. On-Device Learning Mode when Blue Button B1 (PC13) is pressed
if (digitalRead(BTN_LEARN_PIN) == LOW) {
baselineRmsG = rmsG;
// neai_anomalydetection_learn(vibBuffer); // NanoEdge AI On-Device Learning
Serial.printf("Learned Healthy Baseline RMS: %.3f g\n", baselineRmsG);
}
// 2. Anomaly Detection Inference (Replace heuristic with NanoEdge AI call)
uint8_t similarity = 100;
// neai_anomalydetection_detect(vibBuffer, &similarity);
float deviation = fabs(rmsG - baselineRmsG);
similarity = (uint8_t)constrain(100.0 - (deviation * 140.0), 0.0, 100.0);
setStackLight(similarity);
// 3. Update 0.96" OLED Display
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.println("MOTOR VIBRATION AI");
display.drawLine(0, 10, 128, 10, SSD1306_WHITE);
display.setTextSize(2);
display.setCursor(0, 18);
display.printf("HLTH:%d%%", similarity);
display.setTextSize(1);
display.setCursor(0, 42);
display.printf("RMS: %.3f g (1600Hz)", rmsG);
display.setCursor(0, 54);
display.println(similarity >= 80 ? "STATUS: HEALTHY" : (similarity >= 50 ? "STATUS: CHECK MOTOR" : "STATUS: FAULT ALERT!"));
display.display();
// 4. Stream JSON Telemetry to ESP-01S Wi-Fi Bridge over USART1
String json = "{\"motor\":\"M01\",\"health\":" + String(similarity) +
",\"rms_g\":" + String(rmsG, 3) + "}";
SerialWiFi.println(json);
Serial.println(json);
delay(500);
}
7. College Viva & Presentation Q&A
Expand each question to prepare sharp, engineering-backed answers for project reviews and external examiners.
f_s ≥ 2 × f_max). Sampling the ADXL345 at 1600 Hz gives us a clean observable FFT bandwidth up to 800 Hz—easily capturing 1X shaft unbalance (25–50 Hz), 2X/3X misalignment harmonics (50–150 Hz), and early rolling-element bearing defect harmonics (300–750 Hz).
A4 (SDA) and A5 (SCL) like an Arduino UNO. On the STM32 Nucleo-F446RE, A4/A5 are analog inputs (PC1/PC0) with no hardware I2C1 connection by default. Hardware I2C1 is located on D14 (PB9 = SDA) and D15 (PB8 = SCL)—which is exactly where our SSD1306 OLED is wired and configured via Wire.setSDA(PB9) and Wire.setSCL(PB8).