https://github.com/elixir-sensors/sgp40
Use Sensirion SGP40 air quality sensor in Elixir
https://github.com/elixir-sensors/sgp40
elixir iaq nerves-project sgp sgp4
Last synced: 4 months ago
JSON representation
Use Sensirion SGP40 air quality sensor in Elixir
- Host: GitHub
- URL: https://github.com/elixir-sensors/sgp40
- Owner: elixir-sensors
- Created: 2021-05-25T22:52:32.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-11T23:16:13.000Z (over 1 year ago)
- Last Synced: 2026-01-14T07:33:38.442Z (5 months ago)
- Topics: elixir, iaq, nerves-project, sgp, sgp4
- Language: C
- Homepage: https://hex.pm/packages/sgp40
- Size: 85 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# SGP40
[](https://hex.pm/packages/sgp40)
[](https://hexdocs.pm/sgp40)
[](https://github.com/elixir-sensors/sgp40/actions/workflows/ci.yml)
[](https://api.reuse.software/info/github.com/elixir-sensors/sgp40)
Use [Sensirion SGP40](https://www.sensirion.com/en/environmental-sensors/gas-sensors/sgp40/) air quality sensor in Elixir.
The raw signal from the SGP40 sensor is processed using [Sensirion's software algorithm](https://github.com/Sensirion/embedded-sgp/blob/00768191892b2cc0d839ebf95998fc4a85b660c4/sgp40_voc_index/sensirion_voc_algorithm.h) to give the [VOC Index](https://cdn.sparkfun.com/assets/e/9/3/f/e/GAS_AN_SGP40_VOC_Index_for_Experts_D1.pdf) that represents an air quality value on a scale from 0 to 500 where a lower value represents cleaner air.
## Usage
```elixir
iex> {:ok, sgp} = SGP40.start_link(bus_name: "i2c-1")
{:ok, #PID<0.1407.0>}
iex> SGP40.measure(sgp)
{:ok, %SGP40.Measurement{voc_index: 123, timestamp_ms: 885906}}
```
For better accuracy, you can provide the SGP40 sensor with relative ambient humidity and ambient temperature from an external humidity sensor periodically.
```elixir
iex> SGP40.update_rht(sgp, humidity_rh, temperature_c)
:ok
```
Depending on your hardware configuration, you may need to modify the call to
`SGP40.start_link/1`. See `t:SGP40.options/0` for parameters.