According to Japan Meteorological Agency, aging of carbon dioxide concentration, the average global CO2 concentration in 2018 is compared with the previous year. It is said that it has increased by 2.3ppm to 407.8ppm.
It is worrisome that the CO2 concentration continues to increase due to global warming, but the current concerns about the epidemic of the new coronavirus are "sealed," "dense," and "close." The question is whether the room is properly ventilated to avoid the risk of "sealing" in the dense.
About the indoor CO2 concentration Ministry of Health, Labor and Welfare Building Environmental Sanitation Management Standards shows 1,000 ppm or less Ministry of Education, Culture, Sports, Science and Technology School Environmental Hygiene Standards shows 1,500 ppm or less Is the management standard. Also, this figure compiled by CHC GROUP may be helpful. (Source: http://group.chcsys.net/jp/chcgroup/)
I wanted to have proper data on the CO2 concentration of my place in comparison with the standard, so I decided to measure it using a sensor.
Raspberry Pi 3 Model B CO2 sensor MH-Z19B
OS Debian GNU/Linux Linux raspberrypi 4.19.97-v7+ #1294 SMP Thu Jan 30 13:15:58 GMT 2020 armv7l
Enable Serial Port in Raspberry Pi Settings-Interface.
Restart the Raspberry Pi after enabling the Serial Port.
Solder the wiring to each of GND, Vin, TxD, and RxD. (From the wiring diagram https://pypi.org/project/mh-z19/)
Connect the Raspberry Pi and the CO2 sensor according to the wiring diagram.
Based on the information at https://pypi.org/project/mh-z19/. Package installation
$ sudo pip3 install mh-z19
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting mh-z19
Downloading https://www.piwheels.org/simple/mh-z19/mh_z19-0.4.1-py3-none-any.whl
Collecting argparse (from mh-z19)
Downloading https://files.pythonhosted.org/packages/f2/94/3af39d34be01a24a6e65433d19e107099374224905f1e0cc6bbe1fd22a2f/argparse-1.4.0-py2.py3-none-any.whl
Requirement already satisfied: pyserial in /usr/lib/python3/dist-packages (from mh-z19) (3.4)
Collecting getrpimodel (from mh-z19)
Downloading https://www.piwheels.org/simple/getrpimodel/getrpimodel-0.1.15-py3-none-any.whl
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from mh-z19) (2.21.0)
Installing collected packages: argparse, getrpimodel, mh-z19
Successfully installed argparse-1.4.0 getrpimodel-0.1.15 mh-z19-0.4.1
~~ Module mh_z19 seems to output the result in dictionary type. ~~ Module mh_z19 seems to output the result in JSON. (I received an edit request from @UedaTakeyuki. Thank you.)
$ sudo python3 -m mh_z19
{"co2": 1456}
The measured value is output together with the date and time.
import datetime
import mh_z19
now = datetime.datetime.now()
now = "{0:%Y-%m-%d %H:%M:%S}".format(now)
value = mh_z19.read().get("co2") # ex: {"co2": 1456}
out = now + ',' + str(value)
print(out) #Output to console
Output result
2020-04-15 19:34:01,1950
Redirects the result of standard output to a log file. do.sh
#!/bin/sh
cd /home/pi/mh-z19
sudo python3 MeasureAndOutput.py >> ./log/logfile.csv
Put the shell script into executable mode.
$ chmod +x do.sh
$ crontab -e
The editor will start, so set it to measure every minute and output the log.
# m h dom mon dow command
* * * * * mh-z19/do.sh
Restart cron for the settings to take effect.
$ sudo /etc/init.d/cron restart
[ ok ] Restarting cron (via systemctl): cron.service.
When I checked it a few minutes later, the log was output according to the scenario.
$ cat logfile.csv
2020-04-15 19:34:01,1950
2020-04-15 19:35:02,1957
2020-04-15 19:36:01,1965
2020-04-15 19:37:01,1976
2020-04-15 19:38:02,1983
2020-04-15 19:39:01,1996
2020-04-15 19:40:01,2032
Based on the output log file, I tried to make a graph manually for the time being.
・ Alert to LINE Bot when the concentration exceeds a certain level ・ Voice alert by smart speaker
@revsystem https://qiita.com/revsystem/items/76ab1e21d386c5977892 @tororu https://qiita.com/tororu/items/20e8625d3fb24f3e06da @UedaTakeyuki https://qiita.com/UedaTakeyuki/items/c5226960a7328155635f
Recommended Posts