VOC sensing#

In this lesson you’ll collect readings on air quality as measured by the concentration of volatile organic compounds, or VOCs, in the air around your computer (and around you, if you’re sitting near your computer). You can learn more about VOCs on this page, and about the VOC Index, which the sensor we’ll be using in this experiment provides, in this document.

Parts list#

For this exercise you’ll need:

Wire pHAT and sensor#

Your set-up might look slightly different than this. This image shows the BME280 atomospheric sensor and the SGP40 sensors attached to the pHAT.

Wired sensor

Python 3 code#

To use the following code, open a command terminal. Then enter the following command:

source ~/code/4cscc-ln/venv/bin/activate

Then, enter the following command to start an ipython terminal:

ipython

Finally, copy paste the following code into the ipython terminal. This will collect from your SGP40 sensor every 2 seconds and display them on the screen. It will run until you press “Control-c” (i.e., press the “control” and “c” keys at the same time).

from time import sleep
import qwiic_sgp40

voc_sensor = qwiic_sgp40.QwiicSGP40()

if voc_sensor.begin() != 0:
    print('SGP 40 VOC sensor doesn\'t seem to be connected to the system.')
    exit(-1)

while True:
    voc_index = voc_sensor.get_VOC_index()
    print('VOC Index: %d' % voc_index)
    sleep(2) # pause for 2 seconds before collecting the next reading