{"id":21851768,"url":"https://github.com/sighmon/co2_sensor_scd4x_esp32_http_server","last_synced_at":"2025-07-05T09:35:40.495Z","repository":{"id":50543101,"uuid":"452113532","full_name":"sighmon/co2_sensor_scd4x_esp32_http_server","owner":"sighmon","description":"An Arduino sketch for the Adafruit SCD4X and SCD-30 CO2 sensor running on an ESP32 with an http server.","archived":false,"fork":false,"pushed_at":"2024-05-05T01:08:43.000Z","size":6749,"stargazers_count":7,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T09:42:52.867Z","etag":null,"topics":["co2","esp32","http-server","prometheus","scd-30","scd-40","scd-41","sensor"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sighmon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-01-26T02:24:05.000Z","updated_at":"2024-06-24T10:11:34.000Z","dependencies_parsed_at":"2024-01-16T00:20:12.283Z","dependency_job_id":"825e7966-2ab9-440b-be28-b0b0aed8d516","html_url":"https://github.com/sighmon/co2_sensor_scd4x_esp32_http_server","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"c1627fcd796bd39f1d6eeb587d7ef59086ee4eb1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sighmon%2Fco2_sensor_scd4x_esp32_http_server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sighmon%2Fco2_sensor_scd4x_esp32_http_server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sighmon%2Fco2_sensor_scd4x_esp32_http_server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sighmon%2Fco2_sensor_scd4x_esp32_http_server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sighmon","download_url":"https://codeload.github.com/sighmon/co2_sensor_scd4x_esp32_http_server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248914127,"owners_count":21182360,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["co2","esp32","http-server","prometheus","scd-30","scd-40","scd-41","sensor"],"created_at":"2024-11-28T01:10:38.269Z","updated_at":"2025-04-14T16:21:08.787Z","avatar_url":"https://github.com/sighmon.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Adafruit SCD4X/SCD30 CO2 sensor for ESP32\n\nAn Arduino sketch for the [Adafruit SCD4X CO2 sensor](https://github.com/adafruit/Adafruit_CircuitPython_SCD4X) and [Adafruit SCD-30 CO2 sensor](https://github.com/adafruit/Adafruit_SCD30) running on an ESP32 with an http server returning [Prometheus](https://prometheus.io) compatible responses, and sensor readings sent via Bluetooth BLE.\n\n![The Adafruit SCD-41 CO2 sensor graphed in Grafana](scd-41-co2-temperature-humidity.png)\n\nRelated software:\n\n* [Prometheus/Grafana Docker containers for Raspberry Pi](https://github.com/sighmon/prometheus-grafana-raspberry-pi)\n* [Apple HomeKit accessory for the SCD4x/SCD-30 CO2 sensor](https://github.com/sighmon/homekit-scd4x)\n* [iOS/macOS BLE CO2 sensor](https://github.com/sighmon/ios-ble-co2-sensor)\n* [Sensirion iOS app](https://apps.apple.com/ch/app/sensirion-myambience-co2/id1529131572)\n\n## Hardware\n\n* [Adafruit SCD-41 CO2 sensor](https://www.adafruit.com/product/5190)\n* [Adafruit ESP32-C3 QT Py dev board](https://www.adafruit.com/product/5405)\n* [Adafruit battery charger for QT Py](https://www.adafruit.com/product/5397)\n* [Adafruit Qwiic cable](https://www.adafruit.com/product/4399)\n* Nokia BP-6MT 3.7V battery (any 3.7 - 4.2V battery will work)\n\n## Setup\n\n**WiFi**:\n\n* Copy the secrets file: `cp secrets.tmpl.h secrets.h`\n* Fill in your SSID and password in `secrets.h`\n* **Note**: the ESP32-C3 only connects to a 2.4 GHz network\n\n**Arduino**:\n\n* Download the latest version of Arduino from https://www.arduino.cc\n* From `Tools \u003e Manage Libraries...` add the library: `Sensirion I2C SCD4x`\n* If you have an `SCD-30` CO2 sensor, add the library: `Adafruit SCD30`\n* Uncomment either `#define USESCD30` or `#define USESCD4X`\n* Install the Sensirion BLE library: `cd ~/Documents/Arduino/library` and then `git clone https://github.com/Sensirion/arduino-ble-gadget.git`\n* Install the NimBLE library: `cd ~/Documents/Arduino/library` and then `git clone https://github.com/h2zero/NimBLE-Arduino.git`\n* Install the Adafruit boards [following their instructions](https://learn.adafruit.com/adafruit-qt-py-esp32-c3-wifi-dev-board/arduino-ide-setup)\n* Connect your ESP32 via USB\n* Now try `Upload` to send the code to your ESP32\n\n**Note**: As of 9th April 2024 this was the dependency versions that compiled on a Sparkfun ESP32 Thing:\n\n* `git clone git@github.com:Sensirion/arduino-ble-gadget.git` into `~/Arduino/libraries` and then `git checkout tags/1.2.0` and add `#include \u003cstring\u003e` to `ByteArray.h`\n* `git clone git@github.com:Sensirion/arduino-upt-core.git Sensirion_UPT_Core` into `~/Arduino/libraries` and then `git checkout 919ef8b`\n* `git clone git@github.com:h2zero/NimBLE-Arduino.git` into `~/Arduino/libraries` and then `git checkout release/1.4`\n* Install the `ESP32` boards library at `v2.0.11`\n\n**iOS/macOS Bluetooth app**:\n\nI built an iOS/macOS app so location data can be saved with CO2 reading data.\n\nProject code: [ios-ble-co2-sensor](https://github.com/sighmon/ios-ble-co2-sensor)\n\n\u003cimg src=\"https://github.com/sighmon/ios-ble-co2-sensor/raw/main/co2-sensor-ios-green.png\" width=\"20%\" style=\"padding: 10px;\"\u003e\u003cimg src=\"https://github.com/sighmon/ios-ble-co2-sensor/raw/main/co2-sensor-ios-yellow.png\" width=\"20%\" style=\"padding: 10px;\"\u003e\u003cimg src=\"https://github.com/sighmon/ios-ble-co2-sensor/raw/main/co2-sensor-ios-orange.png\" width=\"20%\" style=\"padding: 10px;\"\u003e\u003cimg src=\"https://github.com/sighmon/ios-ble-co2-sensor/raw/main/co2-sensor-ios-archive-detail.png\" width=\"20%\" style=\"padding: 10px;\"\u003e\n\nThis code also works with the standard Sensirion MyAmbience app:\n\n* Install the Sensirion MyAmbience app: [iOS](https://apps.apple.com/ch/app/sensirion-myambience-co2/id1529131572)/[Android](https://play.google.com/store/apps/details?id=com.sensirion.myam)\n* Turn on Bluetooth on your device\n* The readings should update every 5 seconds\n\n\u003cimg src=\"sensirion-ios-app.png\" alt=\"The Sensirion iOS app\" width=\"25%\"/\u003e\n\n## Serial monitor\n\nIf you open the Arduino serial monitor you'll see:\n\n* The WiFi output as it attempts to connect to your WiFi network\n* The SCD4X/SCD-30 CO2 readings\n\n## LEDs\n\nWhile starting up the LED will light up in this sequence\n\n* Red blink - setup is starting\n* Blue slow blink - trying to connect to WiFi\n* Green blink - connected\n\nWhile running:\n\n* Green pulse for an http request\n* Blue pulse for a BLE reading sent\n\n## http response\n\nOnce your ESP32 has connected to your SSID, it will respond over port 80 with a [Prometheus](https://prometheus.io) response. e.g. `curl 192.168.1.100:80/metrics`\n\n```bash\n# HELP ambient_temperature Ambient temperature\n# TYPE ambient_temperature gauge\nambient_temperature 19.95\n# HELP ambient_humidity Ambient humidity\n# TYPE ambient_humidity gauge\nambient_humidity 59.20\n# HELP co2 CO2\n# TYPE co2 gauge\nco2 1333\n# HELP battery_voltage Battery voltage\n# TYPE battery_voltage gauge\nbattery_voltage 3.15\n```\n\nMy ESP32-C3 with the SCD-41 CO2 sensor running off of an old Nokia BP-6MT battery.\n\n![My ESP32-C3 with the SCD-41 CO2 sensor running off of an old Nokia BP-6MT battery](scd4x-esp32-c3.jpg)\n\n## Thanks\n\nShoutout to [Core Electronics](https://core-electronics.com.au) for being so fast with their delivery of the [Adafruit SCD-41](https://core-electronics.com.au/adafruit-scd-41-ndir-co2-temperature-and-humidity-sensor-stemma-qt-qwiic.html).\n\n## Licenses\n\n* My code: MIT License\n* ESP32 example code `SimpleWiFiServer` by Jan Hendrik Berlin\n* Sensirion I2C SCD4X example code `exampleUsage` license:\n\nCopyright (c) 2021, Sensirion AG\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n* Neither the name of Sensirion AG nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\nAND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\nARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\nLIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\nCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\nSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\nINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\nCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\nARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsighmon%2Fco2_sensor_scd4x_esp32_http_server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsighmon%2Fco2_sensor_scd4x_esp32_http_server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsighmon%2Fco2_sensor_scd4x_esp32_http_server/lists"}