Final Year Project β MCA Semester 4
A real-time motorcycle accident detection system that combines computer vision, IoT sensors, machine learning, and automated emergency alerts to improve rider safety.
Features β’ Architecture β’ Modules β’ Installation β’ Usage β’ Evaluation β’ Tech Stack
RideGuard is an integrated motorcycle safety system that detects accidents in real-time using multiple sensor inputs and immediately notifies emergency contacts via Telegram with GPS location and photographic evidence.
The system is simulated using the CARLA 0.9.10 autonomous driving simulator and validated with real IoT hardware including Arduino, MPU6050, HC-SR04 ultrasonic sensor, Neo-6M GPS, and ESP32-CAM.
- Helmet Detection β YOLOv8 detects helmet usage every 5 seconds via webcam. Restricts speed to 30 km/h if no helmet detected
- Tilt/Fall Detection β MPU6050 gyroscope detects motorcycle tilt beyond 10 degrees and triggers fall animation in CARLA
- Rear Collision Detection β HC-SR04 ultrasonic sensor detects rear vehicle proximity. Triggers accident after 3 consecutive readings within 2cm
- Accident Hotspot Warning β DBSCAN clustering on 99 Chennai GPS accident records identifies 6 hotspot zones. Warns rider in real-time when within 2km
- Emergency Alert β Sends Telegram message with rider details, live GPS pin, and ESP32-CAM evidence photos within 20 seconds of accident
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RIDEGUARD SYSTEM β
ββββββββββββββββ¬βββββββββββββββ¬βββββββββββββββ¬βββββββββββββββββ€
β MODULE 1 β MODULE 2 β MODULE 3 β MODULE 4 β
β Helmet β Tilt β Rear β Hotspot β
β Detection β Detection β Collision β Detection β
β (YOLOv8) β (MPU6050) β (Ultrasonic) β (DBSCAN) β
ββββββββ¬ββββββββ΄βββββββ¬ββββββββ΄βββββββ¬ββββββββ΄ββββββββ¬βββββββββ
β β β β
ββββββββββββββββ΄βββββββββββββββ΄ββββββββββββββββ
β
βββββββββββΌββββββββββ
β FILE-BASED IPC β
β (Shared .txt β
β files between β
β processes) β
βββββββββββ¬ββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
β β β
βββββββββββΌβββββββ ββββββββΌβββββββ βββββββΌβββββββββββ
β CARLA 0.9.10 β β MODULE 5 β β HUD DISPLAY β
β Simulation β β Emergency β β (Pygame) β
β Fall Animationβ β Alert β β β
ββββββββββββββββββ β (Telegram) β ββββββββββββββββββ
βββββββββββββββ
Detects whether the rider is wearing a helmet using a custom-trained YOLOv8 model via laptop webcam.
- Model:
best.pt(custom trained, 2 classes) - Classes:
With Helmet/Without Helmet - Confidence threshold:
0.50 - Check interval: every
5 seconds - Speed enforcement:
80% throttlewith helmet,35% throttlewithout
| Metric | Value |
|---|---|
| Accuracy | 90.00% |
| Precision | 88.46% |
| Recall | 92.00% |
| F1-Score | 0.9020 |
MPU6050 gyroscope sensor measures motorcycle tilt angle. When tilt exceeds 10 degrees, it writes LEFT or RIGHT to a shared file which CARLA reads to trigger a 3-stage fall animation.
- Tilt threshold:
10 degrees - Check interval:
5 seconds - Secondary verification: Sobel edge + image moment analysis on ESP32-CAM images
- MPU6050 takes priority over camera analysis
HC-SR04 ultrasonic sensor monitors rear vehicle distance. Uses a 3-reading debounce buffer to prevent false triggers.
- Danger zone:
<= 2cm(3 consecutive readings) - Warning zone:
2cm to 6cm - On trigger: writes ACCIDENT to IPC file, sends CAPTURE command to ESP32-CAM
- ESP32-CAM captures 5 images saved to SD card
| Zone | Distance | Action |
|---|---|---|
| Safe | > 6cm | No action |
| Warning | 2β6cm | HUD warning |
| Danger | <= 2cm (x3) | Accident trigger |
DBSCAN clustering on 99 GPS accident records from Chennai identifies 6 accident-prone zones. Background thread checks rider GPS every 60 seconds and warns if within 2km of any hotspot.
- Algorithm: DBSCAN (Density-Based Spatial Clustering)
- Dataset: 99 GPS records (Chennai)
- eps:
0.5km / 6371 = 0.0000785 radians - min_samples:
5 - metric:
haversine - Warning radius:
2.0 km
Detected Hotspot Zones:
| # | Area | Accidents |
|---|---|---|
| 1 | Koyambedu Junction | 18 |
| 2 | Madhya Kailash (OMR) | 19 |
| 3 | Kathipara Junction | 19 |
| 4 | Poonamallee High Road | 18 |
| 5 | Anna Salai (Gemini) | 18 |
| 6 | Tambaram Bypass | 7 |
| Clustering Metric | Value |
|---|---|
| Silhouette Score | 0.9879 |
| Davies-Bouldin Index | 0.0165 |
| Calinski-Harabasz | 395534.21 |
On any accident trigger, collects GPS location, ESP32-CAM images, and rider details. Sends Telegram alert within 18β21 seconds.
| Content | MPU Fall | Rear Collision |
|---|---|---|
| Text message | Yes | Yes |
| Live GPS pin | Yes | Yes |
| Evidence images | No | Yes (img_1 + img_5) |
All modules communicate through shared text files (File-based IPC):
| File | Writer | Reader | Content |
|---|---|---|---|
fall_status.txt |
MPU6050/Arduino | Merging_module_3.py | LEFT / RIGHT / NONE |
accident_trigger.txt |
Rear_Location.py | Merging_module_3.py | ACCIDENT |
rear_warning.txt |
Rear_Location.py | Merging_module_3.py | WARNING |
hotspot_warning.txt |
hotspot_detector.py | Merging_module_3.py | WARNING|count|dist |
gps_log.txt |
Rear_Location.py | emergency_alert.py | timestamp,lat,lng,sats |
telegram_status.txt |
emergency_alert.py | Merging_module_3.py | SENT |
- Python 3.7 (strict requirement for CARLA compatibility)
- CARLA 0.9.10 Simulator
- Arduino IDE (for hardware code upload)
git clone https://github.com/Banuprasath/RideGuard.git
cd RideGuardinstall.batOr manually install dependencies:
pip install -r requirements.txtcopy .env.example .envEdit .env with your values:
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id
ARDUINO_PORT=COM16
ESP32_PORT=COM3
ESP32_IP=192.168.137.XDownload from: https://github.com/carla-simulator/carla/releases/tag/0.9.10
Extract to C:\CARLA_0.9.10\ then update the path in Merging_module_3.py line 21:
sys.path.append(
r"C:\CARLA_0.9.10\WindowsNoEditor\PythonAPI\carla\dist\carla-0.9.10-py3.7-win-amd64.egg"
)The trained best.pt model is included in the repository root. No separate download needed.
If you want to retrain the model:
python train_helmet.pyOpen 4 terminals and run in order:
# Terminal 1 β Start CARLA Server
cd C:\CARLA_0.9.10\WindowsNoEditor
CarlaUE4.exe
# Terminal 2 β Main System
cd RideGuard
python Merging_module_3.py
# Terminal 3 β Hardware Bridge
python Rear_Location.py
# Terminal 4 β Hotspot Monitor
python hotspot_detector.py| Key | Action |
|---|---|
| W / S | Throttle / Brake |
| A / D | Steer Left / Right |
| Arrow Left / Right | Simulate fall direction |
| 1 | Toggle helmet detection test |
| 2 | Trigger rear collision sequence |
| BACKSPACE | Reset after accident |
| C | Switch camera view |
| ESC | Quit |
Run evaluation metrics (no hardware required):
python evaluation\thesis_evaluation.pyGenerates 3 output images in evaluation/ folder:
| File | Description |
|---|---|
helmet_confusion_matrix.png |
YOLOv8 confusion matrix |
dbscan_hotspot_clusters.png |
DBSCAN cluster scatter plot |
dbscan_unsupervised_evaluation.png |
Silhouette plot + cluster size chart |
| Module | Metric | Value |
|---|---|---|
| Helmet Detection | Accuracy | 90.00% |
| Helmet Detection | F1-Score | 0.9020 |
| Tilt Detection | Success Rate | 92% |
| Rear Collision | Detection Accuracy | 95% |
| Emergency Alert | End-to-end Time | 18β21 seconds |
| DBSCAN Hotspot | Silhouette Score | 0.9879 |
RideGuard/
βββ Merging_module_3.py # Main CARLA + Helmet + Tilt module
βββ Rear_Location.py # Hardware bridge (Arduino + GPS + ESP32)
βββ emergency_alert.py # Telegram alert + evidence logging
βββ hotspot_detector.py # DBSCAN hotspot detection + monitor
βββ compare_hotspot_algorithms.py # ML algorithm comparison
βββ test_gps.py # Neo-6M GPS test utility
βββ train_helmet.py # YOLOv8 training script
βββ best.pt # Trained YOLOv8 helmet detection model
βββ yolov8n.pt # YOLOv8 nano base model
βββ accidents.csv # 99 Chennai GPS accident records
βββ requirements.txt # Python dependencies
βββ install.bat # Auto installer for Windows
βββ SETUP_GUIDE.txt # Manual setup instructions
βββ .env.example # Environment config template
βββ evaluation/ # Thesis evaluation scripts + charts
βββ Neo-6M_Connections/ # Arduino GPS + Ultrasonic code
βββ Testing_Dataset/ # Test CSVs for evaluation
βββ Thesis/ # Final year thesis report + viva PDF
βββ utils/ # Debug and utility scripts
βββ tests/ # Integration test scripts
| Category | Technology |
|---|---|
| Simulation | CARLA 0.9.10 |
| Computer Vision | YOLOv8 (Ultralytics) |
| Machine Learning | DBSCAN (scikit-learn) |
| Hardware | Arduino Uno, MPU6050, HC-SR04, Neo-6M GPS, ESP32-CAM |
| Rendering | Pygame |
| Image Processing | OpenCV |
| Alert System | Telegram Bot API |
| Language | Python 3.7 |
| Data | Pandas, NumPy |
| Visualization | Matplotlib |
| Serial Comm | PySerial |
- HC-SR04: TRIG β D9, ECHO β D10
- Neo-6M GPS: TX β D2, RX β D3
- Receives CAPTURE command via serial
- Serves images via HTTP at
http://ESP32_IP/image
The full project thesis and viva presentation are available in the Thesis/ folder:
| File | Description |
|---|---|
Thesis/Final_year_report_Banu_Prasath_crt (1).pdf |
Complete project thesis report |
Thesis/Banu-Prasath_S_Final_Viva.pdf |
Final viva presentation slides |
Banuprasath S MCA Final Year β Semester 4 GitHub: @Banuprasath Repository: RideGuard
This project is licensed under the MIT License.