Maker.io main logo

CO2 Detection with SCD41

2023-08-03 | By Pimoroni

License: See Original Project

Courtesy of Pimoroni

Guide by Pimoroni

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, which 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.‎

plug_1

plug_2

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.‎

funky_3

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.‎

room_4

room_5

You'll need:‎

  • A SCD41 CO2 Sensor Breakout
  • A Qw/ST (JST-SH to JST-SH) cable
  • Plasma 2040
  • Neon-like RGB LED Strip with Diffuser
  • LED Strip Input/Output Cable - 3-pin (Pin variant)
  • USB-C to USB-A cable for programming

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...‎

led_6

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

led_7

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.‎

battery_8

battery_9

You'll need:‎

  • A SCD41 CO2 Sensor Breakout
  • A Qw/ST (JST-SH to JST-SH) cable
  • Pico GFX Pack
  • Pimoroni Pico LiPo (with soldered headers) and Galleon 400mAh Hard ‎Case LiPo Battery
  • ‎... or Raspberry Pi Pico H and NanoWave 3 5000mAh Power Bank if ‎you don't want to solder
  • USB-C cable (or USB micro-B cable) for programming‎

Link to code:‎

co2.py

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!‎

制造商零件编号 SEK-SCD41-SENSOR
SCD4X DEV BOARD W/CABLES
Sensirion AG
¥543.13
Details
制造商零件编号 PIM666
WIRELESS PLASMA KIT (PICO W ABOA
Pimoroni Ltd
¥354.09
Details
制造商零件编号 PIM582
PLASMA 2040
Pimoroni Ltd
¥132.68
Details
制造商零件编号 PIM631
GALACTIC UNICORN (PICO W ABOARD)
Pimoroni Ltd
¥603.45
Details
制造商零件编号 SC0917
RASPBERRY PI PICO H RP2040
Raspberry Pi
¥40.70
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum