{"id":20082502,"url":"https://github.com/paulgreg/co2-sensor","last_synced_at":"2025-05-06T01:30:23.061Z","repository":{"id":138756106,"uuid":"308420341","full_name":"paulgreg/co2-sensor","owner":"paulgreg","description":"An esp8266 based CO2 sensor","archived":false,"fork":false,"pushed_at":"2024-07-13T10:16:02.000Z","size":197,"stargazers_count":8,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-07-13T11:29:38.873Z","etag":null,"topics":["co2","esp8266","iot","iot-device","temperature"],"latest_commit_sha":null,"homepage":"https://hackaday.io/project/175627-co2-temperature-sensors","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paulgreg.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,"publiccode":null,"codemeta":null}},"created_at":"2020-10-29T18:47:23.000Z","updated_at":"2024-07-13T11:29:45.966Z","dependencies_parsed_at":null,"dependency_job_id":"8ff0cc37-3743-4920-945b-f5fa586d4c25","html_url":"https://github.com/paulgreg/co2-sensor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulgreg%2Fco2-sensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulgreg%2Fco2-sensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulgreg%2Fco2-sensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulgreg%2Fco2-sensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulgreg","download_url":"https://codeload.github.com/paulgreg/co2-sensor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224478444,"owners_count":17318085,"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","esp8266","iot","iot-device","temperature"],"created_at":"2024-11-13T15:43:43.912Z","updated_at":"2024-11-13T15:43:44.538Z","avatar_url":"https://github.com/paulgreg.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esp8266 CO2 sensor\n\nThat project goal is to mesure CO2 and if too high, tell user to open their windows.\nIt’s a simple way to remind to recycle air and so, reduce risk against COVID-19 in crowded space (like classrooms).\nInspiration is from [Eole project](http://lafabrique.centralesupelec.fr/projetco2/). Thanks\n\nOptionaly, you can send data to a server (influxdb \u0026 grafana) to get values over time.\n\n## Components\n\n * esp8266 (I’ve used a Wemos D1 for tryout, and then an ESP8266 for definitive project)\n * I2C 128X64 OLED LCD screen\n * Humidity \u0026 temperature DHT11 sensor (needed as input to SGP30)\n * SGP30 Air Quality Sensor CO2 sensor\n\n## Connections\n\n### I2C screen\n\n * GND on GND\n * VCC on 3.3V\n * SCL on esp8266 D1\n * SDA on esp8266 D2\n\n### SGP30 sensor\n\n * GND on GND\n * VCC on 3.3V\n * SCL on esp8266 D1\n * SDA on esp8266 D2\n\n### DHT11 sensor\n\n * GND on GND\n * VCC on 3.3V\n * sensor to d5 / GPIO14\n\n## Information\n\nFirst copy `parameters.h.dist` to `parameters.h`.\nIt contains the `CO2_THRESHOLD` value which inverts the display.\nIt’s a simple way to bring attention to users to open windows.\n\nAs explained on  [Adafruit SGP30 sensor page](https://learn.adafruit.com/adafruit-sgp30-gas-tvoc-eco2-mox-sensor/arduino-code), the SPG30 sensor needs to be calibrated with a baseline value (given by the sensor).\nThat baseline is periodically asked from SPG30 sensor and stored into EEPROM (~1 time per hour).\nWhen the system boots, it's read from EEPROM and the SPG30 is calibrated with that value. That increase the sensor precision.\n\nIf I understood correctly, the best baseline value is get after 12 continuous hours of operation. If you don’t use the sensor for 7 days, you’ll have to let it run again for 12 hours to « reset » the correct baseline.\n\nAlso, the DHT11 sensor is used to compute absolute humidity level, also used to increase SGP30 precision.\n\nIf you define a `WIFI_SSID`, a `WIFI_PASSWORD` and a `INFLUXDB_URL` in `parameters.h`, the esp8266 will periodically send temperature, humidity \u0026 co2 to an influxdb database. You can set the location name (like the room where the sensor is placed) in `LOCATION` parameter.\n\n## Grafana, Influxdb\n\nYou can install influxdb, telegraf (used for system metrics) \u0026 grafana via docker (links in reference).\n\nYou’ll have to create a `sensor` datbase via : `curl -XPOST -s http://localhost:8086/query\\?pretty\\=true --data-urlencode \"q=CREATE DATABASE sensor\"`\n\nYou can then send a test data :\n`curl -i -XPOST 'http://localhost:8086/write?db=sensor' --data-binary 'temperature,location=home value=20.0'`\n\nAnd read it back :\n`curl -XPOST -s http://localhost:8086/query\\?pretty\\=true --data-urlencode \"db=sensor\" --data-urlencode \"q=SELECT * FROM temperature\"`\n\nThe grafana board I configured has been exported to grafana directory.\n\nHere’s a sample output :\n![Screenshot of grafana dashboard](./grafana/grafana.png 'Dashboard')\n\n\n## References\n\n### Hardware\n\n  * [Eole project](http://lafabrique.centralesupelec.fr/projetco2/)\n  * [I2C OLED screen](https://randomnerdtutorials.com/esp8266-0-96-inch-oled-display-with-arduino-ide/)\n  * [DHT11 sensor tryout](https://hackaday.io/project/175689/log/185783-humidity-temperature-module)\n  * [Adafruit SGP30 sensor explanation](https://learn.adafruit.com/adafruit-sgp30-gas-tvoc-eco2-mox-sensor/arduino-code)\n  * [esp8266 pinout reference](https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/)\n  * [Passage de la requête POST via ESP8266 à InfluxDB](https://stackoverrun.com/fr/q/10514644)\n\n### Server\n\n  * [get system metrics for 5 min with docker telegraf influxdb and grafana](https://towardsdatascience.com/get-system-metrics-for-5-min-with-docker-telegraf-influxdb-and-grafana-97cfd957f0ac)\n  * [install grafana influxdb telegraf using docker compose](https://dev.to/project42/install-grafana-influxdb-telegraf-using-docker-compose-56e9)\n  * [Write data with the InfluxDB API](https://docs.influxdata.com/influxdb/v1.8/guides/write_data/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulgreg%2Fco2-sensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulgreg%2Fco2-sensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulgreg%2Fco2-sensor/lists"}