The PiicoDev Air Quality Sensor is a multi-gas sensor that detects volatile organic compounds, things like ethanol, oxidizing gases, and even bi-products of human respiration and metabolism. The sensor is capable of sampling these gases and producing outputs for total volatile organic compounds, equivalent CO2, and air quality index. These metrics are commonly used to monitor indoor air quality and control ventilation systems. I'm going to show you how to get started reading your PiicoDev Air Quality Sensor with a Raspberry Pi Pico. We'll connect these two together and begin sampling air quality metrics, but first a bit about the sensor. The PiicoDev Air Quality Sensor features two PiicoDev connectors for daisy-chaining connections with other PiicoDev hardware. There's an address switch labelled ASW, which is used for uniquely addressing a second air quality sensor. Leave the switch in the off position for now. Across the bottom, there's also a breakout header for more experienced makers.
To follow along, you'll of course need a Raspberry Pi Pico with the pin soldered facing down. That's to plug into a PiicoDev Expansion Board for Raspberry Pi Pico. You'll need a PiicoDev Air Quality Sensor and a PiicoDev Cable to connect everything together. Plug the Pico into the Expansion Board and make sure that the USB connector is on the same side as the zero pin. Plug in your PiicoDev Cable to one end and connect the other end to your sensor. Make sure this address switch has stayed off and connect to your computer with USB.
In the article for this tutorial, find the download section and select the dev board you're using, Raspberry Pi Pico. Right click PiicoDev Unified and save link as, and I'll save this to a PiicoDev directory in my documents. Do the same with PiicoDev EnS160, that's the device driver. Save link as to PiicoDev. We'll program the Pico with MicroPython. Using Thonny if you haven't used Thonny before with a Pico check the article for more help. Navigate to where you've saved those files, connect to your Raspberry Pi Pico, select both files and upload to. When you see those two files uploaded to your Raspberry Pi, you're ready to proceed. Scroll down to the example reading air quality metrics, highlight all of that code and copy with Ctrl C and paste it into this new script. We're ready to run, click the Green Run button and save the file to your Raspberry Pi Pico as main.py to run it automatically.
If all goes well, you ought to see some air quality metrics being printed to the shell. Here we have a few rows of information, we have AQI as one which is excellent, we have TVOC at 38 parts per billion, eCO2 at about 400 parts per million, excellent and the status is initial start up.
Let's have a look at each of these in turn. Air Quality Index or AQI breaks down air quality into a range between one and five, where one is excellent and five unhealthy. There's also a few recommendations that go along with it. This is derived from a German standard but it's used a fair bit internationally and you can see that there are a few recommendations for ventilation and some recommended exposure limits. Equivalent CO2 is another measure that gets used by industry, particularly in the HVAC or ventilation industry and this is broken down into several ranges along with ventilation requirements. TVOC or Total Volatile Organic Compounds is just the measure that the sensor is performing. It is the sum of all its measurements.
There's also something here called status. Am I currently in the initial start up ? The PiicoDev air quality sensor has three states: initial start up , warm-up and operating. Okay, when the sensor first powers on it will be in this initial start up state which lasts up to an you can still. Use your sensor right away in this state, but the accuracy will be improved once the sensor has warmed up. If the sensor is allowed to run continuously for at least 24 hours, it will never need this long initial start up process again. Instead, it will perform a much faster warm-up which only lasts a few minutes.
Let's take a closer look at the example. We start by importing the device driver and a function to create a delay. We call the initialization function and that returns an air quality sensor object that we assign to sensor. So anytime that we see the word sensor in this script, we are referring to our physical air quality sensor.
Then, inside the infinite loop, we query the sensor for the aqi, t-voc, and the eco2 properties and we store those results in some variables. As we've seen, these properties actually contain more than just a number. Sometimes, for example, the aqi property that we're printing here has a numerical property but also a description. So when it comes time to printing these values, we can print aqi.value or aqi.rating. T-voc returns just a value, so we can print that numeric value in the shell. But when we come to eco2 again, we have some value component as well as some rating component and this is quite convenient because we don't need to do anything to actually extract what the description for that rating is. We can just read it straight from this answer.
If we just want to work with the value, say to create some kind of threshold, then we can just extract the property that we need. I'll show you how that works. Let's take the aqi and print a message if the aqi goes above two. We can remove all of this code. Actually, I'll leave the print aqi in and if aqi.value is greater than 2, print turn on the fan. Now when I rerun the script, we have an aqi of one or two, but if I hold the sensor above this bottle of disinfectant...
We immediately went to an unhealthy fume and had an AQI of five. We turned on the fan and as a side note, if you're unsure whether you should be messing around with bottles of chemicals, it's probably a bad idea. It's possible to read from multiple devices; you can read up to two air quality sensors on the same PiicoDev bus. The only requirement is that they have a different address switch setting. The sensor on the left is the first sensor and this has its ASW switch off. For the second sensor, the ASW switch was set before plugging it in.
Now, in the article, we can find the multiple sensors example. When the script is run, two independent values should be read. Sensor A is the sensor that has been running the whole tutorial with and its data is a little different to Sensor B because Sensor B is still warming up. To do this in code, we just need to initialize each sensor with the ASW argument. We have two initialization functions for these sensors. Sensor A has ASW equal to zero and for the second sensor, Sensor B with the address switch on, we pass in ASW equals one.
Now we have two instances of a PiicoDev air quality sensor in the code. When we want to read from them, we just refer to them as Sensor A and Sensor B and then we can access the properties like dot TIVOC, dot AQI, etc. So there you have a quick guide to the PiicoDev air quality sensor. We were able to read air quality with three different metrics and even read from two devices, so you could measure air quality on different sides of a wall, if you make anything cool from this starter project or you just have some questions, let us know in our forums. We're full-time makers and happy to help. See you next time!
Makers love reviews as much as you do, please follow this link to review the products you have purchased.