Skip to content

PavanKuppili/Smart-Helmet-detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸͺ– Helmet Detection System

An AI-powered helmet detection system using YOLOv8 for safety compliance monitoring with Arduino hardware integration.

πŸš€ Features

  • AI-Powered Detection: YOLOv8-based helmet detection with high accuracy
  • Real-time Processing: Live webcam detection with instant results
  • Hardware Integration: Arduino control for motor, LED, and buzzer
  • Safety Compliance: Automatic safety checks with hardware responses

πŸ“ Project Structure

demo-helmate/
β”œβ”€β”€ helmet-detector/
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ data.yaml              # Dataset configuration
β”‚   β”‚   β”œβ”€β”€ train/                 # Training images (3,648)
β”‚   β”‚   β”œβ”€β”€ valid/                 # Validation images (372)
β”‚   β”‚   └── test/                  # Test images (149)
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── helmet.pt              # Trained YOLOv8 model (6.2MB)
β”‚   β”œβ”€β”€ scripts/
β”‚   β”‚   └── detect.py              # Main detection script
β”‚   β”œβ”€β”€ input/                     # Test images
β”‚   └── helmet_control_fixed.ino   # Arduino code
β”œβ”€β”€ yolov8n.pt                     # Base YOLOv8 model
β”œβ”€β”€ requirements.txt               # Python dependencies
└── README.md                     # This file

πŸ›  Installation

Prerequisites

  • Python 3.8+
  • Arduino IDE
  • Webcam (for live detection)

Setup

  1. Install Python dependencies

    pip install -r requirements.txt
  2. Verify installation

    python -c "import ultralytics, torch, cv2; print('βœ… All dependencies installed')"

🎯 Usage

Quick Start

  1. Test with a single image

    cd helmet-detector
    python scripts/detect.py input/helmate-on-1.webp
  2. Start live webcam detection

    python scripts/detect.py --webcam

Detection Results

  • βœ… PASS: Helmet detected β†’ Motor ON, LED OFF, Buzzer OFF
  • ❌ FAIL: No helmet β†’ Motor OFF, LED ON, Buzzer alert
  • ⚠️ CONFLICT: Conflicting detections β†’ Treat as FAIL
  • ❓ NO_DETECTION: No objects detected β†’ Treat as FAIL

πŸ”Œ Arduino Setup

Hardware Components

  • Arduino Uno (or compatible)
  • Motor (via relay) - simulates bike engine
  • Red LED (with 220Ξ© resistor) - warning indicator
  • Buzzer - alert system
  • USB Cable - for serial communication

Wiring Diagram

Arduino Uno:
β”œβ”€β”€ Pin 8 β†’ Relay β†’ Motor (Engine control)
β”œβ”€β”€ Pin 9 β†’ 220Ξ© Resistor β†’ Red LED (Warning light)
β”œβ”€β”€ Pin 11 β†’ Buzzer (Alert system)
└── USB β†’ Computer (Serial Communication)

Connection Steps

  1. Connect Hardware

    • Connect motor to Pin 8 via relay module
    • Connect red LED to Pin 9 with 220Ξ© resistor
    • Connect buzzer to Pin 11
    • Connect Arduino to computer via USB
  2. Upload Arduino Code

    • Open Arduino IDE
    • Open helmet-detector/helmet_control_fixed.ino
    • Select correct board and port
    • Click Upload
  3. Find COM Port

    • Open Device Manager (Windows)
    • Look for "Arduino" under "Ports (COM & LPT)"
    • Note the COM port number (e.g., COM5)
  4. Update COM Port in Script

    • Open helmet-detector/scripts/detect.py
    • Find line with serial.Serial('COM5', 9600, timeout=1)
    • Change 'COM5' to your actual COM port

Arduino Code Overview

// Pin definitions
const int motorPin = 8;     // Motor control
const int ledPin = 9;       // Red LED
const int buzzerPin = 11;   // Buzzer

// Signal handling
if (data == '1') {
    // Helmet detected: Motor ON, LED OFF, Buzzer OFF
    digitalWrite(motorPin, LOW);   // Motor ON
    digitalWrite(ledPin, LOW);     // LED OFF
    digitalWrite(buzzerPin, LOW);  // Buzzer OFF
} else if (data == '0') {
    // No helmet: Motor OFF, LED ON, Buzzer ON
    digitalWrite(motorPin, HIGH);  // Motor OFF
    digitalWrite(ledPin, HIGH);    // LED ON
    // Buzzer alert sequence
}

πŸ“Š Model Performance

Dataset Statistics

  • Training Images: 3,648
  • Validation Images: 372
  • Test Images: 149
  • Classes: 2 (With Helmet, Without Helmet)

Test Results

  • Helmet Detection: 97.7% confidence
  • No Helmet Detection: 88.4% confidence
  • Average Inference Time: ~200ms per image

πŸ”§ Configuration

Model Parameters

  • Confidence Threshold: 0.5
  • Camera Resolution: 640x480
  • Detection Classes: With Helmet, Without Helmet

Arduino Settings

  • Baud Rate: 9600
  • Timeout: 1 second
  • Port: COM5 (configurable)

πŸ› Troubleshooting

Common Issues

  1. Camera not detected

    • Close other applications using camera
    • Try different camera indices (0, 1, 2)
    • Check camera drivers
  2. Arduino connection failed

    • Check COM port in Device Manager
    • Update Arduino drivers
    • Try different COM ports (COM3, COM4, COM5, COM6)
    • Ensure Arduino code is uploaded
  3. Low detection accuracy

    • Ensure good lighting
    • Position 2-3 feet from camera
    • Avoid shadows on face
    • Check image quality
  4. Model loading error

    • Verify helmet.pt exists in models/ folder
    • Check file permissions
    • Reinstall ultralytics if needed

Arduino Troubleshooting

  1. Motor not responding

    • Check relay connections
    • Verify Pin 8 connection
    • Test relay with multimeter
  2. LED not lighting

    • Check 220Ξ© resistor connection
    • Verify Pin 9 connection
    • Test LED polarity
  3. Buzzer not working

    • Check Pin 11 connection
    • Verify buzzer polarity
    • Test with simple tone() function

πŸ“ Usage Examples

Image Detection

# Test helmet detection
python scripts/detect.py input/helmate-on-1.webp

# Test no helmet
python scripts/detect.py input/helmate-off-1.jpg

Live Detection

# Start webcam detection
python scripts/detect.py --webcam

Expected Output

============================================================
HELMET DETECTION TEST RESULTS
============================================================
Total detections found: 1
🟒 With Helmet detected (confidence: 0.98)
Result: βœ… Helmet worn correctly

FINAL TEST RESULT
🎯 βœ… HELMET WORN CORRECTLY
   Safety compliance: PASSED βœ…
   Status: SAFE TO PROCEED

⚠️ Safety Notice

This system is designed for educational and demonstration purposes. Always follow local safety regulations and wear appropriate protective equipment.

πŸ“ž Support

For issues and questions:

  1. Check the troubleshooting section
  2. Verify all connections
  3. Test components individually
  4. Check Arduino serial monitor for debugging

Happy detecting! πŸͺ–βœ¨

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published