Design a smoke detector through a raspberry pi board and MQ-2 smoke sensor

Byamber

Design a smoke detector through a raspberry pi board and MQ-2 smoke sensor

Overview
This tutorial is to design a smoke detector through a raspberry pi board and MQ-2 smoke sensor.It can detect the concentration of the smoke in the environment.The gas-sensing materials the MQ-2 sensor used is SnO2 material,which is lower conductivity in clear air, the conductivity of sensor would go up with the increase of the smoke concentration.The sensor can convert the different conductivity to the correspondent output signal of the smoke concentration.The MQ-2 gas sensor has high sensitivity to liquefied petroleum gas,propane and hydrogen.

DSC_5496

Parts

本项目将用到如下器件

PI
Raspberry Pi3 x1
5
MQ-2 sensor x1
MCP3008
Analog to digital convertor(ADC) x1
LACC2006AD-12
Breadboard x1
LACC2006AD-31
male to male jumper wire x若干
19
male to female umper wire x若干

Hardware

As only the digital signal can be processed by raspberry pi, we need to add a analog to digital converter (ADC) to process the analog signal from MQ-2 sensor.It can detect the smoke in the air according to the valtage value. MCP3008 as ADC chip is very common and recommended highly.

The MQ-2 sensor can output the analog and digital signal when the work voltage is 2.5V-5V. When the CO gas is detected by sensor, the signal light turns on and the digital signal output the low-level valtage. In additon, there is a adjustable resistor to change the sensor sensitivity.
mq-2
The schematic diagram is as follows:

Pay more attention to the anode and cathode, otherwise it would burnout your raspberry pi board and sensor.You can connect the GND of the sensor to OV, VCC to 3.3V. You could visit the article for your referenc if you want to learn more about the raspberry pi IO port. : How to read Raspberry Pi i/o pin diagram (GPIO pin graph)

Software

You could choose the connect the raspberry pi to monitor, or login in pi via SSH.

1)Write the code

Add new file named mq-2.py under the /home/pi file path via nano editor (the name is arbitrary)

sudo nano mq-2.py

Write the sample code in new file, the code can be obtained by executing shell commands.

sudo wget http://osoyoo.com/driver/mq-2.py

2)Execute python program

sudo python ./mq-2.py

3)Test

When the programme start, there is no signal output within 20s.The sensor would preheat 20s firstly,then output after the data remain stable.It is normal for sensor to stay hot slightly.It can produce the smoke using the lighter.When you light the lighter in front of sensor,there is a signal output of “Gas lealage” word and the valtage value, the signal light turns on . If these the phenomenon above doesn’t appear, you could swing clockwise to adjust the resistor until the above phenomenon appear.

2017-03-30-094819_1824x984_scrot

About the Author

amber administrator

1 Comment so far

BaltazarPosted on  2:00 am - Aug 19, 2017

Hello,

Thank you for the instructions. Finally I’ve managed to set up the Pi with the mq-2 sensor. I am happy AF, because it was the third setup that I’ve tried since ever.
It works properly with gas, I tried It with a lighter, and the results were really fine 🙂

However I set on fire some paper , and the sensor did not show anything.
My question is that, this program is designed for smoke as well, or am I dumb, and messed up something? 🙂

BTW my project would be check and log and trigger some actions (with timestamp) if my neighbors smoke on the balcony , since the vent system is push all their second hand smoke to my apartment. I am a non technical guy so I don’t know if this stuff could check that small amount of smoke, but I really want to do something for sake of my family’s health.

You must be logged in to post a comment