MQ4 Gas Sensor – Methane Natural Gas monitor with MQ3 / MQ4 sensors

Arduino gas sensor MQ4

Can we monitor natural gas leakage with Arduino, without spending allot of money? There are many sensors available everywhere over the internet and most of them can be found very affordable in Asia largest online marketplace. They are quite cheap if you choose to buy them directly from manufacturers and not from the closest re-sellers. For instance, I bought the MQ4 just for 1.29$ from a well known China electronics marketplace.

Arduino MQ4 gas sensor – review and tutorial with video example

MQ4 Gas sensor overview (UPDATES: New code examples added for gas concentration)

MQ series sensors use a small heater inside with an electro-chemical sensor in order to measure different kind of gases combinations. They can be calibrated, but, in order to do that a know concentration of the measured gas or gasses is needed for that. For industrial purpose calibrations are done in special metrology laboratories with accurate probes and tests. In our case, we will test it as it comes from the producer without any additional calibration or settings. The main idea before ordering this kind of sensor was to build a homemade alarm sensor, which should make some alarming noise or light whenever someone forgot the cooker stove one, or my little kid learned to play with stove switches, or there is a leak in my gas installation. To accomplish that, I wanted a methane gas, simple to use, and also compatible with arduino platform. Producer says that MQ4 sensor can sense methane / natural gas easily with a range sensitivity from 300 to 10000ppm , costs are very low, and can be easily plugged with Arduino boards.

MQ4 sensor pinout connections and power consumption

Arduino MQ4 sensor specifications

This model comes with 4 pins:

  • 1 pin VCC 5v
  • 1 pin GND
  • 1 pin DO (digital output) TTL digital 0 and 1 (0.1 and 5V)
  • 1 pin AO (analog output) 0.1-0 .3 V (clean), the highest concentration of voltage around 4V

MQ4 model must be powered with stable 5v and needs at least 150mA (best to have 250mA) according to the datasheet declaration, to be able to work properly. Also before getting stable measurements, this model needs at least 1 minute to heat up. Be aware that in some datasheets use the term “preheat”, which means that some versions needs from 12h to 24h to burn-in the sensor. Only after this you will be able to get consistent data. Also this kind of devices, which have internal heater, are pretty sensible to ambient influences like humidity or moisture.

You can find technical datasheet in PDF format provided by at the end of article.

Hardware and software used for testing

  1. Arduino UNO R3 compatible board
  2. MQ4 gas sensor
  3. breadboard
  4. breadboard compatible power supply (5v, min 300mA)
  5. dupont wires / cables
  6. arduino IDE 1.6.xx

See wiring hookup setup and demonstration in below video.

Here is the arduino code used for demostration:

UPDATE – New code examples for gas concentration

Because this topic is pretty hot, I decided to dig more and find better resources in order to get the best from this sensor. Just reading the Arduino analog input is not enough to make a reliable gas monitoring system. In order to do that we need a new approach to calculate the gas PPM by implementing the formulas provided by the datasheet. Below you can find two code examples which I found and may help you to get better results from this module:

! Note – Now both code pieces above may not be clear for many of you. Therefore to understand the logic behind this calculations you should check here out how this guy got to this solution by trying to implement the Datasheet calculation formulas. Code examples from that website are not working because of the bad encoding (you will get Arduino IDE a C/C++ related error (error/stay 302)) but the formulas and math demonstration are pretty interesting. Use the code from the above examples.

The sensor is quite small and can be fitted easy in any prototype with 4 screws in the board corners. This version comes with a rotating lever from which you can adjust sensitivity by rotating it left or right. On each lateral edge you can find two LEDs which indicates power availability and digital output status. Open this link to read datasheet.

I will come back with more feedback after checking behavior in my house. Until then, thank you for your time.

Hoping that this article inspired you, i kindly invite you share this articlesubscribe my YouTube channel and join the communities on social networks. Feel free to comment or send suggestions / remarks so i can improve the content quality.






1 comment » Write a comment

  1. Pingback: Smart House - Intelligent Home with Internet of Things - Introduction

Leave a Reply

Required fields are marked *.