Sniff, Sniff!

Portable LPG Leak Detector

Johann Wyss

Issue 17, November 2018

This article includes additional downloadable resources.
Please log in to access.

Log in

With the sausage sizzle season upon us, it’s important to ensure the gas bottle, hose lines and regulator on the BBQ are not leaking to avoid wasting gas, or even worse, the risk of explosion. Here’s a clever project to help detect the presence of LPG gas.

BUILD TIME: 4-5 Hours

The Broad Overview

With Summer and therefore the BBQ season approaching quickly, I wanted to build a simple handheld and portable device that can detect small gas leaks when connecting LPG gas bottles. When I originally started to investigate how to do this I expected it would be quite challenging, however, I came across the MQ range of sensors which allows you to easily detect a large number of gases.

The MQ range of sensors allows the user to detect all manner of gases from Alcohol to Ozone. Follow the chart shown of the sensor code and what gases it can detect.

I have chosen the MQ-6 sensor for this project to detect LPG, however, I have designed the circuit to be easily adapted for other sensors. I want the flexibility for users to modify it easily to detect the gas of their choice by using the sensor which correlates to the gas they wish to detect. For example, if you wanted a way to detect the presence of hydrogen gas while charging batteries or for C02 leaks in your home bar system etc, you could just use the sensor that correlates to that specific gas, in this case the MQ-8 or MG-811.

I should point out that some sensors need higher or lower heater voltages, so it may not be a straightforward sensor swap. However, the case and code will for the most part need minimal modification regardless of the sensor.

How It Works

The heart of this device is the MQ–6 LPG/Isobutane/Propane Gas sensor. This sensor is remarkably sensitive to low concentrations between 300–10000ppm of natural gases. It provides an analog output voltage by forming a voltage divider with the RL resistor. The resistance of the sensor changes as the concentration of the target gas changes. This provides a fairly linear output which is then read by the ADC (analog to digital converter) in the microcontroller.

The ADC then converts the voltage into a numerical representation which can then be converted into a reading in PPM (parts per million).

From there we need a way to display the data, for this project I opted to use the Sparkfun Micro OLED breakout sold at Core Electronics.

I wanted to make the device portable, so a lithium battery was required and therefore a lithium charging circuit. It also needs a way to step the voltage up from the 3.2V–4.2V lithium cell to the 5V required for the sensor’s heater.

The OLED, however, requires only 3.3V, therefore I decided it would be easiest to use an Arduino Nano as it has a built-in 3.3V regulator, and as such, would not need any accompanying circuitry.

CodeGas Sensitivity
MQ–2Methane, Butane, LPG, smoke
MQ–3Alcohol, Ethanol, smoke
MQ–4Methane, CNG gas
MQ–5Natural gas, LPG
MQ–6LPG, Propane, Butane
MQ-7Carbon Monoxide
MQ–9Carbon monoxide, Flammable Gasses
MQ–135Benzene, Alcohol, Smoke
MQ–136Hydrogen Sulfide
MQ–138Benzene, Toluene, Alcohol, Acetone, Propane, Formaldehyde, Hydrogen
MG-811Carbon Dioxide

The Fundamental Build:

The Prototype

Parts Required:JaycarAltronicsCore Electronics
1 x MQ6 Gas Sensor--POLOLU-1481
1 x Arduino Compatible NanoXC4414Z6372CE05101
1 x OLED Display--LCD-13003
1 x TP4056 Lithium Charging ModuleXC4502Z6388-
1 x Boost Converter^XC4512Z6366CE05174
1 x Slide SwitchSS0852S2010PRT-14330
1 x 14500 Lithium BatterySB2301S4980-
1 x 20k Ohm 1/4W Resistor*RR0603R7589-

Parts Required:

* Quantity shown, may be sold in packs. You'll also need breadboard, hook-up wire, prototyping hardware and screws.

^ For this project, I used the MT3608 from IC Station, which is what I had available (They have an adjustable output so come in very handy). The module stocked at Jaycar, Core Electronics and Altronics is perfectly suitable, however, you may need to remove the USB socket and wire the circuit directly from the USB + and – through-holes.

Like many of my other projects, I prefer to prototype the circuit on a breadboard first to prove the circuit works. This project represents one of the very few times, for me at least, where the prototype is exactly the same as the final circuit. Absolutely no changes were needed to progress from the prototyping stage to the final product.

If you do intend to build a breadboard version, I highly recommend you purchase an MQ-6 sensor built onto a PCB via a breakout board. This makes it substantially easier to build.

