How to Make a Low-Cost LPG or Methane Gas Leakage Detector
Although natural gas is a safer and more efficient source of energy, it can cause gas poisoning if it leaks, leading to health issues such as fatigue, headache, shortness of breath (hypoxia), etc. Unfortunately, a slow gas leak or build-up is hard to detect, especially if the gas has no smell, such as natural gas or carbon monoxide.
In this DIY guide, we will build a gas sensor that can detect harmful gases, such as methane, propane, LPG, and carbon monoxide. It also sends you alerts to your smartphone or Echo speakers.

Things You Will Need
You will need the following components to build a DIY smart wireless gas leak detector.
You will also need aHome Assistant server setup on a Raspberry Pior any compatible hardware. If interested, you canlearn everything about Home Assistantand see how it works before getting started.

Step 1: Compile the Firmware
To compile the firmware, install theESPHome add-onin Home Assistant. Once installed, follow these steps to compile the firmware for D1 Mini or NodeMCU.
Update the Wi-Fi credentials:

Then paste the following code just below thecaptive portal:
You can update thename:field in the code as per your convenience. The code should look like the screenshot below.

Once the code is ready, you’re able to clickSave > Install.SelectPlug into this computerfrom the options. This will start compiling the firmware and may take roughly 10 minutes to finish.
Once finished, clickDownload projectto download the compiledgas-leakage-factory.binfirmware file.

Step 2: Flash the Firmware
To flash the firmware, you could use the web-based flash tool. The steps are as follows:
After the firmware is flashed, go to theESPHomedashboard in Home Assistant and check thegas-leakagedevice. It should showONLINE.
You may also download and use theESPHome Flashertool to flash thegas-leakage-factory.binfirmware file to your NodeMCU or D1 Mini board.
Step 3: Add Gas Leakage Sensor to Home Assistant Dashboard
Follow these instructions to add the sensor to the Home Assistant dashboard:
That’s it. The device will be added to the selected Home Assistant dashboard. Next, you can connect the MQ-2 gas sensor to the microcontroller.
Step 4: Connect the MQ-2 to Microcontroller
Refer to the following diagram to connect the MQ-2 gas sensor to the D1 Mini or NodeMCU microcontroller board.
The connections are as follows:
Once connected, you may check the updated reading in the Home Assistant dashboard. You can test the sensor by exposing it to smoke or gas. Be careful! Wear a mask and do not smell the gas or smoke. The percent value should increase in the Home Assistant dashboard.
Calibrate the Gas Sensor
While testing the sensor near gas or smoke you want to detect, you should also adjust or calibrate the sensor. Using a small screwdriver, you’re able to rotate the preset on the MQ-2 sensor anticlockwise to decrease sensitivity or clockwise to increase sensitivity.
Put the sensor near the smoke or gas and look for the other LED to glow or check the sensor value in the Home Assistant dashboard and adjust the sensitivity according.
For example, the sensor we built normally shows 10-15%. When we exposed it to a little amount of LPG (methane) gas, the value rose to 35%+. This was the sweet spot for us, after which we installed it in our kitchen, close to the chimney.
Create Automation to Send Gas Leak Alerts
Once you have calibrated and adjusted the sensor sensitivity, you can create automation in the Home Assistant to receive notifications on your smartphone or voice alerts through Alexa smart speaker or Google Assistant.
To create an automation, go toSettings > Automations & Scenesand clickCreate Automation. ChooseStart with empty automationand then click the three dots at the top left. Now, chooseEdit in YAMLand paste the following code.
Next, click thethree dotsagain and chooseEdit in visual editor. In the visual editorwindow, choose and change your Gas Leak sensor and the devices where you want to send notifications.
For instance, the above-shared automation code sends anotification alertto our Android or iOS device and also announces the voice alert viaAlexa speakers(Echo Dot and Echo Show devices installed in the house) when the gas level exceeds the 30% threshold. Usually, the sensor remains at 10-15%.
You need to set up theAmazon AlexaandGoogle Assistantintegrations in Home Assistant to use them for notifications and voice alerts.
Prevent Hazards and Save Money
It’s important to keep the main regulator switch off while the gas stove is not in use, especially when you go to sleep. Thankfully, a gas sensor, such as the one we built, can help you prevent hazards due to leakage of gas and safeguard your home and family. Plus, it will save you from inflated bills that may end up at your door due to gas leakage.
Learn how to build a smart IoT-based energy monitoring device to see real-time energy usage right on your smartphone.
You can block out the constant surveillance and restore your privacy with a few quick changes.
Free AI tools are legitimately powerful; you just need to know how to stack them.
These plugins will make you wonder why you used Photoshop in the first place.
Freeing up vital memory on Windows only takes a moment, and your computer will feel much faster once you’re done.
These films will leave you questioning humanity, but also wanting more.