Use Sensirion SGP40 air quality sensor in Elixir.
The raw signal from the SGP40 sensor is processed using Sensirion's software algorithm to give the VOC Index that represents an air quality value on a scale from 0 to 500 where a lower value represents cleaner air.
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.
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.