You will, of course, still need to purchase the sensor without the breakout board if you intend to use the 3D printed enclosure.

OLED Display

The first point of call with the project is to set the required jumpers for the display. This particular OLED can be controlled via SPI or I2C. SPI is very fast and requires many data lines and therefore many wires, however, I2C is fairly slow but only requires 2 data lines.

Since this speed isn’t paramount for this project I’m going to go with using the I2C protocol.

To set the OLED display up to use this protocol we need to set a few jumpers on the rear of the PCB. It’s just a simple matter of creating a solder bridge across a few small pads, as shown in the images here.

So, in closing to configure the Micro OLED display to use the I2C protocol, the jumpers need to be set to the following configuration.

  • D1 and D2 need to be shorted together
  • DC needs to be set to 1
  • BS1 needs to be set to 1 & BS2 needs to be set to 0

After setting the jumpers we can then finish making the required connections.

GNDGND or common of the circuit
VDD 3.3V pin (do not connect the device to 5V)

MQ-6 Sensor

The MQ-6 sensor has 6 pins in 2 sets of three on each side. The two A Pins are tied to the 5V line as is one of the H pins. The other H pin goes to ground potential. Lastly, one of the B pins is connected to a 20kΩ resistor in series to the ground potential, with the other pin going directly to the A1/analog 1 input of the microcontroller.

The sensor is not sensitive to polarity so there is no chance of connecting the device in reverse polarity and damaging it. Just make sure, you don’t connect the B pins without a resistor to ground, doing so could permanently damage the sensor.

A NOTE ABOUT START UP: The MQ–6 requires a one-time run in of 24–48 hours for correct operation, I recommend you do this as the readings become significantly more stable and I assume more accurate after this run-in period.

Lithium Charging Module

Since the device is designed to be portable we have no option but to use batteries. Whilst we could use off the shelf non-rechargeable alkaline cells, they represent a false economy. Their initial purchase price may be small, however, they have small capacities and require regular replacement. I have personally found that 3D printed parts don’t generally last long when you need to open them up regularly. This means rechargeable batteries are the best option we have.

Rechargeable alkaline batteries are relatively inexpensive and simple to charge, however, generally speaking, have significantly lower energy density. This means you need either a very large battery or have very low usage time. Therefore, I feel it a more practical option to use lithium cells. Lithium batteries have extremely good energy density when compared to alkaline cells, however, they are quite a bit trickier to charge.

We have all heard horror stories of lithium batteries catching fire or “exploding”. This is usually the result of improper charging or discharging of the cell. To correctly charge a lithium cell you need to limit the current to a specific charge rate whilst also limiting the voltage potential. This means some clever circuitry is needed.

For this project, I opted to use the off the shelf TP4056 based lithium charger module, which is inexpensive and highly reliable. To connect it to the circuit you simply need to connect the ‘bat+’ and ‘bat–’ pads of the module to the positive and negative tabs of the lithium cell.

This way you can easily charge your battery using any micro USB cable and supply.

Step-up/Boost Converter Module

The MQ-6 sensor used in this project requires 5V for correct operation. This means we need a way to step up our 3.2V–4.2V battery voltage to 5V. As stated earlier, I used an MT3608 Boost Converter that I had on hand. I thought it was commonly available at our local retailers, which apparently isn’t the case, however, whilst they don’t sell the exact part they do indeed sell a suitable substitute.

Many electronics retailers sell a 5V USB Boost Module, which is designed to step-up the voltage from a battery to 5V USB voltages. All that you would need to do is remove the USB connector and solder the positive and negative pads to the 5V and ground of the circuit.

However, if like me you have the MT3608 from IC Station you simply need to connect the Vin+ and Vin- to the positive and negative of the lithium cell. After which you use the included potentiometer and multimeter to set the output voltage to 5V.

After doing that you just connect the Vout+ and Vout- to the circuit.

The Main Build:

Complete LPG Detector

With the circuit proven on the breadboard prototype, we can now build the main circuit.

VDD/3.3V 3.3V
Reset D9

Wiring The Circuit

For the final device, we essentially do exactly the same as with the prototype, however, this time we need to solder all the components together using hookup wire.

I recommend you take your time and consider the length of the wires carefully. It is surprising just how much space wiring can take up and can easily leave your device unable to fit together.

3D Printed Enclosure

I originally designed the enclosure for this device to house an 18650 lithium cell. I placed all of the components together using Blu-Tack, which provided me with a very good idea of how big the device would be. However, I made one huge rookie mistake, I did not leave sufficient room for all of the wiring. Whilst I could have changed the dimensions of the device I felt it would have made it much bigger than I would have liked. Since the 18650 cell would have produced a bucket load more running time than needed, I opted to reduce the size of the cell to the 14500.

For this enclosure, I tried to use the dual extrusion capabilities of my 3D printer. The results were not quite as good as my USB Soldering Iron from Issue 16, as I used a transparent filament and didn’t design the letters thick enough to match the resolution of the printer. This can be rectified by enlarging the letters in the CAD file and re-printing. Sadly due to time constraints, it was not possible before going to print. Despite this, there is the option to print the enclosure with or without the dual extrusion as both files will be provided.

To secure the enclosure together you’re going to need some M3 20mm coarse thread screws. I had these from scrapped electronics I have collected over a period of a few years. If you don’t have a collection yourself your local hardware is sure to have a suitable option.

All of the components in the device are secured with hot glue with the exception of the charging module. I have found with previous devices that hot glue does not stand up to the abuse of having a charging cable attached and removed. After a short period of use the hot glue gives out and you’re left with a PCB floating around inside the case. Therefore, for this device, I secured the charging PCB to the case using a UV curable glue. If you don’t have access to such glue I recommend a two-part epoxy or something similar.

The Code


#include <Wire.h>
#include <SFE_MicroOLED.h> //Sparkfun micro OLED library
#define PIN_RESET 9
#define DC_JUMPER 1
int count = 600;
int sensorValue = 0;
int refrence = 0;
void setup()

In the setup, we need to include the wire.h library which is now part of the standard Arduino libraries, and for most people, should not need downloading.

If you get an error saying the wire.h library cannot be found, try downloading the latest version of the Arduino UI from:

You will also need the SFE_MicroOLED.h library which you can download from:

Essentially, what the code is doing here is setting up the program. We are setting the code to expect the D/C jumper to be set to 1 and the communication protocol to I2C.

EDITOR'S NOTE: This device should not replace common practices and professional test equipment to ensure your BBQ doesn’t have any gas leaks.


void loop()
  while (count > 0)
  oled.setCursor(15, 2);
  oled.setCursor(17, 11);
  oled.setCursor(20, 21);
  oled.setCursor(18, 35);
  count --;
  for (int i = 0; i < 100; i++)
    sensorValue = analogRead(A1);
    refrence = (refrence + sensorValue);
  refrence = (refrence / 100);
  while(1 == 1) //creates a 2nd loop
  int x0 = 2; int y0 = 50;
  int x1 = 3; int y1 = 50;
  oled.line(x0, y0, x1, y1);
  oled.setCursor(8, 2);
  oled.setCursor(6, 19);
  oled.print("LPG Leak");
  oled.setCursor(6, 27);
  oled.setCursor(0, 38);  
  sensorValue = analogRead(A1);
  sensorValue = (sensorValue - refrence);
  if (sensorValue < 0)
  sensorValue = 0;

Here I have created two loops. The first is designed to allow the sensor time to warm up. The loop takes approximately 60 seconds in which a countdown is presented to the user, instructing them to wait. This process should be done in a known combustible gas free area as this process is essentially a calibration phase.

After the warm-up period, the program takes 100 sensor readings and finds the average result. This average result will give us our baseline reading, which we can later zero out for consistent results.

The second loop is created using an inescapable condition. In this case, the program is forced into it by using:

while (1 == 1)

Of course, 1 will always equal 1, so the program can’t leave this loop once it enters it without the microcontroller being reset.

In this loop, the program simply takes a reading from the sensor then subtracts the expected background reading or reference created in the previous loop. If the result is a negative number it corrects for it by making it zero, then displays the result.


The only way to test this device that I could think of (short of finding a known concentration of gasses to reference) was to simply expose the sensor to LPG and butane from gas bottles and cigarette lighters. Both resulted in an increased reading in the presence of gas which increased as it got closer to the source of the gas.

It proved very effective at pinpointing the source of the gas and as such could easily be used to track along a pipe to find a leak.

Where To From Here?

The device is capable of displaying the parts per million reading of the gas. I chose not to do that as I didn’t want anyone to attempt to use this device to replace a professionally calibrated device. However, I would like to in the future have the device display the actual PPM reading and have it calibrated with a known concentration of gas.

Of course, you can adapt the circuit for other gasses as mentioned in the introduction.