Air Quality Monitor (for CO2, TVOC, Temperature and Humidity) With RP2040

by gubutek in Circuits > Raspberry Pi

768 Views, 15 Favorites, 0 Comments

Air Quality Monitor (for CO2, TVOC, Temperature and Humidity) With RP2040

Air Quality Monitor (for CO2, TVOC, Temperature and Humindity)

This is an upgrade version of the air quality monitor device here https://www.instructables.com/Air-Monitor-With-RP2040-Zero-SSD1306-Oled-Screen-a/

I used RP2040-Zero micro-controller to gather data from

  1. SHT31 humidity and temperature sensor
  2. SGP30 air quality sensor (CO2 and TVOC)

The results are shown on SSD1306 oled screen.

You can download all the code from my Github

Supplies

RP2040-Zero

This is a mini version of RP Pico. It fits small project better because you don't need to use all the GPIO anyway. You will have a compact design using this. More important is the price, this one is cheaper that the original Pico.

SGP30

This is Multi-gas (VOC and CO₂eq) sensor.

SHT31

This Humidity and Temperature sensor is popular thanks to the accuracy and repeatablity. It is much better than DHT11 or DHT22 which are usually come with beginner kit.

Oled Screen SSD1306

In this versio I used the 2-colors yellow and blue, you should update the address of the screen in the ssd1306.py (line 105) to 0x3D instead of 0x3C


You will need some tool and material for soldering

  1. Wires and female headers for the circuit.
  2. Soldering iron
  3. Cutter

Make the Circuit

RP2040ZeroOledSGP30_bb.png
Capture.PNG
vlcsnap-2024-10-06-01h59m22s662.png
vlcsnap-2024-10-06-01h59m39s653.png

There are two I2C buses in the RP2040. According to my test, the SGP30 works well with the I2C1 so the other I2C0 can be used to connect the SHT31 and the oled screen.

It is not a complicated circuit so I decided the soldering it with prototype board. You can have a look at the temporary design there. If you would like to redesign, I recommend to put the two sensors as far as possible to each other. The SGP30 will be heated when it works and that could have affect on the SHT31


Add the Code and Test

PXL_20241004_143625313.jpg
Capture2.PNG
Capture3.PNG
vlcsnap-2024-10-06-03h05m44s052.png

In the python code, you will need to add the libraries for the sensors we used as well as the oled screen (lines 17,18, 19)

Then we have to assign the I2C buses to those components. As I said before, SGP30 only works well with the I2C1 (lines 36, 39) so the I2C0 will be used for both SHT31 and the SSD1306 oled screen (lines 29, 32, 33)

The measured data can be acquired using the build-in functions of the imported libraries (lines 81, 82)

You can use any program to add the code on RP2040-Zero (I used Thorny)

All the code is uploaded on my Github

3D Print a Case (optional)

PXL_20241006_053237557 (1).jpg
PXL_20241006_053314709.jpg
thumbnail2.png

I designed a case for this device. I planned to add magnet so I can mount it where I need it. This step is optional if you don't have access to 3D printers. In case you do, it will need spacers and some M2 screws to attach them together.

For your information, the case may increase the temparature of the SHT31 and you will have 1, 2 degrees higher and the surrouding environment. You can check on my video here for more details

Enjoy

That's all for today. I hope you can learn more about this microcontroller as well as those sensors. Feel free to play with the code. Happy making!