Raspberry Pi Pico Carbon Dioxide Sensor

🔖 iot ⏲️ 1 minute to read

I decided to monitor the CO2 levels in my home office, and building on my previous Rasberry Pi Pico project I swapped out the BME280 Breakout with an SCD41 Breakout (and this time, a JST-SH cable so I didn't need to solder it):

This breakout is significantly more expensive than a temperature monitor, but it's a significantly more complex sensor (and includes temperature and humidity monitoring - so you essentially also get a BME280 chip without atmospheric pressure).

Here's the result in Home Assistant from the first day of the sensor:

Getting started, the pinout from the JST-SH cable to the Pico is as follows:

Wire Color Purpose Pico Pin
Black GND 3
Red 3-5V 36
Blue SDA 1
Yellow SCL 2

Next is the code to initialize and read data from the chip. Pimoroni recommend using their Micropython distribution which has out of the box support, but I preferred to stick with the official Micropython version for now.

I found a good pure Python library published by Yutaka Kato on GitHub, and pulled out the SCD4X class into its own file as scd4x.py.

One thing to note about this chip is that it has an auto-calibration feature, which some users do not like. This library does not yet offer the capability to disable that auto-calibration feature.

Once on the Pico, it was just a case of modifying my existing code to optionally allow the use of this chip via the library:

import machine
import config
import scd4x

# Init SCD4X
if config.scd4x_sensor['enabled']:
    i2c_scd4x = machine.I2C(0, scl=config.scd4x_sensor['scl_pin'], sda=config.scd4x_sensor['sda_pin'], freq=100000)
    scd = scd4x.SCD4X(i2c_scd4x)
    scd.start_periodic_measurement()

def update_scd4x_sensor():   
    current_temp = scd.temperature
    current_co2 = scd.co2
    current_humidity = scd.relative_humidity

    if current_temp is None or current_co2 is None or current_humidity is None:
        return

    # Send update to Home Assistant
    
def main_loop():  
    # <other updates>

    if config.scd4x_sensor['enabled']:
        update_scd4x_sensor()

It takes the sensor a little while to start reporting values, so the None check is required to avoid sending bad values back to Home Assistant. The full code is on GitHub, with configurable support for the SCD41, a motion sensor, and the BME280: config.py.

🏷️ pico sensor chip bme280 breakout code library pi monitor scd41 jst-sh cable significantly temperature assistant

⬅️ Previous post: Using a New Hard Disk on Ubuntu

➡️ Next post: Raspberry Pi Pico W WiFi Resiliency

🎲 Random post: Scam Warning

Comments

Please click here to load comments.