Monitoring indoor air quality can help you improve the environment in which you live and work in. The OKdo Air Quality Kit for Raspberry Pi is an easy to use kit for measuring air quality of the indoor environment. The data collected is connected to the AllThingsTalk Cloud, allowing you to view it via the internet.
The Air Quality Kit comes complete with a Grove Base HAT for Raspberry Pi, Grove Temperature & Humidity Sensor Pro (Asong AM2302 ) and Grove VOC & eCO2 Gas Sensor (Sensirion SGP30), plus all connectors. The parts are also available separately along with Python sample code.
At the end of this project, you will have a fully functioning smart indoor air quality monitoring system that’s connected to the Cloud.
The following dependencies should already be installed:
sudo apt install git python-pip python3-pip
This command needs to be run as a single line – the dashes and spaces are significant – it also takes a couple of minutes to run
curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -
You should get a message informing you that the installation was successful. Do not proceed until this message is displayed.
cd ~
git clone https://github.com/Seeed-Studio/Seeed_Python_DHT.git
cd Seeed_Python_DHT
sudo pip3 install .
cd ~
git clone https://github.com/Seeed-Studio/Seeed_Python_SGP30.git
cd Seeed_Python_SGP30
sudo pip3 install .
cd ~
git clone git://github.com/allthingstalk/python-sdk.git
cd python-sdk
sudo pip3 install .
This creates a pre-configured template for the Air Quality Kit consisting of the 4 different sensors which are known as Assets.
The Grove Python libraries and AllThingsTalk SDK have already been installed on the Pi 4. These are used to create the client that will take readings from the sensors and update the cloud.
import time
import seeed_sgp30
import seeed_dht
from grove.i2c import Bus
import allthingstalk as talk
DEVICE_TOKEN = 'maker:4Pbcra08QeXWW1VeVmCHLnzEet61IpzbsWEAFkT'
DEVICE_ID = 'we6B8WbVKeYWXQWNLzaQFQyQ'
# New OKdo client wrapper class
class AirQualityMonitor(talk.Device):
temperature = talk.NumberAsset()
humidity = talk.NumberAsset()
eco2 = talk.NumberAsset()
tvoc = talk.NumberAsset()
# Create sensors
temp_humid_sensor = seeed_dht.DHT("22", 26) # DHT22 type, digital port D26
gas_sensor = seeed_sgp30.grove_sgp30(Bus()) # I2C bus 1 default
# Create OKdo client
client = talk.Client(DEVICE_TOKEN)
monitor = AirQualityMonitor(client=client, id=DEVICE_ID)
while True:
# Read sensors
humid_pc, temp_c = temp_humid_sensor.read()
eco2_ppm, tvoc_ppb = gas_sensor.read_measurements().data
# Update cloud
monitor.temperature = temp_c
monitor.humidity = humid_pc
monitor.eco2 = eco2_ppm
monitor.tvoc = tvoc_ppb
print('temp: {0:.1f} C humidity: {1:.0f} %'.format(temp_c, humid_pc))
print('eco2: {} ppm tvoc: {} ppb'.format(eco2_ppm, tvoc_ppb))
time.sleep(5)
Go back to the browser and click Settings on the Asset page for your kit and choose Authentication to view the Tokens for that device.
VOC and eCO2 sensors take a few minutes to start sampling accurately.
After a few seconds, the Asset fields in your console should update every 5 seconds with your sensor readings.
You now have your Air Quality Kit for Pi 4 setup and connected to the AllThingsTalk cloud, with sensor updates occurring every few seconds, so you can monitor your indoor environment.
The Grove sensors in the kit are an example of the many kinds of sensors in the Grove range, making it quick and easy to build all sorts of sensor-based projects. Most of them have Open Source Python libraries ideal for use with the Pi 4.
In the AllThingsTalk Maker Cloud console, alerts can be set up to trigger rules when sensors reach threshold values using web, email or push notifications. You can also view the data represented as a custom dashboard or as live graphs.
Now your air quality sensors are connected to the Cloud and are accessible from almost anywhere.
From a quick tap to smashing that love button and show how much you enjoyed this project.