Add Compensated Air Quality Sensors to the Internet of Things

Contributed By Digi-Key's North American Editors

By adding air quality sensors to smart building systems, engineers can implement early warning of the buildup of hazardous gasses and chemicals, but commercial air quality sensors lack the integrated capabilities required to join a smart building network. However, by turning to easy-to-use development kits, engineers can add the processing power and wireless capability demanded to overcome this deficiency.

The most popular type of air quality device for determining the ppm concentration of CO2 or volatile organic compounds (VOCs) in the environment is based on a semiconductor electrochemical element that generates an output voltage proportional to the concentration of the gas or chemical being measured. However, the measurement precision is affected by both temperature and humidity. Temperature and humidity sensors—which could provide the data for a continuous compensation algorithm to improve the accuracy of an air quality sensor’s output—are not routinely integrated with this type of air quality sensor.

In addition, the current range of air quality sensors lack the wireless technology common to other sensor types and required for connectivity to smart building networks.

These deficiencies make it more difficult for an engineer to design air quality sensors for wireless networks for domestic, commercial, and industrial applications.

However, the recent introduction of development kits for air quality monitoring products that include temperature and humidity sensors as well as wireless connectivity, eases the design challenge. This article describes how to use these development kits to shorten the design cycle for an air quality product.

MOS sensor characteristics

There are several types of sensors for monitoring air quality. Examples include electrochemical (EC), nondispersive infrared (NDIR), photoionization detectors (PID), and thermal.

But it is the metal oxide semiconductor (MOS) type that most closely matches the monitoring requirements for smart building applications. The devices are compact, relatively inexpensive, can run from batteries (with sufficient capacity to periodically power the MOS sensor’s heater), and the detection range matches the typical concentrations of C02 and VOCs in indoor workplaces (Figure 1).

Graph of change in concentration of CO2 and VOCs in a bedroom

Figure 1: Change in concentration of CO2 and VOCs in a bedroom throughout the day. (Image source: IDT)

In operation, the sensing element is heated to several hundred degrees Celsius (˚C). The precise temperature determines the element’s selectivity to a particular gas or chemical. The sensitivity depends on the material’s thickness.

The sensors are manufactured with either n-type or p-type semiconductor sensing elements. The sensing element either absorbs (p-type) or desorbs (n-type) the target chemical, and an electrochemical reaction with the target compound either adds or removes electrons from the semiconductor’s conduction band. Electron migration linearly changes the sensing element’s resistivity or conductivity from a known baseline value (Figure 2).

Graph of resistivity of a MOS sensor element

Figure 2: The resistivity of a MOS sensor element changes linearly in response to a change in the concentration of the target chemical. In this example it’s ethanol. (Image source: IDT)

One commercial MOS sensor for smart home applications is supplied by ams. The CCS811B is a digital MOS sensor solution which incorporates a microcontroller, analog-to-digital converter (ADC), and an I2C interface (Figure 3). The device processes raw sensor measurements to output “equivalent total VOC” (eTVOC) and “equivalent CO2” (eCO2) values. The sensor is available in a 10-lead 2.7 x 4.0 x 1.1 millimeter (mm) package.

Diagram of ams’ CCS811B digital MOS sensor

Figure 3: ams’ CCS811B digital MOS sensor includes a microcontroller for onboard processing of raw sensor data. (Image source: ams)

Each MOS sensor has a characteristic baseline resistance for a given air composition, temperature, and humidity. This is used as the basis for calculating the gas or chemical concentration: the difference in resistance from the baseline value is proportional to the gas or chemical concentration.

In the field, ambient temperature and humidity affect the baseline resistance of the sensor element changing its sensitivity, and in turn, accuracy. An increase in ambient temperature, for example, increases the sensor element’s baseline resistance (for a given humidity), while an increase in humidity can lower the baseline resistance (for a given temperature).

Sensor makers advise pairing the air quality sensor with temperature and humidity sensors so that a supervisory microprocessor can run an algorithm to continually compensate for variations in baseline resistance.

A popular device for this application is Bosch Sensortec’s BME280. The BME280 combines digital humidity, pressure and temperature into an LGA package with a footprint of 2.5 x 2.5 x 0.93 mm. The sensor has an I2C interface to communicate with an external microprocessor and requires a power supply from 1.71 to 3.6 volts (V) for the sensor supply. When the sensor is in a sleep mode, current consumption drops to 0.1 microamps (μA).

Commercial MOS sensors lack the built-in connectivity required to join a wireless network. However, there are many low power wireless chips designed to interface directly with sensors. Many of these devices also include embedded microprocessors which are powerful enough to run the algorithms required to process the raw sensor data and compensate for humidity and temperature variations. (For more information on suitable wireless technologies for this application see the Digi-Key article “Comparing Low-Power Wireless Technologies”.)

Developing a basic air quality sensor

Designing a wirelessly connected air quality monitor requires the engineer to combine a discrete MOS sensor, humidity and temperature sensor, wireless transceiver, and (in some cases) a microprocessor into a working system. Such complexity can make this a daunting and time-consuming task.

However, there are a selection of development kits on the market that considerably ease the initial design and testing process. For example, SparkFun Electronics’ SEN-14348 Qwiic Environmental Combo Breakout for air quality sensor development combines a CCS811B air quality sensor with a BME280 sensor for temperature and humidity compensation, and includes two physical I2C interfaces in the shape of 4-pin polarized Qwiic connectors (Figure 4).

Image of SparkFun’s SEN-14348 breakout

Figure 4: SparkFun’s SEN-14348 breakout combines a CCS811B sensor with a BME280 device for temperature and humidity compensation. (Image source: SparkFun)

Although the SEN-14348 can be used as the basis of a temperature and humidity compensated air quality sensor design, it isn’t a comprehensive solution. While the CCS811B includes a microprocessor, the device has limited capability beyond supervising periodic measurements and performing baseline compensation. More complex applications, such as monitoring air quality thresholds or calculating long term gas or chemical concentrations are beyond the microprocessor’s capability. To support more advanced applications with the SEN-14348, it needs to be connected to a more capable microprocessor.

For initial development, SparkFun suggests connecting the SEN-14348 breakout to an Arduino compatible computer such as its RedBoard. The RedBoard connects to a PC via a USB cable (which also provides power to the board) for uploading code from the Arduino IDE. To use the RedBoard with the Qwiic breakout, the computer needs to be adapted with a DEV-14352 Qwiic shield. The shield houses an I2C connector and also regulates the 5 volt RedBoard supply down to the 3.3 volts required for the sensors on the SEN-14348 breakout.

To get things started, the developer needs to download the SparkFun CCS811 and BME280 Arduino libraries from Github. The sensors are configured from the Arduino IDE with information such as sampling rate, finite impulse response (FIR) filter coefficients and oversampling modes.

The code snippet below shows the routine to initialize the BME280 sensor prior to taking readings (the initialization routine for the CCS811 is similar).

Copy

#include <SparkFunBME280.h>

#include <SparkFunCCS811.h>

#define CCS811_ADDR 0x5B //Default I2C Address

//#define CCS811_ADDR 0x5A //Alternate I2C Address

//Global sensor objects

CCS811 myCCS811(CCS811_ADDR);

BME280 myBME280;

void setup()

