An AI-powered helmet detection system using YOLOv8 for safety compliance monitoring with Arduino hardware integration.
- 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
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
- Python 3.8+
- Arduino IDE
- Webcam (for live detection)
-
Install Python dependencies
pip install -r requirements.txt
-
Verify installation
python -c "import ultralytics, torch, cv2; print('β All dependencies installed')"
-
Test with a single image
cd helmet-detector python scripts/detect.py input/helmate-on-1.webp -
Start live webcam detection
python scripts/detect.py --webcam
- β 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 Uno (or compatible)
- Motor (via relay) - simulates bike engine
- Red LED (with 220Ξ© resistor) - warning indicator
- Buzzer - alert system
- USB Cable - for serial communication
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)
-
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
-
Upload Arduino Code
- Open Arduino IDE
- Open
helmet-detector/helmet_control_fixed.ino - Select correct board and port
- Click Upload
-
Find COM Port
- Open Device Manager (Windows)
- Look for "Arduino" under "Ports (COM & LPT)"
- Note the COM port number (e.g., COM5)
-
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
- Open
// 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
}- Training Images: 3,648
- Validation Images: 372
- Test Images: 149
- Classes: 2 (With Helmet, Without Helmet)
- Helmet Detection: 97.7% confidence
- No Helmet Detection: 88.4% confidence
- Average Inference Time: ~200ms per image
- Confidence Threshold: 0.5
- Camera Resolution: 640x480
- Detection Classes: With Helmet, Without Helmet
- Baud Rate: 9600
- Timeout: 1 second
- Port: COM5 (configurable)
-
Camera not detected
- Close other applications using camera
- Try different camera indices (0, 1, 2)
- Check camera drivers
-
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
-
Low detection accuracy
- Ensure good lighting
- Position 2-3 feet from camera
- Avoid shadows on face
- Check image quality
-
Model loading error
- Verify
helmet.ptexists inmodels/folder - Check file permissions
- Reinstall ultralytics if needed
- Verify
-
Motor not responding
- Check relay connections
- Verify Pin 8 connection
- Test relay with multimeter
-
LED not lighting
- Check 220Ξ© resistor connection
- Verify Pin 9 connection
- Test LED polarity
-
Buzzer not working
- Check Pin 11 connection
- Verify buzzer polarity
- Test with simple tone() function
# Test helmet detection
python scripts/detect.py input/helmate-on-1.webp
# Test no helmet
python scripts/detect.py input/helmate-off-1.jpg# Start webcam detection
python scripts/detect.py --webcam============================================================
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
This system is designed for educational and demonstration purposes. Always follow local safety regulations and wear appropriate protective equipment.
For issues and questions:
- Check the troubleshooting section
- Verify all connections
- Test components individually
- Check Arduino serial monitor for debugging
Happy detecting! πͺβ¨