sighmon / co2_sensor_scd4x_esp32_http_server

An Arduino sketch for the Adafruit SCD4X and SCD-30 CO2 sensor running on an ESP32 with an http server.
MIT License
7 stars 2 forks source link
co2 esp32 http-server prometheus scd-30 scd-40 scd-41 sensor

Adafruit SCD4X/SCD30 CO2 sensor for ESP32

An Arduino sketch for the Adafruit SCD4X CO2 sensor and Adafruit SCD-30 CO2 sensor running on an ESP32 with an http server returning Prometheus compatible responses, and sensor readings sent via Bluetooth BLE.

The Adafruit SCD-41 CO2 sensor graphed in Grafana

Related software:

Hardware

Setup

WiFi:

Arduino:

Note: As of 9th April 2024 this was the dependency versions that compiled on a Sparkfun ESP32 Thing:

iOS/macOS Bluetooth app:

I built an iOS/macOS app so location data can be saved with CO2 reading data.

Project code: ios-ble-co2-sensor

This code also works with the standard Sensirion MyAmbience app:

The Sensirion iOS app

Serial monitor

If you open the Arduino serial monitor you'll see:

LEDs

While starting up the LED will light up in this sequence

While running:

http response

Once your ESP32 has connected to your SSID, it will respond over port 80 with a Prometheus response. e.g. curl 192.168.1.100:80/metrics

# HELP ambient_temperature Ambient temperature
# TYPE ambient_temperature gauge
ambient_temperature 19.95
# HELP ambient_humidity Ambient humidity
# TYPE ambient_humidity gauge
ambient_humidity 59.20
# HELP co2 CO2
# TYPE co2 gauge
co2 1333
# HELP battery_voltage Battery voltage
# TYPE battery_voltage gauge
battery_voltage 3.15

My ESP32-C3 with the SCD-41 CO2 sensor running off of an old Nokia BP-6MT battery.

My ESP32-C3 with the SCD-41 CO2 sensor running off of an old Nokia BP-6MT battery

Thanks

Shoutout to Core Electronics for being so fast with their delivery of the Adafruit SCD-41.

Licenses

Copyright (c) 2021, Sensirion AG All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.