Home Gas Detector

Introduction: Home Gas Detector

This project aims to create an effective home gas detector from arduino uno(or in this case its chinese equivalent) and a bunch of sensors.


The equipment you'll need is:

1. Arduino uno or its cheeper version from Geekcreit which is about 5-8$.

2. DS3231 Real Time Clock Module for about 2$ which will be used for the clock but also for temperature measurement.

3. MQ-2 gas sensor which will be used for measuring CO concetration. It's about 2.50$.

4. MQ-7 gas sensor which will be used for measuring LPG and smoke concetration. It's about 2.50$.

5. A passive buzzer and humidity sensor which usually go for 1-2$ or in a bigger sensor pack.

6. 1.8" TFT Color Display ST7735. This is the one I use in this project and is about 5$.


Step 1: The Circuit

The modules and their connections to the board are described next. The pins of the module are on the left side and the arrow points to the board pin that this pin is connected to.


VCC → 5V


SDA → second pin from the top, on the right side of the board

SCL → first pin from the top, on the right side of the board

(SDA and SCL are circled in red on the board picture above)


VCC → 5V


A0 → A0


VCC → 5V


A0 → A1

ST7735 Display:

VCC → 5V


CS → 10


AD → 8

SDA → 11

SCK → 13

LED → 3.3V


- → GND

middle pin → VCC

S → 5

Humidity sensor:

- → GND

middle pin → VCC

S → 5

Step 2: The Code

The code is featured in several screenshots from the arduino editor so you can have a quick look at it or you can download it in full bellow. The project requires quite a few libraries so they are also featured.

Structure and logic of the code

In the first picture the libraries are included, then there are few defines for the buzzer, humidity sensor and the display, also I had to include the color grey because it's not defined by default from the library. After that are the sensor instances and variables which will come handy later. The hr and wr variables are some measurements for the line boundaries. Next is the setup. The serial connection rate is set at 115200 bauds and the mq2 and ds3231(rtc) sensors are started.

In the second picture we set the buzzer pin to be output. We initialize the screen to a black screen and insert a dealy of 10 seconds after which we start drawing the separation lines(white lines) on the screen, this code is marked by the Horizontal lines and Vertical lines comments. Next is the text on the screen. For each specific sensor the block of code that displays the text starts with that sensors name like a comment. This is only the static text that won't change on refresh.

In the third picture the text part continues and the setup ends with another 10 second delay to let the sensors calibrate nicely. After that comes the main loop. In it the first thing to get from the sensors and show on the string is the day, after which follows the date.

In the fourth picture the main loop continues with getting info about the time. After that is the temperature. The color of the text on the screen depends on the temperature. After a few lines of code there is tft.print((char)248), this prints the celsius sign on the screen.

In the fifth picture the humidity is printed with a blue color if is within 30 and 55 percent(the considered normal humidity for a room) and red if it isnt. After that CO(carbon monoxide), smoke and LPG(gas) concentrations are measured and displayed.

In the sixth and seventh picture are the checks that activate the buzzer and warn for potential high and harmful levels of toxic matters. If the LPG is between 15 and 30 ppm, it buzzes in intervals of two seconds as a precautionary warning. If the levels are above 30 it buzzes constantly until those levels go down. For the CO is the same but with three thresholds and one threshold for smoke. The levels are updated every 5 seconds.

Step 3: The Result

You should get the above look on your TFT screen when you power your board.

Be the First to Share


    • Potato Speed Challenge

      Potato Speed Challenge
    • Bikes Challenge

      Bikes Challenge
    • Remix Contest

      Remix Contest

    2 Discussions


    1 year ago

    Thank you for sharing! : )


    Reply 1 year ago

    No problem, hope someone finds it useful. :)