I’ve had a low cost carbon dioxide (CO2) sensor sitting on my desk for over a year! I thought why not get this thing recording, as I have already done a load of work sending data to MQTT feeds.
I did a quick search and found this overview for getting started with this sensor: https://www.hackster.io/kritch83/getting-started-with-the-mh-z14a-co2-detector-e96234. This had everything I needed to be able to connect via serial connection and get the CO2 data.
I connected the unit to my ‘Cheeseboard’ ESP8266 development board. The connections were for 5V power and for a 9600 baud rate serial connection for data.
|GND||GND – PIN 2, 3, 12, 16||GND|
|+5V||Power – PIN 1, 15, 17||Vin|
|Serial||Tx – PIN 10, 13, 19||Rx – PIN D2|
|Serial||Rx – PIN 11, 14, 18||Tx – PIN D1|
Using my workshop environment monitor code, I quickly had a template for sending some CO2 parts per million data to AdafruitIO (one of my last free feeds!). I have created a (hacky!) code here for you to upload and be able to send data to an AdafruitIO feed. You will need to create an account and link to it with you AdafruitIO Key.
Github Repository for the code is here: https://github.com/curiouselectric/CO2Monitor
So running the unit for a day or so, here is a graph of the CO2 level in my office room (ignore the very initial data before 8pm, as this was testing…).
I was not quite sure what was ‘normal’. I know that atmospheric CO2 levels are in the region of 400ppm (which is too much, by the way!). In an enclosed room then the level will always be higher than this and with occupancy then the CO2 level will rise, so you can tell when I was in and out of the room. I found some data here (from Velux, the window people) that says that a good reading would be around 1150 ppm, 1400 ppm would be adequate, but 1600 ppm or higher would be poor.
Obviously CO2 levels are only one factor within air quality. Particulates and other solvents are also important. I built this workshop environment monitor, which includes particulates, temperature, humidity and radiation levels!
In order to set an alarm that the CO2 level in a room is too high there are two aspects: the actual CO2 level and the length of time that the room has been at that level.
I decided to create an algorithm that uses a mixture of the level and the time that the room has been at that level. In maths terms this would be integrating the CO2 to find total exposure. So I need to keep track of the time. When the CO2 level is above 1200ppm then the unit starts a timer. The integral of the CO2 level (value x timestep) is monitored. If it goes above an integral value of 1200ppm for 30 mins then it will raise an alarm. It will also raise an alarm if the values is over 1600ppm (with no timer). Below 1200ppm then the integral value is reset back to zero.
The unit will also show a varying CO2 ppm level as the PWM brightness of the LED light from 1200 – 1600ppm will go from 0 – 100%.
Other CO2 sensor units:
This is a set of (slightly random) link of other C02 sensor units that might be useful:
- Sensirion SDC41
- Photo-acoustic with temperature and humidity calibration.
- Keyestudio CCS811