Gas Detection, Monitor and Control​

by phulelouch in Circuits > Raspberry Pi

182 Views, 0 Favorites, 0 Comments

Gas Detection, Monitor and Control​

Untitled Diagram.drawio (1).png

Unattended gas stoves has been the predominant cause for cooking fire. The National Fire Protection Association (NFPA) has estimated that, in between 2013 to 2017, 173,200 cooking fires were reported annually, which has accounted for an average of 550 civilian deaths, 5,020 civilian injuries, and $1.2 billion in direct property damage per year. Not only are unattended gas stoves detrimental to household, it is reported that, in 2011 to 2013, there were 5,600 restaurant fires reported to fire departments in the United States, resulting in $116 million property damage. These figures alone are enough to pinpoint the severity of unattended gas stoves; which often but not is a human-error that could have been avoided with the help of automated systems.

In response to this human-error, this project aims to build a gas monitor and control system, which is capable of notifying the gas owner through email and activating the gas alarm when gas is detected. On top of that, the gas owner can remotely press an emergency button to turn the gas off.

This is an good introduction of what I am trying to do:

Put and Run the Code on a Virtual Private Server

Screenshot from 2022-06-06 21-54-20.png
Screenshot from 2022-06-07 22-12-45.png

This part represents the connection between 3 of our embedded systems. It is the essential part and it should have a public IP address, mine: Digital Ocean $5/month. But it should be your choice to find your favorite host provider. After that, you should have a host with a public IPv4 address and ssh enabled. Better setup here:

https://www.digitalocean.com/community/questions/how-to-setup-vps-on-digitalocean

Next, we will put a PHP file that serves as backend between our systems

The code of the server is in my GitHub: https://github.com/phulelouch/SIT210/tree/main/Pro...

Clone that and you will see an index.php file

We will use this command to put the PHP file in the server that we just create: scp -r username@ipaddress:/remote/path/to/directory /local/path

After that, we would want to run the PHP code. There are 2 way to do this:

  • Apache where we put the file in /var/www/html and run apache with systemctl apache start
  • We can create a session running in the server with TMUX or Systemd and run this command php -S ip:port /path/to/file

In my own experience, I prefer the second way when developing because it will provide more outputs and we really know what is going on. The result with Tmux should look like the second picture

Next, we will come down to the Argon for reading sensors

System 1: Argon and Sensors

1.png
Schematic_Project_2022-06-05.png

This system comes with the sole purpose of providing data from the outside world for us, specifically the gas value and flame value in the environment with our Particle Argon as microprocessor. We will be using a generic Arduino gas sensor. It has MQ2 probe which is able to detect LPG, i-butane, propane, methane ,alcohol, Hydrogen, smoke. https://www.dfrobot.com/product-681.html

It can be used in gas leakage detecting device in consumer and industry markets. It has a high sensitivity and fast response time.

The sensitivity can be adjusted by the potentiometer. The output is proportional to the density of gas. You can use analog reading to read the data from this sensor.

And about flame sensor a generic Arduino gas sensor. It has MQ2 probe which is able to detect LPG, i-butane, propane, methane ,alcohol, Hydrogen, smoke will do the work https://www.dfrobot.com/product-195.html

And an buzzer or alarm: https://core-electronics.com.au/rotating-led-warning-light-with-adjustable-volume-buzzer-alarm.html

Next comes the wiring which is always an easy part, just with some female-to-female wires and the schematic provided above, you can wire them your self easily

The connection part is harder however, you will need to have a quick look at this link: https://docs.particle.io/quickstart/argon/

After you can connect the Particle to the internet the code would be here: https://github.com/phulelouch/SIT210/tree/main/Project/sensor

Copy it to your build and flash, remember to change the IP address

System 2: Monitor and Relay

2.png
Schematic_Project_2022-06-05 (3rd copy).png

This system's purpose is to monitor the kitchen where the leak may happen and turn on the emergency relay (shut off gas and turn off the power) to prevent fire when receiving signal.

First of all which hardware we would need:

The camera we will be using is the Pi camera https://www.dfrobot.com/product-1179.html

or OV-7670 camera which provides us better quality https://www.auselectronicsdirect.com.au/vga-camera-module-ov7670-for-arduino-projects?gclid=CjwKCAjwkYGVBhArEiwA4sZLuMX9NYk0gC8FacY3I9BJLxAS2FD3UgcuRgtLpbWl_5KypG5ZezTF3RoCvL0QAvD_BwE

And a relay of course: https://www.dfrobot.com/product-563.html

Wiring is the same as the image

After that, you need to set up your raspberry pi which have been provide every details in this link: https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up

Please check it out and make sure to install the full 32-bit OS Raspberry Pi version. Next we need to install some libraries and packages:

  • sudo apt update
  • sudo apt-get -y install python3-rpi-gpio
  • pip3 install picamera gpiozero socketserver

Next we will put code in our RASP, we have 2 python file, 1 for relay and one for stream and a run.sh file

https://github.com/phulelouch/SIT210/tree/main/Project/stream_and_relay

Now put the files in Rapberry Pi using this command from your terminal:

  • scp -r pi@RASP_IP:/remote/path/to/directory /local/path

SSH into your RASP and type in this command:

  • chmod +x run.sh
  • ./run.sh

And your Raspberry Pi should be up and run. If you want it to run every time powerup, please check this link:

https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6

System 3: Remote Alarm and Control

Schematic_Project_2022-06-05 (copy).png
2 (another copy).png

This system is about notifying a person who is far away about a gas leak or fire with an alarm and provide the emergency button to process the situation. Like previously, we suggest using a good industrial alarm: https://core-electronics.com.au/rotating-led-warning-light-with-adjustable-volume-buzzer-alarm.html

And just some simple buttons: https://core-electronics.com.au/multicolor-buttons-4-pack.html

Now after wiring we shall need to set up our Raspberry Pi and install package just like System 2.

After that get this code:

https://github.com/phulelouch/SIT210/tree/main/Project/control

And set it up

The Result

The process of building this project was fun and intriguing. I have taken baby-steps to
connect each sensor at once, and have used the iterative process to print the output and test the effectivity of the sensors. However, some extra time was spent to install and to write a program to control relay, pi camera, and alarm buzzer as these were the devices that I have yet used in any previous units nor previous tasks. Intensive research and internet resources were heavily referred to, multiple test cases were also done to ensure the correctness of my installation steps. If time constraints were to be removed, I’d optimize the code by allowing the action resulted from button press to be valid only if fire was detected, as well as adding more fault- tolerance test cases to prevent false alarms and more accurate reading from the sensors. External protections or shield to the devices will also be built and added, to allow the device to be more temperature-tolerant and endurable. Overall, I’m pretty satisfied with the outcome of my product, considering how real-time the communication between all the devices are, and how the usability of this product has been my main aim throughout the design process, by providing users with 3 outputs: real-time alarm, real-time notification, and emergency button to real-timely turn the gas stove off