014 - MakeCode MicroBit: Brickcell CO2 SGP30
Table of Contents
SGP30 Digital Gas Sensor
The SGP30 is a digital gas sensor from Sensirion designed to detect various gases in the ambient environment. It is commonly used to measure the concentration of Total Volatile Organic Compounds (TVOC) and equivalent carbon dioxide (eCO₂) 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 such as vehicle emissions, industrial processes, and off-gassing from household products and materials. High TVOC levels may indicate poor air quality or the presence of potentially harmful substances.
eCO₂ (Equivalent Carbon Dioxide)
eCO₂ is an estimate of the equivalent carbon dioxide concentration in the air and serves as a proxy for assessing indoor air quality. The value is calculated based on the sensor’s response to various VOCs, providing an indication of how well-ventilated an indoor space is. High eCO₂ levels may suggest inadequate ventilation, leading to discomfort and decreased air quality.
The SGP30 sensor uses metal-oxide semiconductor technology to detect gases and provides a digital output readable by microcontrollers and other digital systems. It is often used in indoor air quality monitoring systems, air purifiers, and HVAC control systems.
Hardware Instruction
Let's explore how to connect the Carbon Dioxide Sensor SGP30 module to a micro:bit microcontroller and utilize MakeCode for programming.
- Connect the SGP30 Sensor GND pin to micro:bit GND pin.
- Connect the SGP30 Sensor VCC pin to micro:bit 5V pin.
- Connect the SGP30 Sensor serial transmit pin (Tx) to micro:bit pin 0.
- Connect the SGP30 Sensor serial receive pin (Rx) to micro:bit pin 1.
Software Instruction
Now, let's start programming the micro:bit to utilize the SGP30 Sensor module.
- Login to https://makecode.microbit.org/ using your Microsoft account.
- Create a new project by clicking the "New Project" button. You may name it descriptively, such as co2-sgp30-test.
- Click the "Extensions" block under the "Math" block.
- Type https://github.com/gbantique/brickcell-co2-sgp30/ in the search bar.
- Select the brickcell-co2-sgp30 from the search results. The "co2 sgp30" block should now appear under the Brickcell category.
- Copy the code provided below:
serial.setBaudRate(BaudRate.BaudRate115200);
Brickcell.iaqInit();
basic.forever(function () {
serial.writeString("tvoc: " + Brickcell.tvoc());
serial.writeLine(" | co2eq: " + Brickcell.co2eq());
basic.pause(2000);
});
- Open a Serial Monitor such as Termite Terminal App. Set the baud rate to 115200 bps.
Or you can make a copy of my created project in your MakeCode workspace:
https://makecode.microbit.org/S21679-46211-50587-76754/
Expected Result
If you carefully follow the provided instructions above, you should be able to view the measured Total Volatile Organic Compounds (TVOC) in ppb units and the Equivalent Carbon Dioxide (eCO₂) in ppm units in the serial terminal. The baud rate should be set to 115200 bps.