by Floris Wouterlood – The Netherlands – November 18, 2020
Clean, fresh air and the feeling of comfort and health go hand in hand. Air quality, especially in cold climates inside the home during winter when windows are closed and the heating is on, can unnoticeably deteriorate to intolerable levels. The quality of the air inside a home can be described with several parameters: temperature, humidity, particles, volatile compounds. The amount of carbon dioxide is often used as an indication for how fresh the air in a room is. Here we connect a CCS811 carbon dioxide sensor breakout board to an Arduino. The CCS811 measures the concentration of carbon dioxide and volatile gases in atmospheric air.
Every time we breathe we take in some oxygen and we release a certain amount of carbon dioxide. One average person is believed to release as much as two pounds of carbon dioxide per day. In poorly ventilated spaces oxygen depletes and carbon dioxide slowly builds up. At a certain point this condition can become harmful and eventually may lead to a condition called ‘respiratory failure’: shortness of breath, inability to concentrate, work or exercise, and sleepiness. An airtight bedroom seems not to be a good place to sleep in. Classrooms in old schools are notorious for poor ventilation.
figure 1. CS811 breakout board for Arduino. VCC needs 3.3V, GND and WAK are connected to GND, SCL and SDA are the i2c connections with a microcontroller board while INT, RST and ADD are not connected.
The quality of the air around us can be measured. Most important air quality parameters are: temperature, relative humidity, particles, fine dust, micro-organisms, volatile gases, oxygen and carbon dioxide (CO2). We pay attention here to the CO2 concentration because the amount of this gas is often used as a measure of how ‘fresh’ air is, that is the degree of ventilation. Air inside the home needs to be replaced every now and then to get rid of accumulated respiratory CO2 but also of CO2 produced by cooking, smoking or other activities involving flames. Ventilation is also paramount in order to get rid of accumulated water vapor, and to reduce the amount of dust in the air.
In the winter in northern parts of Europe, Asia and America heating the home goes hand in hand with reducing ventilation in order to save fuel. Basically this is a poor concept. In overly sealed homes the quality of the inside air may deteriorate to unhealthy levels; additional technical measures are then necessary.
Measuring CO2 concentrations
How does one measure CO2? Of course one can order a ready-to-go CO2 monitor via the internet, with or without automatic calibration or logging function. What we do here is to go to the basics: the sensor itself. As there are several ways to determine atmospheric CO2 it is not surprising to find on the market sensors using infrared detection and chemical sensors. Here we connect a CCS811 chemical sensor to an Arduino. The manufacturer claims that sensor determines the following:
• equivalent carbon dioxide range between 400ppm up to 29206 parts per million (ppm),
• equivalent Total Volatile Organic Compounds (TVOC) from 0 parts per billion (ppb) up to 32768 ppb,
• An internal compensation algorithm using external ambient temperature and humidity data sources,
• temperature range for operation -40C to +80C.
In other words: this sensor can be used to measure CO2 and since we are rather interested in changes of CO2 amounts and not in exact concentrations a CCS811 may be of good use to get an indication of how well areas are ventilated during the day, night or both.
Wemos D1 mini
Although it is very well possible to connect a CCS811 with an Arduino Uno or Nano one has to take into account that the CCS811 breakout board here is designed for use with microprocessors that operate at 3.3V. Although classical Arduinos are equipped with a 3.3V power supply pin, their controller logic operates at 5V which means that voltage-reducing resistors need to be included in all wires running to the CCS811. 220 Ω resistors can be used for this purpose.
All the ESP8266 based microprocessor boards operate at 3.3V and next to that have several advantages over Arduinos. The most important of these is on board Wifi. With this feature transmission of data is possible directly from the microcontroller board to a Wifi device connected to the internet.
The Wemos D1 mini (featured in figure 2) belongs to the family of ESP8266 microcontroller boards. It is programmable via the familiar Arduino IDE using Arduino syntax. It is cheap, endurable and it has a small footprint. Together these features make the Wemos D1 mini highly attractive for hobby purposes.
Figure 2. CCS811 wired to a Wemos D1 mini ESP8266 microcontroller board. Because the Wemos operates at 3.3V there is no need for voltage reduction in the functional connections to the sensor board. The 4.7 kΩ pull up resistors are positioned here between the SDA and SCL lines and 3.3V to get optimal i2c signal from the sensor.
Electronic components needed
1x CCS811 CO2 sensor breakout board, 1x Wemos D1 mini microcontroller board, prototyping breadboard, 2x 4.7 kΩ resistor, jumper wires. Additional: display (see fig. 3).
As the CCS811 communicates via the i2c protocol two connections matter: SDA (data) and SCL (clock). WAK and GND need both to be connected to Ground, and VCC must receive 3.3V DC from some source, usually a 3.3V pin on the microcontroller board (figure 2).
Wiring becomes more complicated when a display is added to the configuration (figure 4). A 1.6 inch 130*130 pixel TFT display was selected for this purpose. This display communicates via the SPI protocol and for that matter needs 8 wires. As wiring and connecting this TFT display is out of scope of the current paper it is described in another paper where it is conveniently included in a Wemos test bench*.
Note: the library “Adafruit_CCS811.h” is required to compile this sketch. It can be installed via Library manager in the Arduino IDE or else located on the internet and downloaded.
The sketch itself is straightforward. Every second a sample is taken. Readings are shown in Serial Monitor. The sketch below is the CCS811_wemos_serial_monitor.ino included in the Download Sketches section at the end of this post
figure 3: basic CCS811 sketch for the Wemos D1 mini with output to Serial Monitor
Addition: 1.6 inch, 130*130 pixel TFT display with a SSD1283A controller
As sketch number one is a ‘bare bones’ sketch, it was appended with code to address the 130*130 TFT display. It is always nice to have visual output. The dimensions of this particular display (1.6 inch across) matches the Wemos D1 mini very well. A display like this can be included in a small CO2 measuring unit that can be taken to any room to conduct measurements. In figure 5 the results of an operational setup in the Wemos D1 mini test bench* is shown.
figure 4: wiring of the CCS811 with a Wemos D1 mini and 130*130 SSD1283A TFT display
figure 5: CCS811 at work in my Wemos D1 mini test bench.
Sketch 2 was written for the test bench shown in figure 5. CO2 and TVOC levels reported by the CCS811 are displayed on screen. The sketch is an expansion of the ‘bare’ CCS811_wemos_serial_monitor.ino
basic sketch: CCS811_wemos_serial_monitor.ino
sketch with TFT display support: CCS811_wemos_130x130_TFT_display.ino
Both sketches are packed into one ZIP file: CCS811_wemos.zip
Test bench with a Wemos D1 mini and a 130*130 TFT display with SSD1283A controller, by Floris Wouterlood, The Solaruniverse, 8 july 2020.