Zonnestroompanelen in Nederland

duurzaamheid achter de meter

(50) Carbon dioxide recording in the office with an ESP8266

by Floris Wouterlood – The Netherlands – July 1, 2021

Summary
Here we assemble a device that monitors air quality. Main parts are: CCS811 carbon dioxide sensor, ESP8266 Wemos D1 mini microcontroller, 1.6 inch TFT display, 130*130 pixels. The Arduino sketch instructs the sensor to sample air every four seconds, calculates a rolling average of five sample iterations and uploads the calculated average carbon dioxide level via wifi and the internet to an account at Thingspeak. If wifi is unavailable this device works standalone, without logging.

Introduction
Working in an office at home requires a healthy indoor atmosphere, say fresh air. Therefore It is useful to have information accessible about local air quality. Does for instance air quality in the office deteriorate in time? When is it urgent to open a window to let fresh air enter? The amount of CO2 inside rooms and offices is often used as an indicator for air quality. A high level signals poor air while a low level indicates fresh air. In my office temperature and humidity are already constantly monitored with Arduino devices, so I decided to construct a desktop carbon dioxide (CO2) monitoring unit.

 

figure 1. The office CO2 monitor – recorder up and running.

The Arduino compatible CCS811 carbon dioxide sensor is applied here. This sensor measures electronically the concentration of carbon dioxide and also reports on volatile gases. The sensor is connected here to a Wemos D1 mini ESP8266 microcontroller board. Data display is on a 130*130 pixel, 1.6 inch TFT screen. Logging is done by uploading data via wifi to an account on a server at Thingspeak. The device is developed from earlier projects *, **

Sensor

figure 2. A CCS811 CO2 sensor breakout board for the Arduino.

In a previous project** I discussed the CCS811 carbon dioxide sensor breakout board. The manufacturer claims that the CCS811 performs the following:

  • measures CO2 in a range between 400 – 29,206 ppm (parts per million),
  • measures Total Volatile Organic Compounds (TVOC) between 0 – 32,768 ppb (parts per billion),
  • calculates values via an internal compensation algorithm using external ambient temperature and humidity data sources,
  • has a temperature range for operation between -40 oC to +80 oC,
  • communicates via the i2c interface.

The sensor is Arduino compatible while there are two libraries available to read the sensor: “Adafruit_CCS811.h” and “SparkFunCCS811.h”. I tested both and obtained stable and realistic values with the Adafruit library.

Wemos D1 mini and 1.6 inch 130*130 TFT display
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 has 3.3V control logic on board. The sensor that I purchased was not equipped with a 5V-3.3V voltage regulator. As classical Arduino controller logic operates at 5V, voltage reduction needs to be applied with Arduinos in all communication wires. ESP8266 based microprocessor boards operate natively at 3.3V and offer in addition the supreme advantage of on board Wifi. Accessibility of the internet makes it possible to outsource data logging to a website.
The Wemos D1 mini is a small-footprint microcontroller board that belongs to the ESP8266 family. It is programmable via an expansion of the familiar Arduino IDE using Arduino C++ syntax. It is cheap, reliable and endurable. Together these features make the Wemos D1 mini a good companion for hobby purposes. Because the i2c interface of an CSS811 sensor requires only two pins , sufficient pins remain available to connect a display through a 5-wire SPI interface. All wiring is shown in figure 3.

 

Figure 3. Board layout and wiring. Top view. The board is a 7*9 cm soldering board. The three major components: sensor, microcontroller board and display, are mounted on header sockets. 4.7 kΩ pull up resistors are necessary to acquire optimal i2c signal from the sensor. A usb-mini breakout jacket (‘usb mini’) is included in the design as a handy means at normal operation to receive power from a 5V external DC power adapter (powering the Vin pin of the Wemos D1 mini). The purpose of the led is to allow signaling of various actions through series of flashes.

Display
Here we selected a 130*130 pixel, 1.6 inch diagonal SPI transflective TFT display with SSD1283A controller. The advantage of this type of display over OLEDs is a relatively big, multicolor screen with big pixel dimensions, with enough pixels and enough resolution to draw an ‘analog’ scale with a needle pointer, and with some space left over to display the CO2 concentration alphanumerically. The entire assembly easily fits a 7*9 cm soldering board.

Electronic components needed
1x CCS811 CO2 sensor breakout board, 1x Wemos D1 mini microcontroller board, 1x 1.6 inch SPI TFT 130*130 display, 1 piece 7*9 cm two-sided soldering board, 1x mini usb connector breakout board, 4x 8-pin socket header, 1x led, 1x 220 Ω resistor, 2x 4.7 kΩ resistor, wires, 4x nylon M2 spacers, 4x nylon screws.

