Skip to content

Raspberry Pi 5 security system combining real-time YOLOv8 object detection and YAMNet audio classification, with alerts via LED, alarm and email notifications.

Notifications You must be signed in to change notification settings

halahleis/AI-security-system

Repository files navigation

Raspberry Pi AI Security System

This project consists of an AI-powered real-time security system using YOLOv8 and YAMNet on Raspberry Pi 5, capable of:

  • Detecting guns and knives using a custom-trained YOLOv8 model
  • Detecting suspicious sounds (screaming, crying, gunshot, etc.) using Google's YAMNet model
  • Sending email alerts
  • Activating a warning LED
  • Playing a siren alarm sound
  • Logging events locally

How It Works

Component Description
image_detect.py Uses YOLOv8 for weapon detection via usb camera
audio_detect.py Uses YAMNet for screaming/gunshot detection via mic
GPIO (LED + sound) Alerts via LED and alarm speaker
Gmail API Sends email when a weapon or suspicious sound is detected
Log Files Events are recorded locally for traceability

Hardware Setup

  • Raspberry Pi 5
  • Monitor
  • Keyboard + Mouse
  • USB Webcam (for YOLOv8 detection)
  • USB Microphone (for YAMNet audio classification)
  • Speakers
  • LED + 470 Ohm Resistor (on GPIO pin 18)
  • Breadboard + Wires

Hardware Setup

🎥 Demo Setup Video


Project Structure

AI-security-system/
├── yolov8_image_classification/
│ ├── image_detect.py
│ └── best.pt
│
├── yamnet_audio_classification/
│ ├── audio_detect.py
│ └── yamnet_model/
│
├── assets/
│ └── alarm.WAV
│
├── media/
│ ├── setup.jpg
│ ├── setup_video.mp4
│ ├── knife_gun_detection.mp4
│ ├── demo_with_led.mp4
| ├── scream_detection.mp4
│ ├── emails_sent_terminal_output.png
│ ├── emails_sent_screenshot.png
│ └── funny_demo.mp4
│
├── .env.example
├── requirements.txt
└── README.md

Installation

  1. Clone the repository
git clone https://github.com/halahleis/AI-security-system.git
cd AI-security-system
  1. Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt

Environment Variables

Create a .env file in the root of your project with:

GMAIL_USER=your_email@gmail.com
GMAIL_APP_PASSWORD=your_app_password

Note: To get an app password 👉 How to create a Gmail App Password


Running the System

Weapon Detection via Camera (YOLOv8)

cd yolov8_image_classification
python image_detect.py
  • Displays annotated detection frame
  • Triggers alarm + LED + email when knife or gun is detected
  • Logs detections to image_detection_log.txt

Suspicious Sound Detection (YAMNet)

cd yamnet_audio_classification
python audio_detect.py
  • Plots real-time confidence of top 5 sound classes
  • Triggers alarm + LED + email when suspicious sounds are detected ("crying, sobbing", "screaming", "shout", "gunshot", "explosion")
  • Logs detections to audio_detection_log.txt

Email Alert

Terminal Output:

Terminal Output

Emails Received:

Emails Received


Event Logging

Both detection scripts log alerts to:

  • image_detection_log.txt
  • audio_detection_log.txt

Each log includes a timestamp and detected event.


Customization

  • To modify the audio classes that trigger alerts, edit these two sections in audio_detect.py:
suspicious_keywords = ["crying, sobbing", "screaming", "shout", "gunshot", "explosion"]
email_sent_flags = {
    "crying, sobbing": False,
    "screaming": False,
    "shout": False,
    "gunshot": False,
    "explosion": False
}
  • The best.pt model was trained on a small custom dataset of around 700 images (after augmentation) for two classes: knife and gun. While sufficient for demonstration purposes, it is not robust for real-world deployment. For improved performance, consider training a yolo model on a larger, more diverse dataset.

Bonus: Demo Videos

Type Demo
Knife/Gun Detection 🎥 Watch
Knife/Gun Detection + LED 🎥 Watch
Scream Detection 🎥 Watch
Fun Demo 🎥 Watch

I especially hope you enjoy watching the last demo as much as I enjoyed making it! 😊


Credits


Author

Made with ❤️ by Hala Hleiss

About

Raspberry Pi 5 security system combining real-time YOLOv8 object detection and YAMNet audio classification, with alerts via LED, alarm and email notifications.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages