lpg-leak-detect-iot

LPG Leak Detector

There are already lots of projects built on top of the MQ family of sensors and also specifically the MQ6. In my case, the goal here was multifold:

This article comprises of the following sections:

About the MQ6 sensor:

I did not buy this separately but I had one fixed to a commercial household LPG leak detector. That system was old and wasn’t working since quite some time. I had already salvaged parts of it for other things (battery charging circuit). I decided to desolder the MQ 6 and use it my own project. However, I wasn’t able to successfully desolder it so in the end, I just cut out the part of the PCB hosting the sensor. The pins were hardly visible but I managed to solder multicore wires to it and via a heatshrink assembly was able to reasonably protect those delicate connections. The MQ 6 does not have any polarity to its pins so you can decide which is which. Of course you need to respect the A, B and H pin identity but you can decide which is H+ & H-. This explains the working principles of all MQ series sensors. The sensor needs some settling time for its heater – first time use is 24 H but subsequent uses are a few minutes. The heater also has a good current draw (~150 mA); you must power it from an external power source and not from your microcontroller. I have not gone into details of connecting the sensor as many people have done that and it is available via a web search easily. Note that practically you would need to convert the analog OUT readings of the sensor to ppm (parts per million) concentration of the gas (I have not incorporated that in my code). My salvaged MQ6 is shown below resting on a steel bowl.

System Overview:

Goal was to design a system as shown in the figure below:

The sensor would be put in a compartment where the LPG cylinder resides. It needs to be as low as possible as the LPG gas itself is heavier than air and tends to collect at the bottom first, in case of any leakage. Considering safety and also the fact that this compartment is not easy to access frequently, I decided to lay a cable from the MQ6 to the Detector circuit. This also allows me enough flexibility to put the Detector where I wish to. I used extension cord cables and soldered them to the four pins of the MQ6 – A, B, H+ and H-. These cables entwined together (each with its own shielding), then lead into the Detector. I used cable ties to manage the cable bulk and avoid it spreading out and becoming snagged in something. The Detector overview is below.

The MQ6 cable ingress is indicated. In addition there is a voltage divider to allow the Node MCU’s analog IN to measure the voltage level change due to gas levels. Apart from that, there is a power supply that supplies 3.3V to the Node MCU and 5V to the MQ6, each separate and independent. There are 3 LEDs; green LED indicates power to the system, a second blue LED blinks every time the Detector and the client script successfully communicate (COMM) and the third red LED lights up when the detected LPG level crosses a set threshold (CRIT). The circuit was first prototyped as a loose breadboard based system and a video and image is shown below. Note that the video shows the Node MCU powered off a battery but in the final circuit, I chose to run everything off a wall wart. Also the battery isn’t really connected if you look carefully. Everything was powered by a power module.

A video of the above setup:

The Node MCU is connected to an 802.11 router and is also hosting a simple HTTP based web server inside it. The code is explained later in this article. The Wi-Fi network that the Detector connects to is also connected to by a laptop. In this case, my laptop is running Win 10 and a Debian Linux Win 10 app is running on top of it. There is a python script running under Debian which periodically requests the LPG level from the Detector, over HTTP. The script is explained later in this article itself.

Detector Code:

This code runs in the Node MCU. Full source is available here. The code logic is as follows:

Python Client Script Code:

The client is pretty simple and written in python. The full source is here. The code logic is as follows:

Results:

Before we go into the results, here are some more pictures of my setup. The first one below shows the Detector system partly packaged into a cardboard box. The black part at the bottom of the image (below the LEDs) where many wires are routed is a header acting as a common ground plane:

Here is a close-up of the MQ6 assembly itself. I have placed the MQ6 into a thick PVC pipe and topped it with a plastic cap having perforations. This is essentially to protect the MQ6.

Finally, a picture of the Detector box closed up. The green and white cables are the 10 ft cables going to the MQ6 assembly above.

The output was pretty good and relatable across readings and sessions. Here are the graphs of runs of a few hours. The raw CSV’s are available here.

The large values (circled red) at the very start seen on the graph are the heater stabilizing. It takes a few minutes to do that and provide stable values. After that happens, the system is ready to detect. Below is a graph where leak detection was made. It is quite evident from the graph itself.

Key Learning: