Skip to content

asispan/DIY-Kitchen-Gas-Leak-Detector

Repository files navigation

πŸ”₯ DIY Kitchen Gas Leak Detector

AI-Powered Gas Detection System with ElevenLabs Voice Alerts

ElevenLabs License: GPL v3 Python Raspberry Pi Flask

An intelligent gas leak detection system featuring airplane-style AI voice readouts, real-time monitoring, and live camera streaming

Features β€’ Hardware β€’ Installation β€’ Usage β€’ API


πŸ“‹ Overview

This project transforms a Raspberry Pi Zero 2W into an intelligent gas leak detector with professional-grade voice alerts powered by ElevenLabs AI. Inspired by aircraft warning systems, it provides clear, audible notifications for various system states including gas detection, system status, and camera monitoring.

✨ Features

  • 🎀 AI Voice Alerts - ElevenLabs-generated airplane-style voice notifications
  • πŸ” Real-time Gas Detection - MQ-135 sensor monitoring via GPIO
  • πŸ“Ή Live Camera Streaming - Pi Camera or USB camera support with web streaming
  • 🌐 Web Dashboard - Real-time monitoring interface with Socket.IO
  • πŸ“Š System Metrics - CPU, memory, temperature, and network monitoring
  • πŸ”„ Auto-start Service - Systemd integration for automatic startup
  • πŸ” SSH Management - Automatic SSH service control
  • πŸ“ Comprehensive Logging - Detailed system and event logging
  • πŸ”Š Bluetooth Audio - Support for Bluetooth speakers (Echo Dot compatible)

πŸ› οΈ Hardware Requirements

Component Description Notes
Raspberry Pi Zero 2W Main controller Tested on Raspbian Bookworm
MQ-135 Gas Sensor Air quality/gas detection Digital output to GPIO17
Pi Camera / USB Camera Video monitoring Optional but recommended
Power Supply 5V 2.5A minimum Ensure stable power
Optional: LED Status indicator GPIO18
Optional: Bluetooth Speaker Audio output For voice alerts

πŸ”Œ Wiring Diagram

MQ-135 Gas Sensor:
β”œβ”€ VCC  β†’ 3.3V (Pin 1)
β”œβ”€ GND  β†’ GND (Pin 6)
└─ DOUT β†’ GPIO17 (Pin 11)

Optional LED:
└─ LED  β†’ GPIO18 (Pin 12)

πŸš€ Installation

Quick Install

chmod +x install.sh
./install.sh

Manual Installation

1. Install System Dependencies

sudo apt-get update
sudo apt-get install -y \
    python3-flask \
    python3-gpiozero \
    python3-socketio \
    python3-eventlet \
    python3-psutil \
    python3-picamera2 \
    python3-opencv \
    libcamera-apps \
    pigpio

2. Install Python Packages

pip3 install --break-system-packages flask-socketio

3. Configure Bluetooth (Optional)

Copy the example configuration:

cp bluetooth_config.json.example bluetooth_config.json

Edit with your device details:

{
  "target_device": "XX:XX:XX:XX:XX:XX",
  "device_name": "Your-Bluetooth-Device"
}

4. Enable System Service

sudo cp gas-sensor-monitor.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable gas-sensor-monitor.service
sudo systemctl start gas-sensor-monitor.service

πŸ“± Usage

Web Dashboard

Access the monitoring dashboard:

http://<raspberry-pi-ip>:5000

Service Management

# Start service
sudo systemctl start gas-sensor-monitor.service

# Stop service
sudo systemctl stop gas-sensor-monitor.service

# Restart service
sudo systemctl restart gas-sensor-monitor.service

# Check status
sudo systemctl status gas-sensor-monitor.service

# View logs
sudo journalctl -u gas-sensor-monitor.service -f

Manual Operation

cd /home/zero2w1
python3 gas_sensor_app.py

🌐 API Endpoints

REST API

Endpoint Method Description
/ GET Web dashboard interface
/api/status GET Current system and sensor status (JSON)
/api/camera-feed GET Current camera frame (base64)
/api/health-check GET System health information
/api/test-voice GET Test voice alert system
/video_feed GET Live MJPEG video stream

WebSocket Events

  • connect - Client connection established
  • disconnect - Client disconnection
  • status_update - Real-time sensor status updates
  • camera_frame - Live camera frame updates

Example API Calls

# Get system status
curl http://<raspberry-pi-ip>:5000/api/status | python3 -m json.tool

# Get camera feed
curl http://<raspberry-pi-ip>:5000/api/camera-feed

# Health check
curl http://<raspberry-pi-ip>:5000/api/health-check

πŸ“ Project Structure

/home/zero2w1/
β”œβ”€β”€ gas_sensor_app.py          # Main application
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ install.sh                  # Installation script
β”œβ”€β”€ bluetooth_config.json       # Bluetooth configuration (not tracked)
β”œβ”€β”€ bluetooth_config.json.example # Example config
β”œβ”€β”€ templates/
β”‚   └── index.html             # Web dashboard
β”œβ”€β”€ static/                     # Static assets
β”œβ”€β”€ logs/
β”‚   └── gas_sensor.log         # Application logs
└── sounds/                     # Voice alert audio files

βš™οΈ Configuration

Application Settings

Edit gas_sensor_app.py to customize:

# Web server
HOST = '0.0.0.0'
PORT = 5000

# GPIO pins
GAS_SENSOR_PIN = 17
LED_PIN = 18

# Sensor settings
BOUNCE_TIME = 0.1  # Debounce time in seconds

πŸ”§ Troubleshooting

Service Won't Start

# Check service logs
sudo journalctl -u gas-sensor-monitor.service -n 50

# Verify GPIO permissions
sudo usermod -a -G gpio zero2w1

# Check if port is in use
sudo netstat -tlnp | grep :5000

Camera Not Working

# Check camera detection
vcgencmd get_camera

# Test camera manually
libcamera-hello --list-cameras

# For USB cameras
ls -l /dev/video*

GPIO Permissions

sudo usermod -a -G gpio $USER
# Logout and login again

πŸŽ™οΈ ElevenLabs Voice Generation

This project uses ElevenLabs AI-powered text-to-speech for generating realistic voice alerts. The alerts are designed to mimic professional aircraft warning systems for clarity and urgency.

Voice Alert Types

  • 🚨 Gas leak detected
  • βœ… System normal
  • πŸ”„ System starting
  • πŸŽ₯ Camera status updates
  • ⚠️ System warnings

To regenerate voice alerts, use the included script:

python3 generate_alert_sounds.py

⚠️ Important Notes

  • ⚑ Ensure adequate power supply (minimum 2.5A recommended)
  • 🌑️ Monitor system temperature to prevent throttling
  • πŸ”Œ Use 3.3V VCC for MQ-135 sensor (not 5V)
  • πŸ§ͺ Calibrate MQ-135 sensor in clean air before use
  • πŸ” Secure your Raspberry Pi if exposed to network

πŸ“Š System Requirements

  • OS: Raspbian Bookworm (Debian 12)
  • Python: 3.11+
  • RAM: Minimum 512MB (Zero 2W has 512MB)
  • Storage: 8GB+ SD card recommended

🀝 Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

πŸ“„ License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

πŸ™ Acknowledgments


Created by Asis Panda on September 2025 | Version 1.0

About

A DIY kitchen gas leak detector that uses ElevenLabs AI created readout alerts like in airplanes to alert of a gas leak and various other states.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors