{:en}
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.
Parts
|
Raspberry Pi3 x1
|
|
| MQ-2 sensor x1 | |
| Analog to digital convertor(ADC) x1 | |
| Breadboard x1 | |
| male to male jumper wire x some | |
| male to female umper wire x some |
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.

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 --no-check-certificate 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.
MQ-2可燃ガス/煙センサーを使って、ラズパイに煙、ガスを検出装備をデザインします。SnO2系煙センサーですので、ガス濃度の変化に応じてSnO2の抵抗値が変化します。周囲環境でのガス濃度が増えると、SnO2の抵抗値が下げます。センサーがその変化値を輸出しできます。MQ-2は、液化石油ガス、プロパン、水素などに敏感です。
必要なパーツ
本项目将用到如下器件
|
Pi3ボード x1
|
|
| MQ-2モジュール x1 | |
| MCP3008 A/Dコンバータ x1 | |
| ブレッドボード x1 | |
| ジャンプワイヤー(オス~オス) x若干 | |
| ジャンプワイヤー(オス~メス) x若干 |
ハードウェア
ラズパイはデジタル信号しか処理しできませんので、今回はガス検知センサーからの電圧信号(アナログ信号)を処理するため、A/Dコンバータも必要です。本プロジェクトではMCP3008と言う、よく利用されるA/Dコンバータを使用します。電圧値より、ガスがあるか無いか判断します。
MQ-2モジュールの工作電圧は2.5~5Vになります、本プロジェクトでは3.3Vを給電します。MQ-2モジュールはアナログ信号とデジタル信号2重輸出できますので、本プロジェクトに、アナログOUTPUT(AO)とデジタルOUTPUT(DO)両方と使用します。ガス検出したら、指示ランプが点灯、DOpinから低電位信号を輸出する、モジュールに可変抵抗がありますので、センサーの感度が調整しできます。
配線図
線路違うとボード、センサーに損害の恐れが御座いますので、正極と負極を十分ご注意して下さい。模块的上的GND接Pi上的0V; Raspberry PiのGPIOピンの概要はこちら~
ソフトウエア
下記の操作は、ラズパイとスクリーンを接続しても、SSHを通じでラズパイと接続しても、操作できます。
1)プログラム
nanoエディタを使用して、下記のコマンドを作動して、/home/piにmq-2.pyと言うファイルを新規作成します。
sudo nano mq-2.py
ファイルにをコードをコーピーして、キーボードのCtrlとXボーダーを押して、Yを入力して、ファイルを保存します。
或いは、下記のコマンドを作動して、弊社編集済みのmq-2.pyを直接にダウンロードできます。
sudo wget --no-check-certificate http://osoyoo.com/driver/mq-2.py
2)下記のコマンドを作動して、pythonプログラムを作動する
sudo python ./mq-2.py
3)結果
まず、mq-2モジュールは20秒の予熱が必要、预热20s左右,ガスライターを使って、モジュールに少しガスを释放したら、ターミナルに”Gas lealage”を表示し、電圧値も表示し、指示ランプも点灯します。もし、モジュールにガスを释放しても、何も変化しないの場合、モジュールでの可変抵抗を調整して、確認して下さい。
本项目将利用MQ-2烟雾传感器模块,在树莓派上设计烟雾检测器。烟雾传感器所使用的气敏材料是在清洁空气中电导率较低的二氧化锡(SnO2),当传感器所处环境中存在可燃气体时,传感器的电导率随空气中可燃气体浓度的增加而增大,模块可以将将电导率的变化转换为与该气体浓度相对应的输出信号。MQ-2气体传感器对对液化石油气,丙烷,氢气敏感的灵敏度高。
Parts
本项目将用到如下器件
|
Pi3 x1
|
|
| MQ-2模块 x1 | |
| 模数转换器 x1 | |
| 面包板 x1 | |
| 公对公跳线 x若干 | |
| 公对母跳线 x若干 |
Hardware
Raspberry Pi只能处理数字信号,但是本项目中要用到MQ-2模块输出的模拟信号,所以需要用到模数转换器。本项目中利用MCP3008把MQ-2模块输出的电压信号转换成数字信号,根据转换后电压的大小来判断是否有烟雾。
其中MQ-2模块工作在2.5-5V电压下,在本项目中利用3.3V供电,模块具有模拟信号和数字信号双路输出,当模块检测到有烟雾的时候,信号指示灯亮起,数字信号输出口输出低电平。模块上面有一个可调电阻,通过调节可调电阻能够调节模块的灵敏度。

模块之间与树莓派具体连接请参考下图
在接线的时候请认清模块正负极,不要接反了,否则会烧坏你的Pi和模块。模块的上的GND接Pi上的0V;模块上的VCC接3.3V。对于如何识别Pi的IO口请参考这篇文章: How to read Raspberry Pi i/o pin diagram (GPIO pin graph)
Software
可以把pi直接接到显示器上,也可以通过SSH方式远程登录Pi。
1)编写代码
在/home/pi路径下用nano新建一个mq-2.py(名字随意,你喜欢就好!)
sudo nano mq-2.py
并往新建的文件中写入示例代码,代码可以通过执行下面的shell命令得到
sudo wget --no-check-certificate http://osoyoo.com/driver/mq-2.py
2)执行python程序
sudo python ./mq-2.py
3)测试
让mq-2模块预热20s左右,让数据稳定,如果出现模块有细微发烫是正常的。用打火机对着模块释放可燃气体,屏幕会打印出来”Gas lealage”的字样,并且打印出当前传感器输出电压,信号指示灯亮起,如果没有上述现象,可通过顺时针调节可调电阻,直到出现上述现象为止;在不向其释放可燃气体时候会输出”Gas not leak”字样。
You must be logged in to post a comment
About the Author