Skip to content

AbhiGen/Luggage-Security-System

Repository files navigation

🛡️ Anti-Theft Bag Security System (ML-Optimized)

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

⚙️ Key Features

  • 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.

🧠 System Components

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)

🔌 Pin Configuration

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

🧩 Software and Logic Flow

1. System Initialization

  • 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, then SEA-DEV (searching for Bluetooth).

2. Gyroscope Calibration

  • Function: calibrate_gyro()
  • Takes ~100 samples from MPU6050 to compute static offsets, reducing false positives from gravity.
  • OLED displays CALIBRATING during this phase.

3. Bluetooth Connection

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

4. Bluetooth Commands

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), SAFESEC-ON
X/x Turn Security OFF Secured → Ready Red LED ON, Buzzer (x2), SEC-OFFCON-DEV

5. Monitoring and Theft Detection

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 A command is received.

6. Core Monitoring Logic (Pseudo-Code)

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();
    }
}

🧪 Testing Procedure

Step Action Expected Result Pass/Fail
1 Power on STM32 LEDs cycle (Blue → Red → Green), Buzzer (x2), OLED: CALIBRATINGSEA-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: SAFESEC-ON, Green LED ON, Alarm stops
7 Send X command OLED: SEC-OFFCON-DEV, Red LED ON (briefly), Security off

🛠️ Tools & Environment

  • 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)

📸 Example Output

OLED Display:

SEC-ON
Monitoring...

Bluetooth Alert (Mobile):

Theft Detected - ALARM

⚡ Power & Safety

  • 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.

🚀 Getting Started

  1. Hardware Setup:
    • Connect components as per the pin configuration table.
    • Verify HC-05 voltage compatibility and add a divider if needed.
  2. Software Setup:
    • Clone this repository.
    • Open the project in STM32CubeIDE or Keil uVision.
    • Include model.h and model.cpp for the ML classifier.
    • Flash the code using ST-Link V2.
  3. Testing:
    • Follow the testing procedure to validate functionality.
    • Use a Bluetooth terminal app (e.g., Serial Bluetooth Terminal) to send commands.

📝 Notes

  • 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.

🤝 Team

Abhiram Bikkina , Dhinesh Chandra , Pavan Vignesh , Pavan Krishna

About

Our luggage security system detects unauthorized movement or vibration of luggage using sensors and alerts the user through buzzer, light and Bluetooth communication.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors