Home IoT Hub Series · 10
[Part 10] Get warned before gas smell becomes obvious - MQ-5 kitchen gas node
Use an MQ-5 sensor node as a gas leak warning slot for the hub.
This node adds gas-leak warning using an MQ-5 module. It is a practical warning slot, but it is not a certified safety device.
MQ sensors need warm-up time and stable power. Install it where air can reach the sensor, not inside a sealed box.
![[Part 10] Get warned before gas smell becomes obvious - MQ-5 kitchen gas node hero image](/iot-lab/assets/gas-leak-mq5-hero.png)
This article is part of the Home IoT Hub system connected to the central NodeMCU server built in Part 2: Building the Brain. The MQ-5 sensor updates the hub warning slot when gas concentration rises, which then drives buzzer logic. The collected data is sent over the local
IoT_Hub_Net network and updates slot 7 for gas leak warning on the central server (/set?no7=value), becoming part of the decision pipeline for the 20-channel smart-home controller.Parts and cost
| Part | Qty | Unit price |
|---|---|---|
| Wemos D1 Mini | 1 pc | $1.50 |
| MQ-5 gas sensor module | 1 pc | $1 |
| Jumper wires 3 pc | — | — |
| Total | $2.50 |
Pin wiring
| Sensor / module | Board pin |
|---|---|
| VCC | 5V (VU pin) |
| GND | GND |
| AOUT | A0 (analog) |
Full code
#include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> const char* ssid = "IoT_Hub_Net"; const char* password = "iothub1234"; const char* hubURL = "http://192.168.1.1"; #define GAS_PIN A0 #define SLOT_NO 7 #define THRESHOLD 400 // suspect a leak above this value #define INTERVAL 5000 void setup() { Serial.begin(115200); pinMode(GAS_PIN, INPUT); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); Serial.print("Connecting to IoT_Hub_Net"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected!"); Serial.println("MQ-5 warming up (60s)..."); delay(60000); // note Serial.println("Ready."); } void loop() { int raw = analogRead(GAS_PIN); int leak = (raw > THRESHOLD) ? 1 : 0; Serial.print("MQ-5: "); Serial.print(raw); Serial.print(" -> "); Serial.println(leak ? "LEAK!" : "OK"); WiFiClient client; HTTPClient http; String url = String(hubURL) + "/set?no" + String(SLOT_NO) + "=" + String(leak); http.begin(client, url); http.GET(); http.end(); Serial.println("HTTP -> " + url); delay(INTERVAL); }
Upload and check
Connect the Wemos D1 Mini to the PC with a USB data cable, select the ESP8266 board and port in the Arduino IDE, upload the sketch, then open Tools → Serial Monitor and set the baud rate to 115200.
Serial Monitor
After uploading, open Tools → Serial Monitor in the Arduino IDE and set the baud rate to 115200. The following is an example Serial Monitor flow for checking normal operation. This is not a real screenshot. It shows MQ-5 warm-up, threshold checking, and slot 7 warning updates.
[BOOT] Home IoT Node #10 - MQ-5 gas warning [WARMUP] MQ-5 heater active, baseline=184 [SENSOR] gas_raw=221 threshold=420 [FILTER] alcohol_vapor_guard=PASS [HTTP] GET /set?no7=0 [HUB] 200 OK - slot no7=NORMAL [LOOP] next gas sample in 5000 ms
- If
Connectedorconnectedappears, the Wi-Fi step passed. - If
HTTP 200or200 OKappears, the value reached the brain server. - If the value does not update, check both the slot number in the URL and the sensor wiring.
Build notes
- Use the serial monitor to observe normal room values first. Set the warning threshold after you understand the baseline in your home.
- Power on the hub brain first so the node can join
IoT_Hub_Net. - Use the same slot number written in the source code.
- Open the serial monitor at 115200 baud and confirm
HTTP 200. - If the value does not appear on the hub, recheck wiring, GPIO number, and Wi-Fi connection.
Where and How to Use the MQ-5 Gas Leak Sensor
The MQ-5 detects combustible gases such as LPG, LNG (city gas), and butane, sounding a buzzer at dangerous concentrations as an early-warning helper device. Paired with the other nodes of your home IoT hub, it can go beyond a local beep to push a smartphone alert.
Troubleshooting checkpoints
The node code can look short, but real home installation is affected by placement, power, Wi-Fi quality, and sensor noise. Check these points before letting the node become a decision input for the brain server.
| Symptom | Likely cause | Field fix |
|---|---|---|
| Alerts keep firing right after installation | The MQ sensor heater has not stabilized yet | Treat the first 24-48 hours as burn-in and disable alerts or log only. |
| Cooking wine or alcohol vapor triggers alerts | MQ-5 is also sensitive to alcohol vapor | Place it at least 1.5 m away from the stove side or ceiling area and ignore short spikes. |
| The value does not fall quickly | Gas or vapor remains in the sensor chamber and recovery is slow | Clear alerts only after normal readings continue for a fixed duration. |
| The ESP8266 reboots unexpectedly | The MQ-5 heater current makes a weak USB supply sag | Use a stable 5V supply for the sensor and keep common GND while leaving enough power margin. |
Use Cases
- Early kitchen leak warning: If you forget to close the stove valve or a slow leak develops, the buzzer reacts before your nose does.
- Boiler and utility rooms: Unattended spaces benefit most from constant machine monitoring.
- Single-person and elderly safety: In homes where someone lives alone or has a dulled sense of smell, it catches leaks that are easy to miss.
- Alerts while away: Send readings to your server through the hub and you'll know instantly on your phone if a leak happens while the house is empty.
Recommended Placement
Height changes completely depending on the gas type. This is the most important point.
- LPG (propane/butane): Heavier than air, so it sinks to the floor. Mount the sensor about 30cm above the floor.
- City gas (LNG/methane): Lighter than air, so it rises. Mount the sensor about 30cm below the ceiling.
- Keep 1-3m from gas appliances (stove, boiler). Too close causes frequent false alarms while cooking; too far slows the response.
- Avoid placing it right in front of vents, windows, or the range hood, where airflow disperses gas and delays detection.
Practical Tips and Cautions
- Warm-up: After power-on, allow at least 2-3 minutes; for precise readings, let it stabilize 24-48 hours. Don't trust the value right after startup.
- Sensitivity tuning: Set the threshold with the onboard potentiometer, but only as sensitive as your normal cooking environment allows without false alarms.
- False triggers: It can also react to cooking smoke, oil vapor, alcohol, sprays, and detergent fumes. Filter these out with placement and sensitivity.
- Lifespan and replacement: The sensing element is a consumable. Accuracy degrades, so replace it roughly every 2-3 years.
- Supplementary only: The MQ-5 is a hobby/auxiliary alarm. It cannot replace a certified home gas detector; leave life-safety to certified products.
Frequently Asked Questions
Q. My home uses city gas — where should I mount the sensor? City gas (LNG) is light and rises, so install it about 30cm below the ceiling. If you use LPG instead, mount it near the floor (about 30cm).
Q. It goes off every time I cook — is it broken? Not broken; the sensitivity is too high or it's too close to the appliance. Move it 1-3m away and lower the sensitivity with the potentiometer.
Q. Can this replace buying a real gas detector? No. The MQ-5 is a supplementary alarm, not a substitute for a certified gas detector. Always use both together.
This article is part of the 20-channel Home IoT system built from the Part 2 central brain server and the distributed edge nodes in Parts 3-19. Use this map to check the slot and sensor flow across the series.
[Part 1] Home IoT Hub overview[Part 2] Central brain server · slots 1-20[Part 3] Stop guessing room comfort · slots 1/2[Part 4] Did I close the door? · slots 9[Part 5] Is the fridge really cooling? · slots 12[Part 6] Should I open the window? · slots 3[Part 7] Stop bathroom mold before it starts · slots 19[Part 8] Is the boiler actually running? · slots 5/17[Part 9] Did I leave the gas stove on? · slots 6[Part 10] Get warned before gas smell becomes obvious · slots 7[Part 11] Catch flame signs while away from home · slots 8[Part 12] Is bad air making you foggy? · slots 13/14[Part 13] Why is the power bill so high? · slots 15[Part 14] Is water leaking, and how much are we using? · slots 16[Part 15] Do not leave windows open in the rain · slots 18[Part 16] Are the lights off and the door locked? · slots 11/10[Part 17] Control the air conditioner from the IoT hub · slots 4[Part 18] Is the dog bowl empty? · slots 20[Part 19] Cool the room only when someone is there · slots 1/4[Part 20] The house finally fits on one screen · slots all