A real-time combustible gas monitoring system using ESP8266, MQ-6 sensor, and GSM module for SMS alerts. This project provides both hardware sensing capabilities and a web-based dashboard for monitoring gas levels.
- Real-time gas level monitoring with MQ-6 combustible gas sensor
- SMS alerts via GSM module when dangerous gas levels are detected
- Responsive dashboard with dark/light mode and real-time updates
- Historical data tracking with 24-hour gas level charts
- Alert management system with acknowledgment capability
- Battery and signal monitoring for the IoT device
- ESP8266 (NodeMCU or similar)
- MQ-6 Gas Sensor
- SIM900 GSM Module
- SIM card with SMS capability
- Power supply (for ESP8266 and GSM module)
- Jumper wires
- Python 3.13+
- Flask and related packages
- Arduino IDE with ESP8266 support
- Web browser with JavaScript enabled
-
Clone this repository:
git clone https://github.com/yourusername/gas-detection-system.git cd gas-detection-system -
Install Python dependencies:
pip install -r requirements.txt -
Create necessary directories:
mkdir -p data
-
Open the Arduino IDE
-
Install required libraries:
- ESP8266WiFi
- ESP8266HTTPClient
- ArduinoJson
- SoftwareSerial
-
Open the ESP8266 sketch from the
arduinodirectory -
Update the following variables:
- Wi-Fi credentials (
ssidandpassword) - Server URL (
serverUrl) - Phone numbers for SMS alerts (
phoneNumbers)
- Wi-Fi credentials (
-
Connect your ESP8266 to your computer
-
Upload the sketch to your device
- Connect the MQ-6 sensor to ESP8266
- Connect the SIM900 GSM module:
- Optional: Connect the buzzer
- Optional: Connect an external LED
-
Start the backend server:
python main.py -
Access the dashboard: Open your web browser and navigate to
http://localhost:5000 -
Power on your ESP8266 device
-
The system should automatically begin monitoring gas levels and displaying them on the dashboard
- Real-time gas level indicator with status (Safe, Warning, Danger)
- Historical chart showing 24 hours of gas level readings
- System status panel showing battery level and connectivity
- Active alerts panel with acknowledgment option
- Dark/light mode toggle for comfortable viewing
The system exposes several API endpoints:
GET /api/current-reading- Get the latest gas readingGET /api/gas-readings- Get historical gas readings (default 24h)GET /api/alerts- Get all active alertsGET /api/system-status- Get device status informationGET /api/gsm-config- Get GSM/SMS configurationPOST /api/sensor-data- Submit new sensor readings from ESP8266POST /api/alerts/{id}/acknowledge- Acknowledge an alertPOST /api/alerts/{id}/sms-status- Update SMS status for an alert
The default alert thresholds for the MQ-6 gas sensor are:
- Safe: 0-29 PPM
- Warning: 30-49 PPM
- Danger: 50+ PPM
These thresholds can be adjusted in the utils/gas_utils.py file based on your specific requirements and the gases you're monitoring.
Edit the get_status_from_ppm function in utils/gas_utils.py:
def get_status_from_ppm(ppm):
if ppm < 30: # Change this value
return "safe"
elif ppm < 50: # Change this value
return "warning"
return "danger"Edit the phoneNumbers array in the ESP8266 sketch:
String phoneNumbers[] = {
"+1234567890", // Replace with actual numbers
"+0987654321" // Add more numbers as needed
};The MQ-6 sensor requires calibration for accurate readings. In the ESP8266 code, adjust the conversion formula in the readGasSensor() function:
// Convert analog reading to PPM
float ppm = 50.0 * voltage; // Adjust this formula based on calibration- Ensure Wi-Fi credentials are correct
- Verify the server is running and accessible
- Check the server URL includes "http://" and correct IP/port
- Ensure SIM card is active and has credit
- Check power supply (3.7-4.2V required)
- Verify TX/RX connections are correct
- Monitor serial output for AT command responses
- Allow 24-48 hours for initial warm-up and stabilization
- Verify analog pin connection
- Check power supply (5V required)
- Check if port 5000 is already in use
- Verify database directory has write permissions
- Check log messages for detailed errors
- Flask - Web framework
- Chart.js - JavaScript charting library
- Tailwind CSS - CSS framework