Read CO2 concentration from mh-z19 sensor on the Raspberry Pi & handle it. Detect Raspberry Pi model automatically and read the value from an appropriate serial
Read CO2 concentration from mh-z19 sensor on the Raspberry Pi & handle it. Detect Raspberry Pi model automatically and read the value from an appropriate serial
Read CO2 concentration from mh-z19 sensor and handle it.
Connect RPi & mh-z19 as:
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}
>>> 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:
sudo python -m mh_z19 --serial_device /dev/ttyUSB0See this wiki.
See this wiki.
See this wiki.
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!
The forum is avai at here. Any questions, suggestions, reports are welcome!
--co2valueonly option by merging issue#39 and issue#40. Thanks jonesthefox! 2026.07.36 send2monitor.py support Python 3.13No open issues yet, or sync has not completed.