This is my first IoT project, and in this tutorial, I will show you how to build an IoT IAQ-sensor. This sensor was made during the course "Introduction to Applied Internet of things" at Linnéuniversitetet.
After this tutorial, you'll be able to gather and see visualizations of data that affects indoor air quality like Temperature, Relative humidity (RH), CO2 levels and tVOC levels (Total Volatile Organic Compounds)
I chose to build this project mainly because I wanted to learn the basics of IoT sensors and platforms. But at the same time, I wanted to monitor the indoor air quality in our apartment as me and my partner both work and study at home right now during the covid19 pandemic. My plan is to give us more insight into healthy levels of CO2, temperature, and relative humidity. And then to use this data to manage air quality issues if we receive bad values.
Hardware | Price (in EUR)* | Link |
---|---|---|
Lopy4 (with headers) | €34.95 | Pycom |
Expansion board 3.0 | €16.00 | Pycom |
CCS811 Air Quality Sensor | €20.99 | Conrad** |
DHT11 Humidity & Temperature Sensor | €5.24 | Electrokit |
Wirings & Extra | Price (in EUR)* | Link |
---|---|---|
10 x Jumper wires | €3.10 | Electrokit |
Micro USB cable | €2.03 | Electrokit |
Breadboard*** | €6.31 | Electrokit |
Software | Link |
---|---|
Visual Studio Code (or Atom) | VS Code (or Atom) |
Node.js | Node.js |
Pymakr plugin for your IDE | Pymakr |
In this tutorial, I used the LoPy4 device (Fig. 1) which is a device from Pycom. Their devices use the lightweight and fast scripting language MicroPython, got plenty of analog and digital in- and outputs and works with LoRa, Sigfox, WiFi, and Bluetooth connectivity.
The Expansion board is needed for connecting the device to your computer.
The breadboard is not mandatory but will make connections easier. We use this tool to connect the jumper wires to the modules and our pycom device.
(Fig. 1. LoPy4 with headers.)
(Fig. 2. Expansion board 3.0.)
*As for time writing (2020-06-30). (VAT included)
**I'm using CCS811v1 from Joy-It, but other CCS811's will do as well!
My preferred IDE is Visual Studio Code, so that's what I'll be using throughout this tutorial. (You can use any other IDE of your liking. Atom for an example.)
If you haven't installed VS Code already, download it here.
Once you got VS Code running, install Node.js.
Now, get the Pymakr extension for VS Code. We'll use this extension to connect, run, upload, and download scripts to our device. Either download it via your browser here or follow these instructions:
You can do this either by pressing the icon in the left navbar:
Or by using the shortcut on Mac (⇧⌘X)
Pymakr
and click on the green button to install the extension.
This should only take a couple of minutes. And you might be prompted to reload VS Code when done.
Don't worry about these errors just yet. We get these messages as we haven't connected to our LoPy4 device yet.
We will use this terminal to run, download and upload our code to the device.
Go get your Expansion board. It should look something like this:
Now, pull out your LoPy4 device. It should look like this:
Now put the LoPy4 module on top of the Expansion Board with the reset button pointing towards the USB connector. It should firmly click into place and the pins should now no longer be visible.
When you're done, it should look like this:
Head to Pycom's Pybytes platform and register an account here.
Once you're registered. Head to the Pybytes platform here.
You'll we presented 4 choices:
When your project is created. Click on it to continue.
Now we get to choose between all these Pycom devices:
Save this activation code! (blurred in this photo) We need it for the next step in this tutorial.
It is highly recommended that you upgrade your device firmware to the latest version as Pycom constantly is making improvements and adding new features. Please follow the instructions carefully.
Locate your device in the "Port"-dropdown menu.
Check "Force update Pybytes registration" before you press Continue!
The tool will now load and then you'll receive this prompt:
Remember the activation token we got before? Paste it here!
You'll get to this 'Advanced Settings' section now:
Don't worry about the rest of the settings for now. Click Continue.
Your device will now upgrade, and it might take up to one minute.
When it's finished. Click Done.
Before we get into the connection phase:
This IoT IAQ system is aimed for personal use and our goal is to learn how to setup an IoT device. Therefore, this circuit diagram is used for a development setup. Let's continue!
The breadboard is used to easily connect our sensors and pycom device with wires altogether. I preferably use red wires to 3V3, and black wires to GND.
Take a red wire and put one end in the "3V3" pin on your pycom device.
Put the other end in the first pin of the + row on your breadboard.
Take a black wire and put one end in the "GND" pin on your pycom device.
Put the other end in the first pin of the - row on your breadboard.
I will use these little tables in the next steps to show how to wire:
Pycom pins | Breadboard |
---|---|
GND | - row |
3V3 | + row |
When you're done it should look like this picture:
The CCS811 is used for measuring CO2 levels and tVOC.
Important! My CCS811 sensor may differ from yours. Please have a look at your sensor's datasheet before you continue.
Take 5 of your jump wire cables (remember black wire for GND and red for 3v3) and wire them like this:
Pycom device | CCS811 |
---|---|
3V3 (breadboard + row) | 3v3 / Vcc |
GND (breadboard - row) | GND |
P10 | SCA |
P9 | SDL |
GND (breadboard - row) | WAKE |
When you're finished it should look something like this:
Now connect the DHT11 sensor. We will use this sensor to measure both temperature and relative humidity.
Important! Same thing here as with the CCS811 sensor, please look up the datasheet of your device before you move any further.
Take 3 jump wires this time and wire them by this scheme:
Pycom | DHT11 |
---|---|
P23 | S |
GND (Breadboard - row) | - |
3V3 (breadboard + row) | + |
Now everything should be connected. It should look something like this:
Before you plug in your USB, please look carefully if all the wires are connected correctly.
I've chosen Pycom's Pybytes platform to manage our device, store, and visualize my data. It's easy to set up and it is also cloud-based so you don't have to run any servers or databases on your local machine.
With the Pybytes platform, we're also able to create a dashboard with different types of charts to visualize our data. The dashboard isn't public, but it doesn't matter in this case as our project is only for personal use.
It's easy to add more pycom devices to Pybytes if you want to expand this project in the future. You're also able to integrate with other platforms as Google, Amazon, and Microsofts IoT platforms or create Webhooks if you want to.
I've used two libraries for the sensors.
Then I've created two python files for reading our values.
This one for DHT11. I have named it dht_read.py
.
And this one for CCS811. I've named it ccs_read.py
.
And in our main.py
file, we use both of these files to read and then send the values to Pybytes.
My file structure looks like this before we upload it to our Pycom device:
To upload our code to our device:
Our data is now transferred using the MQTT protocol over WiFi.
This was already set up for us when we activated our device earlier in this tutorial with our pycom firmware tool.
As seen in our code example recently (line 23 in main.py
) our data is sent once every minute to the pybytes platform.
Now that we're sending data to Pybytes, we're able to visualize it!
You can click on them to give the signal a name, and a unit.
In our code earlier, we sent specific data on specific signals. You can name these after this scheme:
Signal | Name | Unit |
---|---|---|
Signal 1 | Temperature | C |
Signal 2 | Relative humidity | % |
Signal 4 | CO2 | ppm |
Signal 5 | tVOC | ppb |
Now as we've defined our signals, let's add some charts to display our data!
Click on a signal to see data.
You'll now see a dull table by default. Click on "CREATE NEW DISPLAY".
Choose a display of your like. I'll use a bar chart in this example.
You'll now be able to customize your chart by giving it a name, set the pull size and time scale, etc.
Click on Create when you're done.
Navigate to one of your charts, and click on edit.
Now tick the box that says "Display on Dashboard".
Repeat those steps with all your signals, and then go to your dashboard.
Now you'll be able to see all your charts on your dashboard!
Click on the organize button to customize the look to your likes.
Data is saved on pybytes every time we send a signal. This will then be saved for one month. You can set up an integration with other services if you send your data elsewhere, or if you want to persist your data. I won't cover integrations in this tutorial. But you can read about it here.
Our Indoor Air Quality Monitor System is now done!
My goal was to learn the basics of IoT sensors and platforms, but at the same time, monitor the indoor air quality in our apartment. This project isn't advanced at all however, I've learned alot. And I think that this is a good base to continue develop from. Maybe integrate with other services like Amazon AWS, or Google IoT. Maybe build a case for my device, or just to expand this device with more sensors.
I feel like this is a really simble but fun and beginner friendly way to get the hang of the very IoT basics. I think this project went great as I reached my goal, and that by the fact that I'm able to continue building this project. I could've made it more challenging by not using the pybytes platform or by using another protocol than WiFi (especially Sigfox or LoRa). I feel that I've got a hang of the basics for now, so I will absolutely continue to build more advanced projects in the future and maybe post some more tutorials!
Here we see my caseless device in action!
Thanks for reading!