Try   HackMD

A safety system for gas leakage

Name : Amirhossein Soltaninejad

Short project overview:
A safety system for gas leakage is based on the Internet of Things system, where the system sends a value that expresses the percentage of gas in the air of the apartment and sends it on the dashboard to track the percentage of gas in the air while determining the percentage of danger.

How much time it might take to do:
I have spent around 30 hours programming the project and about 8 hours testing the functionality.

Objective

Why you chose the project:
I have chosen to do this project, first because of showing the strength and effectiveness of the Internet of things in effectively solving daily problems and also have a simple solution for the problem that can happen to every people.

What purpose does it serve:
Due to the presence and danger of gas leakage in the apartment and its impact on human life, this project can help to identify and measure the gas leakage and prevent possible upcoming damages

What insights do you think it will give:
It can be an opportunity to provide gas meters with the additional task of not only measuring consumption but also securing people's lives by adding this system to the meter.

Material

List of material:

  1. Microcontroller (NodeMCU esp8266)

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  2. Gas Sensor (MQ4)

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

  3. Jumpers for connections

    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

What the different things (sensors, wires, controllers):

  • Microcontroller
    It contains the processor and storage memory (flash memory) that holds the code that runs the entire system.
    specification:
    WeMo’s NodeMCU V3 ESP8266 CH340G WIFI Module With Extra Memory 32M Flash module is based on widely explored esp8266 System on Chip from Expressif.We add extra memory size to 32Mb. This better, for making a big project with the big library. You do not need to worry about the size of memory.
    Onboard have USB-TTL serial converter CH340G, with Micro-USB socket.
    Power In for DC 4~9V, to pin VIN.

  • Gas Sensor (MQ4)
    This sensor reads the gas value in the atmosphere and converts it into a voltage signal and sends it to the controller.Sensitive material of MQ-5 gas sensor is SnO2, which with lower conductivity in clean air. When the target combustible gas exist, the sensors conductivity is higher along with the gas concentration rising. The sensor convert change of conductivity to correspond output signal of gas concentration.
    MQ-5 gas sensor has high senility to Methane, Propane and Butane, natural gas and could be used to detect both Methane and Propane.
    specification:
    Main chip: LM393, ZYMQ-5 gas sensor
    Operating voltage: DC 5 Volt
    Size: 32mm X22mm X27mm

  • Jumpers for connections
    It is a wire that ends with a conductor, it connects three pins to the controller, which are:
    VCC
    Ground
    Analog Signal Pin

Where you bought them and how much they cost:

I have bought the microcontroller from https://www.styrahem.se with the price of 149kr.

I have bought the gas leak sensor from https://AliExpress.com for 13kr.

I have bought jumpers from https://elektristad.com/ for 25kr.

Computer setup

How is the device programmed:
The device is programmed using micro-Python firmware, which consists of three files, the first file is called boot.py and this is responsible for starting the firmware in the controller first when the system starts.
And the second file is called config.py and it is responsible for adjusting the settings in the controller before working.
The last one is main.py which contains the main function to be executed.

Inital steps
For inital setup it is needed to download specific version of the micro-python firmware for specific microcontroller from micro-python website. Then, by using uPyCraftV1.1 and choose upload firmware configure the setting for your microcontroller and upload it.

Chosen IDE:
I have used uPyCraftV1.1 which is editor and serial communication built-in.

How the code is uploaded:

  1. Created three files for the project boot.py, config.py and the main.py
  2. Using uPyCraftV1.1 and choose upload and upload them in order.

Steps that you needed to do for your computer:

  1. Download uPuCraftV1.1 for windows.
  2. Download specific version of the micro-python firmware for specific microcontroller from micro-python website.

Electronics and Connections

  • The sensor has four PINS, one for the input voltage, one for ground, one for the output analog signal, and one for the digital output signal.
  • We will connect the input voltage to 3.3 volts from the micro.
  • And the ground to micro ground.
  • Output analog signal to A0 in micro.

Circuit diagram

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  1. VCC -> need 3.3 volt to work
  2. Ground -> Ground 0 volt
  3. OUT -> A0 change as sensor work
  4. For resistor we don’t need here as we use power from micro.

I should mention that the project is only for development and the only step to go to production is to merge micro with sensor to reduce the cost.

Platform

Platform Choice:
I have used node-red because it is simple and allows the user to customize and design their system. It depends on the local host.

Local or cloud:
I have used a cloud service that is a free hiveMQ free broker. And to scale need to subscript for cloud service.

platform in terms of functionality:
platforms in terms of functionality are the MQTT protocol to send and used data on free broker hiveQM. Or microcontroller based on.

The code

The code is uploaded in the GitHub following link and it contains 3 classes. boot.py and this is responsible for starting the firmware in the controller first when the system starts.
And the second file is called config.py and it is responsible for adjusting the settings in the controller before working.
The last one is main.py which contains the main function to be executed.
The code link: https://github.com/mantoomine/IOT_Project

Transmitting the data / connectivity

How often is the data sent:
Data is sent every second because the project is critical and depends on the speed, and the size of data is 4 bytes.
Which wireless protocols did you use (WiFi, LoRa, etc …):
Wi-Fi wireless protocols are used for this project.
Which transport protocols were used (MQTT, webhook, etc …):
MQTT protocol is used to send and use data on free broker hiveQM.

Presenting the data

Visual examples on how the dashboard looks:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

How often is data saved in the database:
I have used Excel, but the data can be saved in any database. I used Excel because the data sent is a lot, as the sensor sends readers every second, and it is not important, so storing it is a waste of time and resources. I only record important events, such as when the reading increases dramatically, there is a leak here. I record the event, not the reading.

Finalizing the design

As it was my first experience with microcontrollers and python programming language, I have chosen a simple project it can help me to learn the basics of IoT and python. And also I have tried to choose a project that is helpful in people's lives. This system can be added to the gas meters so that the meter comes with the system built in, making it more effective in the direction of productivity.

This is a picture of the final result of the system while it is working, and it shows the outputs on the dashboard and displays a real reading in real-time.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →