How to Measure ROOM CO2 concentration with 20$ sensor "MH-Z19" and Raspberry Pi, 2nd edition.

MH-Z19 CO2 concentration Sensor

MH-Z19 is small, low-cost, weigh 15g CO2 sensor module product by 郑州炜盛电子科技.
You can buy it at online shop like eBay or aliexpress about 20$.



The electrical interface of this sensor is compatible with Raspberry Pi. So you can make your D.I.Y. CO2 Monitor with MH-Z19, Raspberry Pi .



Normal CO2 concentration is about 400ppm. On a global scale, this value is sensitive to the effect of the activities of the plants, seasonally it get lower in summer due to vigorous plants photosynthesis and getting higher in winter, and the long range trend is continue to rise linearly. The Japanese Meteorological Agency report CO2 concentration chart continuously as hire. It indicate clear trend of rising.

On your room scale, in a closed room with 2 person, CO2 concentration rise up to 1,200ppm soon, and keep falling slowly after 1 person go out.


In high CO2 concentration room as 1200ppm, somebody can get a headache or sleepiness.

But no need to concern about it. It fall down rapidly to about 400ppm after just open the window.


So, let's open the window and get fresh air to refresh your head when CO2 concentration is getting higher.
Let's measure your room CO2 concentration yourself by MH-Z19 sensor and Raspberry Pi.




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 connect to cross between RPi and mh-z18 

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


Install & Setup mh-z19 software

The software library to handle MH-Z19 sensor on the Raspberry Pi is available as here.

You can download latest release or git clone as:

git clone https://github.com/UedaTakeyuki/mh-z19.git


Then, go into this directory and call setup.sh command as follows:

./setup.sh 
All required software will be installed and setuped.

Read CO2 concentration value

Read MH-Z19 sensor value as follows:

pi@raspberrypi:~ $ sudo python -m mh_z19 
{'co2': 668}
"Sudo" might be necessary because mh_z19 manage Serial Port.

Send sensor value to MONITOR™ to view Chart.

MONITOR™ is a free web service of a Still Picture based Remote Watching and Sensor data viewing like as following pictures.



Please refer this introduction to grasp birds-eye understanding about MONIOR™.

A free account is available as follow.
Then, login and get a value_id which is unique id to point a data area on the MONITOR™ to show latest value and chart. Please refer here for detail.

After get a value_id at your browser, return to terminal of your Raspberry Pi, then you should set your mh_z19 software to send measured value to send to the value_id. To do this, call setid.sh command in the mh_z19 installed directory. Let's say your value_id is vpgpargj, then issue setid.sh command as follows:

./setid.sh vpgpargj
Then, call "pondslider" python script as follows:

pi@raspberrypi:~/mh-z19 $ sudo python -m pondslider
{'co2': 742}

In the same time, your time-series chart on the MONITOR™ display shoud be updated by the latest CO2 concentration value.

In case return value indicated as follows:


{"ok":false,"reason":"ViewID not valid"}
The most possible cause is you've specified wrong value_id. Please make shore the value_id which you've set by setid.sh.

Set automatically start to send CO2 data to MONITOR™ at 5 minute interval at Raspberry Pi start up time.

You can set it by autostart.sh command in the mh_z19 installed directory as follows:

./autostart.sh --on

You can turn off this as follows:

./autostart.sh --off

Also, you can check current status as follows:

./autostart.sh --status


Comments

Popular posts from this 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