A production‑ready IoT gas leakage detection system using ESP32, MQ gas sensor, FastAPI backend, PostgreSQL, Telegram Bot alerts, Web Dashboard, and Docker deployment.
This project is designed for real‑world deployment in smart homes, laboratories, kitchens, and industrial environments.
- 🔥 Real‑time gas leakage detection (LPG, Methane, Propane)
- 📡 ESP32 Wi‑Fi based sensor communication
- 🚨 Automatic buzzer & LED alerts
- 🤖 Telegram Bot instant notifications
- 📊 Web dashboard for live monitoring
- 🗄️ PostgreSQL database logging
- 🐳 Docker‑based deployment
- 🔐 Environment‑based configuration
MQ Gas Sensor → ESP32 → FastAPI Backend → PostgreSQL
↓
Web Dashboard + Telegram Bot
| Layer | Technology |
|---|---|
| Hardware | ESP32, MQ‑2 / MQ‑5 |
| Firmware | Arduino (C++) |
| Backend | Python, FastAPI |
| Database | PostgreSQL |
| Alerts | Telegram Bot API |
| Frontend | HTML |
| DevOps | Docker, Docker Compose |
Smart-Gas-Leakage-Bot/
│── README.md
│── docker-compose.yml
│── requirements.txt
│── .env.example
│
├── firmware/
│ └── esp32_gas_detector.ino
│
├── backend/
│ ├── main.py
│ ├── config.py
│ ├── database.py
│ ├── models.py
│ └── telegram_bot.py
│
├── dashboard/
│ └── index.html
│
└── docs/
└── system_architecture.png
- ESP32 Development Board
- MQ‑2 or MQ‑5 Gas Sensor
- Active Buzzer
- LED (optional)
- 5V Power Supply
- Open
firmware/esp32_gas_detector.ino - Update Wi‑Fi credentials
- Set backend server IP
- Upload to ESP32 using Arduino IDE
The ESP32 continuously reads gas levels and sends data to the backend every few seconds.
git clone https://github.com/YOUR_USERNAME/Smart-Gas-Leakage-Bot.git
cd Smart-Gas-Leakage-Botcp .env.example .envEdit .env:
DATABASE_URL=postgresql://gasuser:gaspass@db/gasdb
TELEGRAM_TOKEN=YOUR_TELEGRAM_BOT_TOKEN
CHAT_ID=YOUR_CHAT_ID
docker-compose up --buildBackend will be available at:
http://localhost:8800
- Create a bot via @BotFather
- Copy the bot token
- Get your chat ID
- Add both to
.env
🚨 When gas exceeds the safe threshold, an instant Telegram alert is sent.
A lightweight web dashboard displays system status and confirms live monitoring.
Access:
http://localhost:8800
- FastAPI backend
- PostgreSQL database
Fully containerized for easy deployment on:
- VPS
- Local server
- Raspberry Pi
- Flash ESP32 firmware
- Configure
.env - Start Docker containers
- Verify Telegram alerts
- Test gas sensor response
- 📱 Android mobile app
- ☁️ MQTT cloud integration
- 🧠 AI‑based leak prediction
- 📞 SMS & voice call alerts
- 🏭 Industrial multi‑sensor support
MIT License
Abdullahi Bundi
IoT • Embedded Systems • AI • Python • C++
⭐ If this project helps you, please star the repository and share it!