Trinket Air Quality Sensor

Source code is on GitHub. Ceramic cap is 104M, base resistor is 500 ohms, switch resistor is 1k. Electrolytic is 47 micro-farads

With the recent wildfires here in California and the on-going Covid crisis making us all stay indoors, indoor air quality has become a very important consideration. Working in a back bedroom all day can subject you to some bad air. Mostly volatile organic compounds — you know the stuff that smells — can build up and make a room unhealthy.

What I want, ultimately, is to monitor the indoor and outdoor air quality and generate alerts and run automation to deal with bad air. This sensor project is a key component for indoor air quality monitoring. But I wanted the sensor to provide some limited stand-alone functionality. By using the trinket’s dot star, a piezo buzzer and a button some basic functionality can be implemented.

The dot star on the Trinket serves as a visual indicator of the 10-minute rolling average of both pm 2.5 and eCo2 levels. Steady on is the current level of co2 — green, yellow, orange, red, purple, maroon. Flashing on is the current level of pm 2.5.

The levels are set as follows:


green< 1000 ppm
yellow< 1500 ppm
orange< 2000 ppm
red< 3000 ppm
purple< 5000 ppm
maroon> 5000 ppm

If enabled the alert will sound on orange and above. Solid on led displays eCO2 level.

pm 2.5

green< 12.1
yellow< 35.4
orange< 55.4
red< 150.4
purple< 250.4
maroon> 250.4

Blinking dot star is showing the pm25 warning level.

The button has 3 functions. If the alert is sounding 1 press will cancel it. Double click will toggle the alert buzzer on or off. Default is off. There is an increasing or decreasing tone to denote which happened. So, a hi to low tone means the alert is off. A long press will set the brightness of the dotstar. Default brightness is 90%. These settings revert to defaults on reset/power on.

A buzzer provides audible feedback of button presses and alerts. If enabled an alert tone will sound for 1 minute when a level goes above level 2 for either monitored compound.

The CCS811 measures VOCs that are normally found in indoor environments and provides an equivalent CO2 level. VOC levels vary by the atomic weight of the compound in question, so it is hard to pin down levels that require actions to be taken. But CO2 has well defined levels (such as this) that can be used for triggers.

For pm 2.5 measurement I chose the PMSA003I sensor. Adafruit sells this sensor on a breakout board which would be the way to go if you can get them. Otherwise you will need to either solder some wires on the very fine pitch connector Adafruit includes or you can use a swd breakout connector and a cable like I did. You will need to use a dremel to cut the connector to fit the PMSA003I. It’s really easy:

Start with this

Grind it down to this. The key has to go.

Ready for test. Can be glued and mounted as is or moved to another board.

A BME280 completes the package. The temperature and humidity are passed to the CCS811 to compensate for the measurements.

This is sort of a stew — the project takes advantage of components I had on hand as much as possible. If I were buying all the parts for this I would probably go with a BME680 and reduce the component count.

To utilize the project as a sensor for an HVAC system, we connect to it via the USB serial port. Command Messenger is used to pass messages to the device and retrieve data from the device. A python app is included that can help set measurement offsets and monitor data. It requires PyCmdMessenger. Data can be retrieved from the device in json format:

See the python source to see how offsets can be set for sensor readings. These are stored in flash when changed and will be valid after restarts.

The Arduino code is set up as a project. Change trinket_aqs.cpp to trinket_aqs.ino to use in Arduino ide. See the source for required libraries.