二酸化炭素センサー MH-Z19
二酸化炭素センサー MH-Z19 を試す。
Applications
It is widely used in the HVAC refrigeration and indoor air quality monitoring.
Note: Please let us know the measuring range you need in the Remarks.
If no remarks, we will ship 0~5000ppm by default.
データシート
http://eleparts.co.kr/data/design/product_file/SENSOR/gas/MH-Z19_CO2%20Manual%20V2.pdf
Technical Parameters and Structure
Product Model MH-Z19
Target Gas CO2
Working voltage 3.6 ~ 5.5 V DC
Average current < 18 mA
Interface level 3.3 V
Measuring range 0 ~ 0.5% VOL optional
Output signal
UART
PWM
Preheat time 3 min
Reponse Time T90 < 60 s
Working
temperature
0 ~ 50 ℃
Working humidity
0 ~ 95% RH
(No condensation)
Dimension
33 mm×20 mm×9 mm
(L×W×H)
Weight 21 g
Lifespan > 5 years
PWM用の配線
PWMだけなら 右側3つしか使わない。
PWM : GPIO21
AOT : (開けたまま)
GND : GND
Vin : 5v
に接続した。
PWM 制御の情報
- Output Data Reading
7.1 PWM output (taking PWM output from 2000ppm as example)
CO2 output range: 0ppm-2000ppm
Cycle: 1004ms ± 5%
High level output for beginning: 2ms ± 5%
Middle of cycle: 1000ms ± 5%
Low level output for ending: 2ms ± 5%
とある。
High(1), Low(0), High と繰り返すわけですが、その周期は 約 1000ms で、High の始まりと Low の終わりに 2ms つくと。
データシートの例は Range が 2000ppm の場合だから、5000ppmで納品されているはずだから、全部 High なら 5000ppm ということか。
Python コード
PWMの読み取りをする。
High の時間(Span)とLowの時間(Span) で、結果を読み取る。
Cycle が狂っていなければ、片方だけでも答えに繋がるけど、風を当てたりして計測テストすると、 Cycle が異常に成ったりするので、Cycle自体も見たい所。
頭が混乱するポイント
HighのSpanとLowのSpanの計算がわからなくなる。
最後に High だった時刻(Lowに成った瞬間) と 最後に Low だった時刻(Highに成った瞬間)と考える。
#!/usr/bin/env python # -*- coding: utf-8 -*- import time import RPi.GPIO as GPIO PIN_PWM = 21 def getPwm(): GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(PIN_PWM,GPIO.IN) time.sleep(0.2) while GPIO.input(PIN_PWM) == 1: last_high = time.time() while GPIO.input(PIN_PWM) == 0: last_low = time.time() while GPIO.input(PIN_PWM) == 1: last_high = time.time() span_high = (last_high - last_low) * 1000 print("span_high : " + str(span_high)) while GPIO.input(PIN_PWM) == 0: last_low = time.time() while GPIO.input(PIN_PWM) == 1: last_high = time.time() while GPIO.input(PIN_PWM) == 0: last_low = time.time() span_low = (last_low - last_high) * 1000 print("span_low : " + str(span_low)) print("Cycle : " + str(span_high + span_low)) co2 = 5000 * ( span_high - 2 ) / ( span_high + span_low - 4 ) GPIO.cleanup() return co2 print getPwm()
実行結果
$ ./pwm.py span_high : 167.595148087 span_low : 836.373090744 Cycle : 1003.96823883 828.002038746
室内で 828 ppm というのはどうなんだろうか。
窓を開けてしばらくしたら、 600 ppm 程度までは下がり、 ベランダでは、 450 ppm 程度までは下がった。
外気で400ppm でキャリブレーションが必要だろうか?