{:en}
Overview
This tutorial is to design a CO gas detector through a raspberry pi board and MQ-7CO sensor. It can detect the concentration of the CO gas in the environment.The gas-sensing materials the MQ-7 sensor used is SnO2 material,which is lower conductivity in clear air, the conductivity of sensor would go up with the increase of the CO gas concentration.The sensor can convert the different conductivity to the correspondent output signal of the CO gas concentration.The MQ-7 gas sensor has high sensitivity and a variety of application in low price.
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-7 sensor.It can detect the CO gas concentration according to the valtage value.MCP3008 as ADC chip is very common and recommended highly.
The MQ-7 sensor can output the analog and digital signal when the work voltage is 5V. When the CO gas is detected by snesor, 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 5V. 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)
Parts
本项目将用到如下器件
|
Pi3 x1
|
|
| MQ-7 sensor x1 | |
| MCP3008 convert x1 | |
| Breadbooard x1 | |
| Male to male Jumper wires | |
| Male to female Jumper wires |
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-7 sensor.It can detect the CO gas concentration according to the valtage value.MCP3008 as ADC chip is very common and recommended highly.
The MQ-7 sensor can output the analog and digital signal when the work voltage is 5V. When the CO gas is detected by snesor, 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 5V. 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-7.py under home file (the name is arbitrary)
sudo nano mq-7.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-7.py
2)Execute python program
sudo python ./mq-7.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 CO gas using the lighter. When you light the lighter in front of sensor,there is a signal output of CO is detected 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.
{:}{:ja}
概要
本プロジェクトではMQ-7一酸化炭素センサーとラズパイ3ボードを使って、周囲環境の一酸化炭素濃度検測装備を作ります。SnO2系センサーですので、一酸化炭素濃度の変化に応じてSnO2の抵抗値が変化します。周囲環境での一酸化炭素濃度が増えると、SnO2の抵抗値が下げます。センサーがその変化値を輸出しできます。MQ-7は、一酸化炭素に敏感と言われます。様々な場合に採用できる、コストパフォーマンス高いのセンサーと言われます。
必要なパーツ
|
Pi3ボード x1
|
|
| MQ-7モジュール x1 | |
| MCP3008 A/Dコンバータ x1 | |
| ブレッドボード x1 | |
| ジャンプワイヤー(オス~オス)x若干 | |
| ジャンプワイヤー(オス~メス)x若干 |
ハードウェア
ラズパイはデジタル信号しか処理しできませんので、今回は一酸化炭素センサーからの電圧信号(アナログ信号)を処理するため、A/Dコンバータも必要です。本プロジェクトではMCP3008と言う、よく利用されるA/Dコンバータを使用します。周囲環境での一酸化炭素濃度が増えると、SnO2の抵抗値が下げます。センサーがその変化値を電圧値に変更して、輸出しできます。電圧値より、周囲環境の一酸化炭素濃度を判断できます。
MQ-7モジュールの工作電圧は5Vになります、MQ-7モジュールはアナログ信号とデジタル信号2重輸出できますので、本プロジェクトに、アナログOUTPUT(AO)とデジタルOUTPUT(DO)両方と使用します。一酸化炭素検出したら、指示ランプが点灯、DOpinから低電位信号を輸出する、モジュールに可変抵抗がありますので、センサーの感度が調整しできます。
配線図
線路が違うとボード、センサーに損害の恐れが御座いますので、正極と負極を十分ご注意して下さい。Raspberry PiのGPIOピンの概要はこちら~
ソフトウエア
下記の操作は、ラズパイとスクリーンを接続しても、SSHを通じでラズパイと接続しても、操作できます。
1)プログラム
nanoエディタを使用して、下記のコマンドを作動して、/home/piにmq-7.pyと言うファイルを新規作成します。
sudo nano mq-7.py
ファイルにをコードをコーピーして、キーボードのCtrlとXボーダーを押して、Yを入力して、ファイルを保存します。
或いは、下記のコマンドを作動して、弊社編集済みのmq-7.pyを直接にダウンロードできます。
sudo wget --no-check-certificate http://osoyoo.com/driver/mq-7.py
2)下記のコマンドを作動して、pythonプログラムを作動する
sudo python ./mq-7.py
3)結果
まず、mq-7モジュールは20秒の予熱が必要、ガスライターを点火したら、モジュールに近づいてくると、ターミナルに”CO is detected”を表示し、電圧値も表示し、指示ランプも点灯します。もし、点火したのライターがモジュールのそばに置いても何も変化しないの場合、モジュールでの可変抵抗を調整して、確認して下さい。
{:}{:zh}Overview
本项目将利用MQ-7CO传感器模块,在树莓派上设计CO气体检测器,可以检测环境中CO气体浓度。MQ-7气体传感器所使用的气敏材料是在清洁空气中电导率较低的二氧化锡(SnO2),传感器的电导率随空气中一氧化碳气体浓度增加而增大,模块可以将电导率的变化,转换为与该气体浓度相对应的输出信号。 MQ-7气体传感器对一氧化碳的灵敏度高,是一款适合多种应用的低成本传感器。
Parts
本项目将用到如下器件
|
Pi3 x1
|
|
| MQ-7模块 x1 | |
| 模数转换器 x1 | |
| 面包板 x1 | |
| 公对公跳线 x若干 | |
| 公对母跳线 x若干 |
Hardware
Raspberry Pi只能处理数字信号,但是本项目中要用到MQ-7模块输出的模拟信号,所以需要用到模数转换器。本项目中利用MCP3008把MQ-7模块输出的电压信号转换成数字信号,根据转换后电压的大小来判断环境中CO浓度。
其中MQ-7模块工作在5V电压下,具有模拟信号和数字信号双路输出,当模块检测到CO气体的时候,信号指示灯亮起,数字信号输出口输出低电平。模块上面有一个可调电阻,通过调节可调电阻能够调节模块的灵敏度。
模块之间与树莓派具体连接请参考下图

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