{

  Serial.begin(9600);

  Serial.println();

  Serial.println("Apply BME280 data to CCS811 for compensatio

n.");

  //This begins the CCS811 sensor and prints error status of .

begin()

  CCS811Core::status returnCode = myCCS811.begin();

  if (returnCode != CCS811Core::SENSOR_SUCCESS)

  {

    Serial.println("Problem with CCS811");

    printDriverError(returnCode);

  }

else {

    Serial.println("CCS811 online");

  }

  //Initialize BME280

  //For I2C, enable the following and disable the SPI section

  myBME280.settings.commInterface = I2C_MODE;

  myBME280.settings.I2CAddress = 0x77;

  myBME280.settings.runMode = 3; //Normal mode

  myBME280.settings.tStandby = 0;

  myBME280.settings.filter = 4;

  myBME280.settings.tempOverSample = 5;

  myBME280.settings.pressOverSample = 5;

  myBME280.settings.humidOverSample = 5;

  //Calling .begin() causes the settings to be loaded

  delay(10);  //Make sure sensor had enough time to turn on. B

ME280 requires 2ms to start up.

  byte id = myBME280.begin(); //Returns ID of 0x60 if successf

ul

  if (id != 0x60)

  {

    Serial.println("Problem with BME280");

  }

else {

    Serial.println("BME280 online");

  }

}    

Code snippet 1: Initialization routine for BME280 sensor prior to taking readings. (Code source: SparkFun)

To take readings from the sensors, a void loop must be added to the code (the Arduino “sketch”) (Code snippet 2).

Copy

void loop() {

if (myCCS811.dataAvailable()) //Check to see if CCS811 has n ew data (it's the slowest sensor)

  {

    myCCS811.readAlgorithmResults(); //Read latest from CCS81

1 and update tVOC and CO2 variables

    //getWeather(); //Get latest humidity/pressure/temp data f

rom BME280

    printData(); //Pretty print all the data

}

  else if (myCCS811.checkForStatusError()) //Check to see if C

CS811 has thrown an error

  {

    Serial.println(myCCS811.getErrorRegister()); //Prints what

ever CSS811 error flags are detected

  }

  delay(2000); //Wait for next reading

}

Code snippet 2: Routine for taking and printing out readings from CCS811 sensor. (Code source: SparkFun)

The environmental data (“ENV_DATA”) from the BME280 is written to CCS811 so that a compensation factor can be applied to the baseline resistance to factor in the effect of temperature and humidity.

Humidity and temperature information are communicated as an unsigned 16-bit integer with a resolution of 1/512% RH and 1/512 degrees. The default value for humidity is 50 percent (= 0x64, 0x00). For example, 48.5 percent humidity = 0x61, 0x00. The temperature reading includes an offset with 0 mapping to -25°C. The default value is 25°C (= 0x64, 0x00). For example, 23.5°C = 0x61, 0x00.

Feeding the temperature and humidity from the BME280 to the CCS811 allows the microprocessor to apply the compensation algorithm (Code snippet 3).

Copy

void loop() {

  //Check to see if data is available

  if (myCCS811.dataAvailable())

  {

    //Calling this function updates the global tVOC and eCO2 v

ariables

    myCCS811.readAlgorithmResults();

    //printData fetches the values of tVOC and eCO2

    printData();

    float BMEtempC = myBME280.readTempC();

    float BMEhumid = myBME280.readFloatHumidity();

    Serial.print("Applying new values (deg C, %): ");

    Serial.print(BMEtempC);

    Serial.print(",");

    Serial.println(BMEhumid);

    Serial.println();

    //This sends the temperature data to the CCS811

    myCCS811.setEnvironmentalData(BMEhumid, BMEtempC);

  }

  else if (myCCS811.checkForStatusError())

  {

    Serial.println(myCCS811.getErrorRegister()); //Prints what

ever CSS811 error flags are detected

}

  delay(2000); //Wait for next reading

}

Code snippet 3: Feeding temperature and humidity data to enable the CCS811 sensor to perform a compensation algorithm. (Code source: SparkFun)

Adding an air quality sensor to the IoT

While SparkFun’s SEN-14348 breakout, Arduino computer, and shield allow control and collation of air quality data, the system offers no wireless connectivity. Cypress Semiconductor’s CY8CKIT-042-BLE-A PSoC 4 BLE Pioneer Kit includes wireless capability to resolve this requirement.

The PSoC 4 BLE Pioneer Kit is a development tool designed to help engineers develop wireless sensor applications. The kit allows an engineer to code and compile applications and then port the firmware to Cypress’ PSoC 4 Bluetooth low energy SoC. The SoC incorporates a 32-bit, 48 MHz Arm® Cortex®-M0 processor and Bluetooth low energy radio.

In this case the breakout’s compensated air quality data is fed via the breakout’s I2C connection to an I2C connector on the kit’s pc board. In addition to receiving data from the I2C interface’s SDA line, the processor is capable of resetting, interrupting, and putting the sensors to sleep.

Some development work is required to program and debug an air quality sensor design when using the kit. Cypress offers the Windows CySmart Host Emulation Tool (running on a PC) and a Bluetooth low energy dongle for coding and testing. Both the dongle and the Pioneer Kit can simultaneously be connected to a common host PC during the development process (Figure 5).

Image of Cypress Bluetooth Low Energy development tools (click to enlarge)

Figure 5: Cypress supplies Bluetooth Low Energy development tools and a dongle (configured as a Bluetooth Low Energy Central device) to aid application firmware development with the PSoC 4 BLE Pioneer Kit. (Image source: Cypress Semiconductor)

Development with the CY8CKIT-042-BLE-A PSoC 4 BLE Pioneer Kit design process comprises four stages:

  • Create the design in the PSoC Creator schematic page
  • Write the firmware to initialize and handle Bluetooth Low Energy events
  • Program the Bluetooth Low Energy SoC using the Pioneer Kit
  • Test the design using the CySmart Host Emulation Tool (or mobile app)

(For more information on Bluetooth low energy application development, see the Digi-Key article, “Bluetooth 4.1, 4.2 and 5 Compatible Bluetooth Low Energy SoCs and Tools Meet IoT Challenges”.)

The application firmware enables the Bluetooth low energy SoC to collate and process the sensors’ data and transmit the information across a Bluetooth low energy link to, for example, a smartphone for analysis and display.

Data from the sensor could then be forwarded from the smartphone to a cloud server to save data and perhaps trigger “If This Then That” (IFTTT) notifications based on the data. For example, a persistently high CO2 reading in a child’s bedroom could trigger a notification on a parent’s smartphone advising an increase in ventilation.

Connecting to the cloud directly from the sensor is a little more complex. Bluetooth low energy SoCs such as the Cypress component generally lack a native IPv6 network layer. The solution is to send the Bluetooth data to a “gateway” employing an alternative protocol to connect to the cloud (for example, Wi-Fi).

Cypress and SparkFun have again teamed up to make this possible. By using a CY8CKIT-062-BLE PSoC 6 BLE Pioneer Kit from Cypress and a DEV-14531 PSoC Pioneer IoT add-on shield from SparkFun (equipped with an XB2B-WFWT-001 XBee Wi-Fi module), an engineer can develop a network that takes the compensated air quality data from the sensor, transmits it across a Bluetooth low energy link from the CY8CKIT-042-BLE-A PSoC 4 BLE Pioneer Kit to the CY8CKIT-062-BLE PSoC 6 BLE Pioneer Kit, and from there (via Wi-Fi) to the cloud (Figure 6). (See the Digi-Key technical article, “802.11x Modules, Dev Kits Can Help Simplify IoT Wireless Design Efforts” for more information on using Wi-Fi modules to connect to the Cloud.)

Diagram of wireless system built from Cypress and SparkFun development kits

Figure 6: This wireless system built from Cypress and SparkFun development kits uses Bluetooth low energy and Wi-Fi to send air quality sensor data to the cloud. (Image source: Digi-Key Electronics)

Conclusion

Including air quality sensors as part of a smart building network is becoming important due to the growing awareness of the detrimental health effects of the buildup of VOCs and gases such as CO2 in controlled ventilation buildings.

Commercial air quality sensors currently lack the powerful integrated microprocessor and wireless connectivity typical of other (modular) sensors. However, by turning to easy-to-use design tools, an engineer can not only compensate raw air quality data for temperature and humidity effects, but also wirelessly transmit the information across a Bluetooth low energy network, and via a smartphone network or Wi-Fi module to the cloud.

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this publisher

Digi-Key's North American Editors