A smart luggage protection system built on the STM32F401 Black Pill microcontroller, utilizing a lightweight Machine Learning (ML) model to detect theft through motion and vibration analysis. The system integrates MPU6050 gyroscope, SW-420 vibration sensor, HC-05 Bluetooth module, SSD1306 OLED display, RGB LEDs, and a buzzer for real-time alerts and user feedback.
YouTube link ( project demo ) - https://youtu.be/AzWjN9hOwwE
- ✅ ML-Powered Theft Detection: Uses a lightweight classifier to analyze motion and vibration patterns for accurate theft detection.
- ✅ Dual Sensor Monitoring: Combines MPU6050 gyroscope (orientation/movement) and SW-420 vibration sensor (physical shocks).
- ✅ Wireless Alerts: Sends instant alerts via HC-05 Bluetooth to a connected mobile device.
- ✅ Visual Feedback: SSD1306 OLED (128x32) displays system status, and RGB LEDs indicate operating modes (Blue: Boot, Green: Armed, Red: Alarm/Off).
- ✅ Local Alarm: Buzzer sounds a loud alert when theft is detected.
- ✅ Secure Control: System ON/OFF and alarm deactivation via secure Bluetooth commands.
- ✅ Automatic Calibration: Calibrates gyroscope offsets on boot to eliminate false positives from static gravity.
| Module | Function | Interface |
|---|---|---|
| STM32F401 Black Pill | Main microcontroller (ML execution) | - |
| MPU6050 Gyroscope | Detects movement and angular velocity | I2C1 (Shared) |
| SW-420 Vibration | Detects physical shocks/vibrations | GPIO (PA7) |
| HC-05 Bluetooth | Wireless control and alerts | USART1 (PA9, PA10) |
| SSD1306 OLED (128x32) | Displays system status and warnings | I2C1 (Shared) |
| Buzzer | Sounds local alarm | GPIO (PB1) |
| RGB LEDs | Indicate system state | GPIO (PA0, PA1, PA2) |
| Component | Signal | STM32 Pin | Description |
|---|---|---|---|
| SW-420 Vibration | VCC | 3.3V | Power (3.3V preferred) |
| GND | GND | Ground | |
| AO | PA7 | Digital Input (Vibration Status) | |
| HC-05 Bluetooth | VCC | 5V | Power |
| GND | GND | Ground | |
| TXD | PA10 | USART1 RX (STM32 ← HC-05 TXD) | |
| RXD | PA9 | USART1 TX (STM32 → HC-05 RXD) * | |
| OLED (128x32, I2C) | VCC | 3.3V | Power |
| GND | GND | Ground | |
| SDA | PB7 | I2C1 SDA Data Line | |
| SCL | PB6 | I2C1 SCL Clock Line | |
| MPU6050 Gyroscope | VCC | 3.3V | Power |
| GND | GND | Ground | |
| SDA | PB7 | I2C1 SDA (Shared with OLED) | |
| SCL | PB6 | I2C1 SCL (Shared with OLED) | |
| Buzzer | Signal | PB1 | Digital Output (Alarm Signal) |
| GND | GND | Ground | |
| LED Blue | Signal | PA0 | Power/Boot Indicator |
| LED Red | Signal | PA1 | Alarm/Security OFF Indicator |
| LED Green | Signal | PA2 | Security ON Indicator |
- Function:
system_init() - Initializes clocks, GPIO, UART (USART1), I2C (I2C1), OLED, MPU6050, and loads the ML model.
- Boot Sequence: Cycles LEDs (Blue → Red → Green), buzzer beeps twice, OLED displays
CALIBRATING, thenSEA-DEV(searching for Bluetooth).
- Function:
calibrate_gyro() - Takes ~100 samples from MPU6050 to compute static offsets, reducing false positives from gravity.
- OLED displays
CALIBRATINGduring this phase.
| State | OLED Message | LED Color | Bluetooth Action |
|---|---|---|---|
| Searching | SEA-DEV |
Off | Waiting for connection |
| Connected | CON-DEV |
Off | Sends "DEVICE CONNECTED" |
| Disconnected | DIS-DEV |
Off | Indicates connection lost |
Control the system via a mobile app or serial terminal:
| Command | Function | Resulting State | LED/Buzzer/OLED |
|---|---|---|---|
O/o |
Turn Security ON | Ready → Secured | Green LED ON, Buzzer (x2), SEC-ON |
A/a |
Deactivate Alarm | Alert → Secured | Green LED ON, Buzzer (x1 long), SAFE → SEC-ON |
X/x |
Turn Security OFF | Secured → Ready | Red LED ON, Buzzer (x2), SEC-OFF → CON-DEV |
When armed (SEC-ON):
- Reads MPU6050 (gyroscope data: ΔX, ΔY, ΔZ) and SW-420 (vibration status).
- Feeds 4 features (ΔGyro_X, ΔGyro_Y, ΔGyro_Z, Vibration) into the ML model.
- If model predicts theft (
Prediction = 1):- OLED:
ALERT - Bluetooth: Sends "Bag has been removed - ALARM"
- Alarm: Red LED flashes, buzzer sounds repeatedly
- Persists until
Acommand is received.
- OLED:
if (security_on && !alert_active) {
mpu6050_read_gyro(&x, &y, &z); // Read gyro data
float features[4] = {
(float)x - gyro_x_offset,
(float)y - gyro_y_offset,
(float)z - gyro_z_offset,
(float)read_vibration()
};
int prediction = predict(features); // ML model prediction
if (prediction == 1) {
alert_active = 1;
send_bt_msg("Theft detected - ALARM");
oled_display("ALERT", "");
trigger_buzzer_and_red_led();
}
}| Step | Action | Expected Result | Pass/Fail |
|---|---|---|---|
| 1 | Power on STM32 | LEDs cycle (Blue → Red → Green), Buzzer (x2), OLED: CALIBRATING → SEA-DEV |
|
| 2 | Connect mobile app to HC-05 | OLED: CON-DEV, Buzzer (x1 long) |
|
| 3 | Send O command |
OLED: SEC-ON, Green LED ON, Buzzer (x2) |
|
| 4 | Leave device still for 10s | No alert (confirms calibration) | |
| 5 | Gently lift/move/shake device | OLED: ALERT, Red LED flashes, Buzzer sounds, BT: "Bag has been removed" |
|
| 6 | Send A command (during alert) |
OLED: SAFE → SEC-ON, Green LED ON, Alarm stops |
|
| 7 | Send X command |
OLED: SEC-OFF → CON-DEV, Red LED ON (briefly), Security off |
- MCU: STM32F401 Black Pill
- IDE: STM32CubeIDE or Keil uVision
- Language: C/C++ (ML model in
model.h/model.cpp) - Debugger: ST-Link V2
- ML Model: Lightweight classifier integrated via
model.h - Libraries:
- STM32 HAL for GPIO, UART, I2C
- MPU6050 driver for gyroscope data
- SSD1306 driver for OLED display
- Power: USB (5V) or external 3.3V–5V supply (~100–200 mA)
OLED Display:
SEC-ON
Monitoring...
Bluetooth Alert (Mobile):
Theft Detected - ALARM
- Supply: 3.3V–5V via USB or external source.
- Grounding: Ensure common GND for all modules.
- HC-05 Safety: Use a voltage divider for HC-05 RXD (PA9) if 3.3V logic is required.
- Current Draw: ~100–200 mA total.
- Hardware Setup:
- Connect components as per the pin configuration table.
- Verify HC-05 voltage compatibility and add a divider if needed.
- Software Setup:
- Clone this repository.
- Open the project in STM32CubeIDE or Keil uVision.
- Include
model.handmodel.cppfor the ML classifier. - Flash the code using ST-Link V2.
- Testing:
- Follow the testing procedure to validate functionality.
- Use a Bluetooth terminal app (e.g., Serial Bluetooth Terminal) to send commands.
- Ensure the ML model (
model.h) is pre-trained and optimized for the STM32F401's memory constraints. - The system assumes a stable 3.3V power supply for sensors and STM32 to avoid erratic behavior.
- Test the HC-05 pairing process in a controlled environment to avoid interference.
Abhiram Bikkina , Dhinesh Chandra , Pavan Vignesh , Pavan Krishna