Wiring
As the CCS811 communicates via the i2c protocol, two pin connections matter: SDA (data) and SCL (clock). Pins WAK and GND must both be connected to Ground, and VCC must receive 3.3V DC from some source, usually a 3.3V pin on the microcontroller board (figure 3).

figure 4: Top and bottom pictures of the board. The sensor breakout, Wemos D1 and TFT display removed to reveal their header sockets. The white cord inserted in the mini usb jacket on the bottom picture is the 5V DC power supply usb cable. 5V DC power is wired to the Vin pin of the Wemos D1 mini (on the board marked as ‘5V’).

The display needs 5 wires for the SPI interface (CS, RST, A0, SDA, SCK), two power wires and one GND wire. One pin of the microcontroller is wired to the led, via a 220 Ω resistor to produce low intensity light when the led blinks.
All wiring consists of code-colored wires that connect header sockets. The use of such sockets makes exchange of major components very easy. The left panel of figure 3 shows the completed board just before the sensor, microcontroller and display were mounted. Figure 5 shows the fully assembled device.

Sketch
Note: the library “Adafruit_CCS811.h” is required to compile this sketch. It can be installed via the Library manager in the Arduino IDE, or else located on the internet, downloaded and installed.
The sketch itself is straightforward. Measurements are made every 4 seconds. CO2 and TVOC readings are processed through a five-iteration rolling average function and then presented in Serial Monitor. The rolling average smoothes upticks and downticks in the CO2 logging and produces a dampened logging graph. A timer forces every 60 seconds an upload session of the averaged CO2 and TVOC values to an account at Thingspeak.com. If no wifi is available or if wifi is inaccessible, data is not uploaded while the monitoring and display continues in offline, standalone mode.

 

figure 5: A complete, working office CO2 monitor.

Results
As one may notice in figure 1 there is no casing containing the carbon dioxide monitor-recorder. Any casing, even one with perforations, slits or an opening in front of the sensor, presents an obstacle for the air that must flow freely around the sensor to get accurate readings. No casing, therefore.
The office CO2 monitor-recorder has found its niche in my office. The device’s power supply adapter is inserted in the same power strip as my computer and wifi gear. As soon as I flip the switch on the power strip my computer, wifi, and CO2 monitoring are started. The rolling average function causes the the needle on the display to move to the ambient carbon dioxide level in about 30 seconds. In the mean time wifi connection is established between the CO2 recorder and the internet, and after a minute data upload starts. The led flashes 5 times in rapid succession after each successful upload,
In figure 5 some typical results of an operational setup in the Wemos D1 mini test bench* are shown.

figure 6: Browser screenshot of ambient CO2 level (left) and graphic representation (right) via an account at Thingspeak.com. One advantage of the Thingspeak account is that there are several analysis tools. Data can be downloaded as well in csv format for local processing.

It should be mentioned here that a CCS811 has tow peculiar characteristics. First, it is a ‘slow responder’: after switching on it takes several minutes for the sensor to stabilize. Second, a new sensor needs a couple of days of being permanently switched-on to acquire initial ‘burn in’. Initial measurements with a brand new sensor can be disappointing; just let it run for some days and then start serious logging.

Downloadable sketches

  • Bare sketch for standalone operation. No wifi and no upload, just the actual CO2 level expressed in ppm.
  • Sketch for IOT operation. Wifi is necessary and a registered account (free account) at www.thingspeak.com. This sketch will also run when no wifi is available

The ‘bare’ sketch is named ESP8266_CO2_monitor_standalone.ino
The ‘IOT’ sketch is named ESP8266_CO2_monitor_IOT.ino. In this sketch you must enter the SSID and key of your own wifi network as well as the API key of your Thingspeak account.

Both sketches are packed into one ZIP file: ESP8266_CO2_monitor.zip

References – previous projects

*Test bench with a Wemos D1 mini and a 130*130 TFT display with SSD1283A controller, by Floris Wouterlood, July 8, 2020. https://thesolaruniverse.wordpress.com/2020/07/09/test-bench-with-a-wemos-d1-mini-and-a-130130-tft-display-with-ssd1283a-controller/

**CCS811 carbon dioxide sensor breakout and the Arduino, by Floris Wouterlood, November 26, 2020
https://thesolaruniverse.wordpress.com/2020/11/26/ccs811-carbon-dioxide-sensor-breakout-and-the-arduino/