Difficulty: 3/5, Time Needed: ~60 min
Got the new Air Quality Kit for Raspberry Pi? Let’s get started!
Make an air quality monitoring device with your Raspberry Pi and two sensors which will measure eCO2 (Carbon dioxide equivalent), VOC (Total Volatile Organic Compounds), Temperature and Humidity. All of this data will be sent to OKdo Cloud and you’ll be able to check it (current and historical) using your web browser or your smartphone. Let’s go:
You’ll need to create the device on OKdo Cloud so you can use your Raspberry Pi to send data from its sensors to it.
You’ll have a default “Playground” ground if you’ve just created your account
Assets TVOC, eCO2, Temperature and Humidity are already present and your Raspberry Pi will send sensor data to them.
Make sure to use the included spacers and screws - it’ll be more stable
You can use any digital port, but be sure to change the pin in the code later
Flashing the OS
In this step, you’ll flash the operating system for your Raspberry Pi so you can start working in it.
- This is the “Lite” version of the OS, which means it doesn’t have a graphical user interface - it only has command line, which is good since you’re going to run the Raspberry Pi headless (without monitor/keyboard/mouse)
If you already have a system installed, please make sure it’s at least Raspbian Buster because older Raspbians (e.g. Stretch) will need additional steps of upgrading python and a few other things.
You’ll see a lot of command line output on your monitor. Once you see “raspberry pi login:”, you can continue with the steps below
Initial System Configuration
Now you’ll configure the Raspberry Pi so that you have a functional system ready to be used without a monitor or a keyboard.
pi(default user) and then enter
raspberry(default password). You’re now logged in to your Raspberry Pi
sudo raspi-configto enter the Raspberry Pi software configuration tool
This is important - leaving the default password on an SSH-enabled system is a security risk
pias user and your new password
ifconfigand make note of your IP Address (should be under network interface “wlan0” as “inet X.X.X.X”)
In case you’re using a Linux or macOS machine, open terminal and execute
ssh pi@your_ip_addressand you’ll be prompted to enter the user and password
This is the part where you’ll actually read and send data from your sensors!
sudo apt-get install python-pip python3-pip
Installs “pip”, which is a Python package installer. Enter “y” when asked to confirm installation.
curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -
Installs “grove.py”, a dependency for sensor libraries
sudo pip3 install allthingstalk seeed-python-dht seeed-python-sgp30
Installs the library for communicating with OKdo, Temperature & Humidity Sensor and the VOC and eCO2 (SGP30) Sensor
sudo nano /usr/bin/okdo_airquality.py
DEVICE_IDvariable to contain your device ID
To get your Device ID, on OKdo Cloud, go to your Device > Settings > Authentication > Device ID
DEVICE_TOKENvariable to contain your device token
To get your Device ID, on OKdo Cloud, go to your Device > Settings > Authentication > Device Tokens
DHT_PINvariable to your pin number.
The sensor data is printed out in your terminal and sent to your OKdo Cloud every 30 seconds.
Now you’ll make the system take care of the script, so it makes sure it:
You’ll do that by adding the script as a service in the “systemd” directory:
sudo nano /etc/systemd/system/okdo_airquality.service
Press CTRL+X, Confirm with “y” and confirm the name.
sudo chmod +x /usr/bin/okdo_airquality.py- Adds permissions
sudo systemctl daemon-reload- Reloads services
sudo systemctl start okdo_airquality- Starts our script
sudo systemctl enable okdo_airquality- Enables our script to start at boot
sudo systemctl status okdo_airquality- Check the status.
Active: active (running)
sudo systemctl stop okdo_airqualityif you want to stop the service, or
sudo systemctl disable okdo_airqualityif you wish to stop it from being executed at boot.
You now have a fully functional air quality measuring device!
Let’s do the final stuff to make it look nice.
Make the data more presentable by creating a Pinboard to show it all:
You can also rearrange and change control’s size, so you can get something like this:
Help others be aware of air quality in your area by sharing your data with the OKdo Air Quality Community:
Click “+ New Asset” and fill it out as shown:
Set your Location by clicking the location asset, and click
Use my location, or choose your location on a map (does not have to be precise if you’re not comfortable with it).
Enjoy your new Air Quality device!