CO2 Detection with SCD41

Good ventilation is important, and while carbon dioxide is pretty useful for a bunch of stuff (making drinks fizzy, preserving exotic fruits, photosynthesis) an excess of it in your indoor spaces usually indicates that they're poorly ventilated and that there's quite a lot of recently exhaled air hanging about.

High CO2 levels can be used to identify spaces that are high risk for transmission of COVID-19 or other airborne diseases. An excess of CO2 in the air can also lead to tiredness and impaired cognitive function (unless you're a plant).

This quick guide will show you a few recipes for making some carbon dioxide detectors for your home, classroom or workspace, that are hopefully more interesting to look at than a boring grey box with a number on it. Because we're programming it ourselves with MicroPython it's completely customisable, and we're using a high quality Sensiron sensor breakout so it should give us proper CO2 readings.

About SCD41

SCD41 measures the amount of carbon dioxide in the air using photoacoustic spectroscopy (put very simply: zapping a gas sample with ultrasound, and measuring the concentration of gas by listening to the sound that it makes!).

This sensor is a true CO2 sensor which actually measures the concentration of CO2 in the air. Until recently, true CO2 sensors were a) huge and b) very expensive so they weren't very accessible to the maker community. We had to make do with eCO2 sensors, which estimate CO2 based on the amount of Volatile Organic Compounds floating around the place. This kind of works, but the readings can fluctuate a lot based on changes in humidity and other chemicals in the air (like when office mates accidentally leave the lids off their Sharpies!)

SCD41 also has temperature and humidity sensing built in, so you can program your CO2 detector devices to be thermometers and hygrometers as well - bonus!

Where carbon dioxide detection is useful

According to this article on hse.gov.uk - carbon dioxide detection is most useful in small and medium spaces (like offices and meeting rooms) that are consistently in use for over an hour. You should position detectors away from window, doors and air conditioner vents for accurate measurements, and they should be over 50cm away from people, as their exhaled breath can cause disproportionately high readings.

Interpreting the readings

The sensor reading will tell you how much CO2 is present in parts per million (ppm). You can use this to estimate the fresh air ventilation rate - a fresh-air supply rate of at least 10 litres per second is recommended for most commercial spaces which is equivalent to a CO2 reading of 1,000 ppm. Our pals at the Health and Safety Executive suggest that "CO2 levels consistently higher than 1,500ppm in an occupied room indicate poor ventilation and you should take action to improve it".

Disclaimer!

We are air quality enthusiasts and not air quality experts - if you're using DIY SCD41 measuring in your workplace/classroom to help keep people safe, we'd recommend calibrating your device against a known good commercial device to check that it (and your code) is behaving as expected.

Installing MicroPython on your RP2040 board

You'll first need to install our custom version of MicroPython, which comes with drivers for the SCD41 built in. If you're using a board that comes with MicroPython pre-installed like Galactic Unicorn, you can skip this step (though we're recommend updating to the newest version of MicroPython anyway, for the latest fixes and improvements.)

If you're brand new to Raspberry Pi Pico/RP2040 boards, you might find the step by step instructions in our Getting Started with Raspberry Pi Pico tutorial useful - it will show you how to install our custom MicroPython build and goes into more detail about how to use Thonny . Here's a quick TLDR!

  • Download the most recent MicroPython .uf2 for your board from the Releases page of our pimoroni-pico Github repository.
  • Hold down the BOOTSEL button of your board, and then press, and release, the RESET button. This will put it into bootloader mode, and it should appear as a drive on your computer called RPI-RP2.
  • Copy the .uf2 file to the RPI-RP2 drive - once you've done that your board will reboot running pirate brand MicroPython.

Plugging in your breakout

Plug one end of your Qw/ST cable into the Qw/ST connector on your breakout, and the other into the connector on your RP2040 board.

Plugging the Qw/ST cable into the breakout

Plugging the Qw/ST cable into your board

Running the basic SCD41 example

Here is a basic example that reads the sensor and should work on any of our boards. Fire up Thonny, copy and paste the example into the top box and press the green run button to run it. If your board is already busy running something else, you might need to press the stop button first.

After initialising the sensor (it takes a few seconds) it will start giving you CO2, temperature and humidity readings in Thonny's 'Shell' box (note that it won't update the screen or the display).

