COLLEGE PROJECT BLUEPRINT #4 • INDUSTRIAL IOT + EDGE AI

Smart Industrial Motor Predictive Maintenance via Vibration AI

Prevent costly factory motor breakdowns before they happen. Mount an ADXL345 3-axis accelerometer onto a motor casing, sample high-speed vibrations at 1600 Hz over SPI1 on an STM32 Nucleo-F446RE, and run unsupervised NanoEdge AI anomaly detection locally—driving an industrial stack light, OLED display, and Wi-Fi MQTT alerts.

BoardSTM32 Nucleo-F446RE (180 MHz)
SensorADXL345 SPI (1600 Hz)
AI EngineNanoEdge AI / Edge Impulse
Est. Cost₹2,400 / $28

1. System Architecture Pipeline

How an ARM Cortex-M4 microcontroller turns raw mechanical motor shaking into actionable predictive maintenance alerts.

STAGE 1 • SPI1

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.

STAGE 2 • DSP

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.

STAGE 3 • TINYML

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.

STAGE 4 • IIOT

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.

3.3V Reg SPI1 SCK SPI1 MISO SPI1 MOSI SPI1 CS I2C1 SCL I2C1 SDA TX1 → RX RX1 ← TX D4/PB5 Buzzer + Mini-USB ST-LINK/V2-1 Debugger Arduino Uno V3 + Morpho STM32 F446RE 180MHz FPU B1 (PC13) AI Learn Btn NUCLEO-F446RE (3.3V) 3V3 GND D13/PA5 D12/PA6 D11/PA7 D10/PB6 D8/PA9 (TX1) D2/PA10 (RX1) GND 3V3 GND D15/PB8 D14/PB9 D9/PC7 D6/PB10 D7/PA8 D4/PB5 MOTOR CASING 3-AXIS ADXL345 SPI 1600 Hz Rigid Mount VCC GND SCL SDO SDA CS ESP-01S Wi-Fi MQTT Telemetry Bridge USART1 115200 baud 3V3 RX TX GND 0.96" SSD1306 OLED (0x3C) MOTOR HEALTH AI HEALTH: 96% ISO ZONE A (GOOD) RMS: 0.14g | 1500RPM VCC GND SCL SDA 220Ω Green (OK) Amber Red 3.3V Active Buzzer 3.3V GND SPI1 (D10–D13) I2C1 OLED (D14/D15) USART1 Wi-Fi (D8/D2) Buzzer (D4/PB5) Stack LEDs (D9/D6/D7)
All Wires Shown: The ADXL345 runs on dedicated SPI1 (D10–D13) for 1600 Hz sampling, the OLED runs on dedicated I2C1 (D14/D15), the ESP-01S bridges telemetry over USART1 (D8/D2), and D9/D6/D7/D4 drive the industrial stack indicators.

Hardware Safety & Pinout Caution (Important for STM32 Nucleo-F446RE)

  1. The Nucleo-F446RE A4/A5 I2C Trap: Unlike an Arduino UNO, the STM32 Nucleo-F446RE does NOT route hardware I2C1 to A4/A5 by 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.
  2. 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.
  3. 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.

3-AXIS VIBRATION WAVEFORM (g) X Y Z
0–800 Hz FFT SPECTRUM (SPI 1600 Hz) 1X = 25.0 Hz
1X Fundamental Shaft Frequency = RPM ÷ 60
Higher mechanical load slightly raises baseline vibration amplitude
Simulates progressive wear from healthy baseline to critical failure
SSD1306 (I2C1) NANOEDGE AI
HEALTH: 96%
STATE: HEALTHY MOTOR
RMS: 0.14 g (1.1 mm/s)
ISO 10816: ZONE A (GOOD)
Stack Light
BUZ: OFF
AI Similarity 96%
Health Score 96 / 100
ISO 10816 Zone
ZONE A: GOOD
USART1 → ESP-01S MQTT (factory/motor01/vib) 115200 baud

        

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.

1

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.

2

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.

3

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.

4

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.

stm32_motor_vibration_ai.ino • Nucleo-F446RE + ADXL345 SPI1 (1600 Hz) + OLED I2C1 + USART1
// ============================================================================
// 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.

The Arduino UNO runs an 8-bit ATmega328P at 16 MHz with only 2 KB of RAM and no floating-point hardware—making real-time 1600 Hz FFT and ML inference impossible. The STM32F446RE features a 32-bit ARM Cortex-M4 at 180 MHz, a dedicated hardware Floating-Point Unit (FPU), single-cycle SIMD DSP instructions (CMSIS-DSP), and 128 KB SRAM, allowing it to compute 256-point FFTs and NanoEdge AI anomaly detection in just a few milliseconds.
Standard I2C (100–400 kHz) has protocol overhead (start/stop/ACK bits) that struggles to sustain deterministic 1600 Hz or 3200 Hz 3-axis sampling without jitter. SPI1 operates at 2–5 MHz full-duplex, reading all 6 acceleration bytes in microseconds with rock-solid timing—preventing spectral smearing in the FFT.
The Nyquist-Shannon theorem states that to reconstruct a frequency without aliasing, you must sample at least twice that frequency (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).
In real factories, every motor has different mounting stiffness, load, and age, and you cannot intentionally break expensive industrial motors just to record labeled "broken bearing" training data. Unsupervised Anomaly Detection (like NanoEdge AI) learns only from the motor's normal healthy vibration right on the machine via the B1 button, and flags any unknown future fault as a drop in Similarity %.
ISO 10816 (and newer ISO 20816) is the international standard that grades rotating machine health using RMS vibration velocity (mm/s): Zone A (Good) for newly commissioned machines, Zone B (Satisfactory) for unrestricted long-term operation, Zone C (Unsatisfactory) requiring scheduled maintenance, and Zone D (Unacceptable) where vibration is severe enough to cause immediate mechanical damage.
Many students assume Arduino-shaped boards always put I2C on 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).