CO2 Sensor
Deutsch   English 

7. CO2 Sensor

New TigerJython ( Version 2.22 [Sep-18-2021] and later) required.

With the CO2 sensor you can measure and monitor the CO2 concentration in the room. The CO2 level is a reliable indicator of air quality. Fresh indoor air is particularly important today to reduce the risk of infection with Covid-19.

SGP30 Air Quality Sensor


The SPG30 CO2 sensor from Sensirion provides highly precise measured values of the CO2 concentration in the air. The gas sensor TVOC/eCO2 SGP30 can be ordered at www.brack.ch or at www.mouser.ch . The connection cable is integrated in the delivery.

 



 

With little effort you can set up a simple measuring station for measuring the CO2 concentration for example in your classroom.

The module sgp, which supports the communication with this sensor, is integrated in TigerJython (from version 2.22) and is automatically copied to the micro:bit during flashing. You can also download it under Help/APLU Documentation and install it with Tools/Download module.

 


The sensor is connected to the mico:bit with the supplied I2C cable via an I2C hub. An I2C hub that can be screwed to the micro:bit is included in the IoT set.

 

Example 1: Measure and display CO2 concentration

In program import sgp is used to import the module sgp, in which SGP30 sensor and querying the measured values of SGP30 sensor is implemented. The command sgp.getValues() returns a tuple with two values: CO2 Concentration in ppm* TVOC Total Volantile Organic Componds*.

The two values are written out in the terminal window with print command. delay(500) specifies the measurement period.

 



from microbit import *
import sgp

while True:
    co2, voc = sgp.getValues()
    print ("CO2 = ", co2, "  TVOC = ", voc)   
    sleep(500)
► Copy to clipboard

After the program start, the sensor is first calibrated and returns the CO2 value 400 for the first 20 seconds. Then the measured CO2 values are displayed correctly.

* The CO2 content in the air is given in parts per million, ppm for short. SGP30 sensor returns the values in the range 400 - 60000 ppm, where for the values greater than 1000, the air is no longer called fresh.

* Indoors there are many jellyfish that emit pollutants (lamps, floor coverings, cleaning products...). The sensor returns TVOC values in the range 0 to 60 000.

 

Example 2: A measuring device for CO2 concentration in the classroom

The following limit values apply to the measurement of the CO2 concentration:

  • < 1000 ppm: Air is fresh
  • 1000 - 1400 ppm: Air soon
  • > 1400 ppm: Open window

With the LEDs on the micro:bit you can display different symbols for these measuring ranges. The program remains stored on the micro:bit. So you can unplug it from the computer and connect it to another power source, for example powerbank.

 

from microbit import *
import sgp

while True:
    co2, voc = sgp.getValues()
    print ("Co2 = ", co2) 
    if co2 < 1000:
        display.show(Image.YES)
    elif co2 < 1400:
        display.show(Image.ARROW_S) 
    else:
        display.show(Image.NO)      
    sleep(500)
► Copy to clipboard

The sensor measures the CO2 content in ppm (parts per million) and provides readings in the range 400-60 000. For values < 1000, the air is good; for values > 1400, a supply of fresh air is strongly recommended. A high CO2 concentration in the room increases the risk of infection with the corona virus.

 

Exercises:

1)


Measure the CO2 values with the measuring period of 2 seconds and write the results with ticker on the micro:bit display

2) Build a CO2 measuring system that plays an acoustic signal at a CO2 value > 1400. Micro:bit V2 has a loudspeaker, with micro:bit V1 you have to connect a loudspeaker as described in the chapter "Sound". For testing you can lower the threshold value 1400 ppm.  

 

ADDITIONAL EXERCISE: SELF-SOLDERING CO2 SENSOR

If you enjoy electronics, you can use a CO2 sensor where all electronic components are visible. The GY-SPG30 Air Quality Sensor is compatible with the SPG30 sensor used above and can be programmed with the same sgp module. It can be ordered from different suppliers.  



 


The sensor is soldered to an I2C cable.
You take a Grove cable with an I2C connector, strip the much thin wires and solder the black wire at GND, the red at VCC, the yellow at SCL and the white at SDA.
 
red
black
yellow
white
 


The sensor is connected to the mico:bit via an I2C hub.