Low-Cost Smart Gas Leak Detector with ESP32 + Flutter Mobile App
A real-time, affordable LPG/gas leak monitoring system that detects leaks using MQ-2/MQ-5 sensors, compensates for humidity & temperature false alarms (via DHT11/22), triggers local buzzer/LED, and sends live data + alerts to your phone via MQTT.
Built for kitchens, homes, garages — prevents disasters with smart logic instead of simple threshold triggering.
-
Smart Detection Logic (3-layer):
- Rate of change (sudden spikes)
- Duration (sustained high reading)
- Stability + humidity compensation (avoids false alarms from steam/shower)
-
Local Alarm — Buzzer + LED on device
-
Mobile App (Flutter) — Real-time gas level, humidity, temperature, leak status
-
MQTT — Reliable, low-latency data sync (works over Wi-Fi)
-
Low-Cost — Uses common components (~$10–15 total excluding ESP32)
-
Responsive, trendy dark UI with animations on alert
-
Easy to tune thresholds for your environment
| Component | Recommended Model | Approx. Price |
|---|---|---|
| Microcontroller | ESP32 DevKit / NodeMCU-32S | $5–8 |
| Gas Sensor | MQ-2 or MQ-5 | $2–4 |
| Temp/Humidity | DHT11 or DHT22 | $1–3 |
| Buzzer | Active/Passive | $0.5 |
| LED + resistor | Red 5mm | $0.2 |
| Breadboard + wires | — | $2–5 |
Total estimated cost: $12–25
| Sensor/Pin | ESP32 Pin | Note |
|---|---|---|
| MQ analog out | GPIO 34 | ADC pin |
| DHT data | GPIO 4 | 4.7–10k pull-up resistor |
| Buzzer | GPIO 2 | — |
| LED (anode) | GPIO 5 | 220Ω resistor to GND |
| VCC all sensors | 3.3V or 5V | MQ usually 5V |
| GND | GND | — |
- Install Arduino IDE or PlatformIO
- Add these libraries:
- DHT sensor library
- PubSubClient
- WiFi (built-in)
- Copy code from
/firmware/folder - Update WiFi credentials & MQTT broker (default: broker.emqx.io)
- Upload to ESP32
- Install Flutter SDK (3.24+ recommended)
- Go to
/app/folder - Run:
flutter pub get flutter run
- App connects automatically to the same public MQTT broker
- In clean air → app should show low gas level (~100–200)
- Use lighter gas from ~30–50 cm → after 5–10 seconds → alert triggers
- Boil water nearby → should not false-trigger if humidity compensation tuned
LeakSentry/
├── firmware/ # ESP32 Arduino sketch
│ └── LeakSentry.ino
├── app/ # Flutter mobile application
│ ├── lib/
│ └── pubspec.yaml
├── docs/ # Schematics, photos, tuning guide
├── images/ # Screenshots & wiring diagrams
└── README.md
Edit these in firmware/LeakSentry.ino:
#define ALERT_THRESHOLD 320 // Adjust after seeing clean-air avg
#define HIGH_HUMIDITY 82 // Raise threshold above this %
#define RATE_JUMP 60 // Sudden increase that counts as "fast"
#define MIN_DURATION 5 // Seconds to confirm leak- Add push notifications (Firebase + MQTT trigger)
- Historical charts in app (fl_chart)
- Private MQTT broker support (TLS + credentials)
- Over-the-air (OTA) updates
- Multi-sensor / multi-room support
- Battery-powered version
MIT License — feel free to use, modify, and share!
- Inspired by low-cost IoT safety projects
- Thanks to: PubSubClient, flutter_mqtt_client, DHT library authors
- Built with ❤️ by Khalid