014 - Brickcell CO2 SGP30 | MakeCode Microbit


The SGP30 is a digital gas sensor from Sensirion that is designed to detect various gases in the ambient environment. It's commonly used to measure the concentration of Total Volatile Organic Compounds (TVOC) and equivalent carbon dioxide (eCO2) in the air.

TVOC (Total Volatile Organic Compounds): TVOC is a measure of the total concentration of volatile organic compounds present in the air. These compounds can include a wide range of organic chemicals and can come from various sources, including emissions from vehicles, industrial processes, and off-gassing from products and materials. High TVOC levels can indicate poor air quality or the presence of potentially harmful substances.

eCO2 (equivalent carbon dioxide): eCO2 is an estimate of the equivalent carbon dioxide concentration in the air. It's used as a proxy for assessing indoor air quality. The eCO2 value is calculated based on the sensor's response to various VOCs, and it provides an indication of how well-ventilated an indoor space is. High eCO2 levels may suggest inadequate ventilation, which can lead to discomfort and decreased indoor air quality.

The SGP30 sensor uses a metal-oxide semiconductor technology to detect these gases and provide a digital output that can be read by microcontrollers and other digital devices. It's often used in applications such as indoor air quality monitoring, air purifiers, and HVAC systems to assess and control air quality.

Hardware Instruction

Let's explore how to connect the Carbon Dioxide Sensor SGP30 module to a micro:bit microcontroller and utilize MakeCode for programming.

  1. Connect the SGP30 Sensor GND pin to microbit GND pin.
  2. Connect the SGP30 Sensor VCC pin to microbit 5V pin.
  3. Connect the SGP30 Sensor serial transmit pin (Tx) to microbit pin 0.
  4. Connect the SGP30 Sensor serial receive pin (Rx) to microbit pin 1.

Software Instruction

Now, let's start into programming the micro:bit to utilize the SGP30 sensor module.

  1. Login to https://makecode.microbit.org/ using your Microsoft account.
  2. Create a new project by clicking the "New Project" button. You may name it anything you want, I suggest to name it with descriptive name such as "co2-sgp30-test".
  3. Click the "Extensions" block just under the "Math" block.
  4. Type https://github.com/gbantique/brickcell-co2-sgp30/ on the search bar.
  5. Select the "brickcell-co2-sgp30" from the search results. The "co2 sgp30" block should appear under the "Brickcell" block.
  6. Copy the code provided below.
3basic.forever(function () {
4  serial.writeString("tvoc: " + Brickcell.tvoc());
5  serial.writeLine(" | co2eq: " + Brickcell.co2eq());
6  basic.pause(2000);
  1. Open a Serial Monitor such as Termite terminal app https://www.compuphase.com/software_termite.htm/. Set the baud rate to 115200 bps.

Or you make a copy of my created project in your MakeCode workspace.


Expected Result

If you carefully follow the provided instruction above, you should be able to view the measured Total Volatile Organic Compounds (TVOC) in ppb unit and the Equivalent Carbon Dioxide in ppm unit in the serial terminal. Baud rate should be set to 115200 bps.

Posts in this series

No comments yet!

GitHub-flavored Markdown & a sane subset of HTML is supported.