โš  If you have a board that uses the alternate I2C pins (Pico Explorer, Motor 2040, Servo 2040, Plasma 2040, Interstate 75) you will need to edit this example to use PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS instead of BREAKOUT_GARDEN_I2C_PINS.

Building your own CO2 detector

Now we've shown you the basics of how to read the sensor, here's a few ways to make it interesting with some cool pirate hardware.

You can run the code examples linked below by copying and pasting them into a new tab in Thonny and pressing the run button, just as above.

If you'd like the code to run automatically whenever your board gets power, save it to the board as main.py using Thonny. It's a good idea to test your code is behaving as expected before you do that though, as a malfunctioning main.py can stop you from communicating with the board.

Ominous CO2 detection with Wireless Plasma Kit

Wireless Plasma Kit gives you fifty individually controllable addressable RGB LEDs in a funky bottle, plus a Plasma Stick 2040 W microcontroller to drive them. There's also a Bring Your Own variant that comes without a bottle, in case you'd prefer to drape the LEDs around the place and make something like a carbon dioxide sensing Christmas tree.

CO2 sensing skull!

You'll need:

Link to code:

Smart CO2 detection with Plasma 2040 and neon effect LEDs

You can get addressable LEDs in all shapes and sizes these days! For a more futuristic option you could run a strip or two of this round the edge a whiteboard or window frame for a super bright reminder of when to improve the ventilation.

A strip of neon effect LEDs overlooking the Pimoroni warehouse

Close up of Plasma 2040 with a CO2 sensor attached

You'll need:

Link to code:

Beautiful CO2 detection with Galactic Unicorn

Want eye-catching LEDs and a numeric readout of the CO2 levels? Check out our swish Unicorn family of deluxe all-in-one LED matrices...

Galactic Unicorn showing a CO2 readout

We've also got a smaller Stellar Unicorn board coming soon (shhh!)

Stellar Unicorn showing a CO2 readout

You'll need:

Links to code:

Our Unicorns are both wearing laser cut acrylic diffusers, if you'd like to make one of your own there are links to the .dxf files on the shop page.

Portable CO2 detection with Pico GFX Pack

For CO2 on the CO go, you could consider Pico GFX Pack, with its pleasingly pixelated text options and a controllable RGB backlight for showing the CO2 situation at a glance. It's possible to plug a standard Raspberry Pi Pico or Pico W into GFX Pack, but we're using a Pimoroni Pico LiPo board which has a handy on/off power button and LiPo battery charging. We're powering it with one of our teeny tiny Galleon batteries here, but you might prefer a bigger LiPo battery or a USB power bank if you need longer battery life.

GFX Pack showing CO2 readouts

GFX Pack with Pico Lipo, battery and CO2 sensor attached

You'll need:

Link to code:

Securing the breakout to your board

If you want to stop the breakout from flapping about, we've had good results using a M2.5 standoff or M2.5 bolt to fasten your breakout to your board. You could also use Velcro dots!

โš  Note that the mounting holes on Galactic and Stellar Unicorn are slightly smaller, so you'll need M2 bolts or standoffs if you want to attach your breakout to a Unicorn.

Next steps

Let us know how you get on by tweeting your setup and experiences to us @pimoroni. We'd love to see how you make the code more visual and interesting! ๐Ÿงก๐Ÿ’›๐Ÿ’š

That's all folks!

Search above to find more great tutorials and guides.

Plasma 2040

Swathe everything in rainbows with this all-in-one, USB-C powered controller for WS2812/Neopixel and APA102/Dotstar addressable LED strip.