An intelligent security system running on Raspberry Pi 4 that uses computer vision and AI to detect intrusions, differentiate between humans and animals, and send instant alerts via Telegram.
- Dual Motion Detection: PIR sensor + OpenCV motion detection for reduced false positives
- AI Classification: YOLOv5 distinguishes between people and animals
- Smart Alerts:
- 🚨 CRITICAL: Person detected (immediate alert)
⚠️ HIGH: Person + Animal detected- ℹ️ LOW: Animal only
- Remote Control: Full system control via Telegram bot
- Live Streaming: Web dashboard with real-time video feed
- Local Processing: All AI runs on-device, no cloud dependency
| Component | Specification | Purpose |
|---|---|---|
| Microcontroller | Raspberry Pi 4 (2GB RAM) | Main processor, runs AI |
| Camera | USB Webcam | Video capture |
| Motion Sensor | PIR HC-SR501 | Infrared motion detection |
| Storage | MicroSD 32GB Class 10 | OS and data storage |
| LEDs | Green + Red 5mm | Status indicators |
| Buzzer | Active 5V | Audio alarm |
| Power Supply | 5V/3A USB-C | Power adapter |
- Language: Python 3.9+
- Computer Vision: OpenCV 4.8
- AI Framework: Ultralytics YOLOv5 nano
- Web Server: Flask 3.0
- Bot Framework: python-telegram-bot 20.6
- GPIO Control: RPi.GPIO 0.7
git clone https://github.com/cozel6/smart-security-system.git
cd smart-security-systembash setup.shThis will:
- Install system dependencies
- Create Python virtual environment
- Install Python packages
- Setup GPIO permissions
- Download YOLO model
cp .env.example .env
nano .envEdit .env with your credentials:
TELEGRAM_BOT_TOKEN- Get from @BotFatherTELEGRAM_CHAT_ID- Get from @userinfobot
python3 main.py --armAccess web dashboard at: http://[raspberry-pi-ip]:5000
| Command | Description |
|---|---|
/start |
Initialize bot |
/help |
Show command list |
/arm |
Arm the system |
/disarm |
Disarm the system |
/status |
Get system status |
/snapshot |
Get current camera frame |
/logs |
View recent events |
Access at http://[raspberry-pi-ip]:5000
Features:
- Live MJPEG video stream
- System status (armed/disarmed)
- Arm/Disarm controls
- Recent detections
- System metrics (CPU, RAM, temp)
┌─────────────────────────────────────────────────────────────┐
│ System Manager │
│ (Main Orchestrator) │
└─────────────────────────────────────────────────────────────┘
│ │ │ │
┌────▼────┐ ┌────▼────┐ ┌────▼────┐ ┌────▼────┐
│ Hardware│ │Detection│ │ Alerts │ │Streaming│
└─────────┘ └─────────┘ └─────────┘ └─────────┘
│ │ │ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │ │ │
CAM PIR LED BZ MOT YOLO TELE ALERT WEB VIDEO
Threading Model:
- Thread 1: Camera capture (continuous)
- Thread 2: Detection pipeline (PIR → Motion → YOLO)
- Thread 3: Alert manager (queue processing)
- Thread 4: Telegram bot (polling)
- Thread 5: Flask server (web dashboard)
| Metric | Target | Actual |
|---|---|---|
| Response Time | < 3 sec | TBD |
| Streaming FPS | 10-15 FPS | TBD |
| YOLO Inference | 200-300ms | TBD |
| CPU Usage | < 85% | TBD |
| RAM Usage | ~700MB | TBD |
| Detection Accuracy | 75-85% | TBD |
- Romanian README - Full documentation in Romanian
- Project Documentation - Complete project plan
- Architecture - System architecture diagrams
- Setup Guide - Detailed installation instructions
- API Reference - API endpoints and commands
- GPIO Wiring - Hardware connection diagram
Run unit tests:
pytest tests/ -vRun individual test suites:
pytest tests/test_hardware.py -v
pytest tests/test_detection.py -v
pytest tests/test_alerts.py -v# Test camera
python3 -c "import cv2; cap = cv2.VideoCapture(0); print('OK' if cap.isOpened() else 'FAILED')"sudo usermod -a -G gpio $USER
# Reboot required# Model will auto-download on first run
# Or manually download:
cd models
wget https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5n.ptDevelopers:
- Cosmin - @cozel6
- Daniel - @danielbuilds27
Timeline: October 2024 - January 2025 (12 weeks) Institution: MIPE Faculty Project
This project is for educational purposes.
- YOLOv5 by Ultralytics
- OpenCV community
- Raspberry Pi Foundation
- Python Telegram Bot library
For issues and questions:
- Create an issue in the repository
- Check documentation in
docs/ - Review troubleshooting section
Made with ❤️