百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

mh-z19

> 编程语言
开源

从 Raspberry Pi 上的 mh-z19 传感器读取 CO2 浓度并进行处理。自动检测 Raspberry Pi 机型,并从相应的串口读取值

198 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

从 Raspberry Pi 上的 mh-z19 传感器读取 CO2 浓度并进行处理。自动检测 Raspberry Pi 机型,并从相应的串口读取值

mh-z19

Read CO2 concentration from mh-z19 sensor and handle it.

cabling

Connect RPi & mh-z19 as:

  • 5V on RPi and Vin on mh-z19
  • GND(0v) on RPi and GND on mh-z19
  • TxD and RxD are connected to cross between RPi and mh-z18

Followings are example of cabling, but you can free to use other 5v and 0v Pin on the RPi.

pi@raspberrypi:~/mh-z19 $ gpio readall
 +-----+-----+---------+------+---+---Pi B+--+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5v      |     |     |  >> import mh_z19
>>> mh_z19.read_all()
{'SS': 232, 'UhUl': 10738, 'TT': 61, 'co2': 734, 'temperature': 21}
>>> 

Use specific serial device.

In case you should use specific serial device instead of Raspberry Pi default serial device which this library automatically select, for example in case to need to use /dev/ttyUSB0 for FT232 usb-serial converter as issue#12, you can specify serial device by --serial_device option as follows:

bash
sudo python -m mh_z19 --serial_device /dev/ttyUSB0

How to use without root permission.

See this wiki.

How to use in your program.

See this wiki.

PWM support.

See this wiki.

In case you can't get the value.

Even if cabling seems no problem and uart seems to be prepateted well but you can't get sensor value. As nincube8 suggested that the pull up by 1-5kΩ register can be working solution. Thank you nincube8!

Q&A

The forum is avai at here. Any questions, suggestions, reports are welcome!

Blog

  • How to Measure ROOM CO2 concentration with 20$ sensor "MH-Z19" and Raspberry Pi.
  • Monitoring all over the world with 3G Network for not more than 10$ monthly payment.
  • How to make shareable SD card by Raspberry Pi & PC.

References

  • MH-H19B DataSheet version 1.5
  • MH-H19 DataSheet version 1.0
  • MH-H19B DataSheet version 1.0
  • RevSpace

history

  • 0.1.0 2018.09.13 first version self-forked from slider.
  • 0.2.2 2018.11.19 introduce pondslider and separate this PyPi package.
  • 2.0.0 2019.01.18 Add Calibration, ABC on/off requested by this issue. Please refer this wiki.
  • 0.3.5 2019.01.22 Both Python2 & Python3 support
  • 2.3.6 2019.01.22 Merge Pull Request #3 & Pull Request #4. Thanks David!
  • 2.3.7 2019.02.25 Add --all option which requested as issue#5, thanks Rafał!
  • 2.3.8 2019.04.16 Merge Pull Request #7. Thanks Alexander!
  • 2.3.8.1 2019.04.20 Merge Pull Request #8. Thanks WO15!
  • 2.3.8.5 2019.04.21 Merge Pull Request #9. Thanks WO15!
  • 2.3.8.6 2019.04.22 Merge Pull Request #10. Thanks WO15!
  • 2.3.9 2019.05.06 Revise the serial port selection logic. Support using PL011 uart on Raspberry Pi Model 3 and Zero W which is selected by setting dtoverlay=pi3-miniuart-bt or dtoverlay=pi3-disable-bt. Thanks 片岡さん for your kindly report including this issue!
  • 2.4.1 2019.08.11 Add --serial_device option as solution of issue#12. Thanks Actpohomoc and TBR-BRD!
  • 2.4.2 2019.12.12 Merge Pull Request #15. Thanks WO15!
  • 2.5.1 2020.05.16 Add --serial_console_untouched option to support execution without sudo asked as issue#17. Thanks ralphbe91!
  • 2.5.2 2020.06.30 Update the link for datasheet of MH-Z19B from version 1.0 to version 1.5 based be pointed it out as issue#18. Thanks WO15!
  • 2.6.1 2020.07.07 Add --detection_range_10000 option to support Set 0~10000ppm detection range asked as issue#19. Thanks WO15!
  • 2.6.3 2020.08.27 Fix issue#21. Thanks idegre!
  • 3.0.0 2021.02.05 PWM support.
  • 3.0.1 2021.02.17 Fix a degradation of not running with python3. Thank you Masahiko OHKUBO san for your report.
  • 3.0.2 2021.03.25 Fix to support RPi4 correctly as issue#29. Thanks iperniaf!
  • 3.0.3 2021.11.08 Fix issue#35. Thanks false!
  • 3.0.4 2011.11.11 Fix issue#36. Thanks David Bock
  • 3.0.5 2022.01.01 Fix issue#38. Thanks kzehnter!
  • 3.1.0 2022.01.22 add --co2valueonly option by merging issue#39 and issue#40. Thanks jonesthefox!
  • 3.1.1 2022.01.23 remove code clone.
  • 3.1.2 2022.01.31 Fix issue#41. Thanks Christopher M. Pierce!
  • 3.1.3 2022.02.25 Fix issue#43. Thanks Jannis Möller!
  • 3.1.4 2023.11.14 Don't install python2-pip if OS version is BullsEye or later.
  • 3.1.5 2024.05.06 FIx issue#53. Thanks Tats Shibata
  • 3.1.6 2024.08.29 FIx issue#54. Thanks 80kpc
  • 3.1.7 2025.03.01 drop the RPi.GPIO dependenc. Thanks mroelandts
  •   2026.07.36 send2monitor.py support Python 3.13

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythoncalibrationmh-z19monitorpython

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言