Embedded bike theft detection using an ESP32-S3, MPU6050 IMU, Bluetooth Low Energy, and an on-device machine learning classifier.
BikeGuard is a prototype system that monitors a bicycle's motion and classifies whether that motion is consistent with a theft attempt. The project spans the full sensing to inference pipeline: embedded firmware collects accelerometer and gyroscope data, a React Native Android app controls the device and records labeled examples, and a Python/scikit-learn pipeline trains a classifier whose learned rules can be exported back to C++ for on-device inference.
flowchart LR
IMU[MPU6050 IMU<br/>Acceleration + Gyroscope] -->|I2C| ESP[ESP32-S3<br/>C++ Firmware]
ESP <-->|BLE| APP[React Native<br/>Android App]
APP --> DATA[Labeled IMU<br/>Recordings]
DATA --> ML[Python + scikit-learn<br/>Motion Classifier]
ML -->|Export decision rules| ESP
The MPU6050 provides six-axis motion measurements to the ESP32-S3 over I2C. The firmware handles sensor sampling, device control, and BLE communication with the Android app. The app can connect to BikeGuard, arm/disarm the system, and record labeled IMU sessions for building the training dataset.
The current prototype is built around an ESP32-S3 and MPU6050 accelerometer/gyroscope. The breadboard setup was used to develop and test sensor sampling, BLE communication, data collection, and the classification pipeline before moving toward a more integrated physical design.
The React Native app provides a BLE interface for interacting with the embedded device. It scans for nearby BLE devices, connects to BikeGuard, displays system state, and provides controls for arming the device and starting a data-recording session.
![]() |
![]() |
| Device control | Labeled data collection |
For data collection, a recording is assigned an action label and a binary theft / no-theft classification before capture. This makes it possible to collect labeled motion directly from the physical prototype rather than manually matching sensor logs to labels afterward.
Each recording contains timestamped acceleration and gyroscope measurements from the MPU6050 along with the recording session, action, and theft label.
The sensor stream includes:
accel_x,accel_y,accel_zgyro_x,gyro_y,gyro_z- recording/session metadata
- an action label describing the motion
- a binary theft label
Keeping a session identifier is also important for evaluation: recordings are split between training and testing by recording session, rather than allowing windows from the same recording to appear in both sets.
The current ML pipeline uses a lightweight decision tree classifier designed to be simple enough to translate into C++ and execute directly on the ESP32-S3.
- Split each IMU recording into 50-sample windows.
- Compute acceleration and gyroscope magnitudes.
- Extract 10 statistical features: mean, standard deviation, minimum, maximum, and range for each magnitude signal.
- Split training and testing data by recording session.
- Train a binary theft vs. normal-motion decision tree using scikit-learn.
- Export the learned tree rules to C++ for on-device inference.
The pipeline also makes it possible to visualize how recorded motions differ. The example below compares acceleration magnitude from a normal bump with a labeled theft attempt.
These plots are exploratory examples from collected recordings; they are not presented as classifier performance metrics.
| Layer | Technologies |
|---|---|
| Embedded | C++, ESP32-S3 |
| Sensors | MPU6050 IMU, I2C |
| Wireless | Bluetooth Low Energy (BLE) |
| Mobile | React Native, Android |
| Data / ML | Python, scikit-learn |
| Classification | Statistical feature extraction, decision tree |
- C++ firmware for IMU sampling, device control, and BLE communication
- A React Native Android app for BLE device control and labeled motion-data collection
- A data pipeline for turning raw accelerometer/gyroscope recordings into windowed statistical features
- A scikit-learn pipeline for training a binary motion classifier
- A path for exporting the learned decision-tree rules to C++ for on-device inference
The current classifier focuses on binary theft detection. A natural next step is multiclass motion classification so BikeGuard can distinguish between different suspicious events, such as wheel tampering and lock tampering, rather than only predicting theft vs. normal motion.
Additional work can then focus on collecting a larger and more varied real-world dataset and evaluating how well the classifier generalizes across different bicycles, mounting positions, and everyday motion.
BikeGuard is an ongoing prototype exploring embedded sensing, BLE-connected data collection, and lightweight edge ML for physical security.





