Professional Documents
Culture Documents
Calculate IAQ indices scaled 0-100% (100% is excellent) and 0-500 where 0 is
excellent and 500 Hazardous.
*/
/****************************************************************************
This is a library for the BME680 gas, humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME680 Breakout
----> http://www.adafruit.com/products/XXXX
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface.
***************************************************************************/
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h" //Standard PIN for BME680 is 0x76, so this redirects
to there.
#include "RTClib.h"
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library:
http://librarymanager/All#SparkFun_SCD30
#include "rgb_lcd.h"
#include <SeeedOLED.h>
#include <WiFiNINA.h>
#include "secrets.h"
#include <Seeed_HM330X.h>
float hum_weighting = 0.25; // so hum effect is 25% of the total air quality score
float gas_weighting = 0.75; // so gas effect is 75% of the total air quality score
HM330X sensor;
uint8_t buf[30];
const char *str[] = {"sensor num: ", "PM1.0 concentration(CF=1,Standard particulate
matter,unit:ug/m3): ",
"PM2.5 concentration(CF=1,Standard particulate
matter,unit:ug/m3): ",
"PM10 concentration(CF=1,Standard particulate
matter,unit:ug/m3): ",
"PM1.0 concentration(Atmospheric environment,unit:ug/m3): ",
"PM2.5 concentration(Atmospheric environment,unit:ug/m3): ",
"PM10 concentration(Atmospheric environment,unit:ug/m3): ",
};
RTC_DS1307 rtc;
void setup() {
Serial.begin(9600); // start the serial communication at 9600 baud
lcd.begin(16, 2); // set up the LCD's number of columns and rows
lcd.setRGB(colorR, colorG, colorB);
lcd.print("Volante Puro v.4");
Serial.println(F("BME680 test"));
Wire.begin();
if (!bme.begin()) {
Serial.println("Could not find a valid BME680 sensor, check wiring!");
while (1);
} else Serial.println("Found a sensor");
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.println("Sensor Readings:");
Serial.println(" Temperature = " + String(bme.readTemperature(), 2) +
"°C");
Serial.println(" Pressure = " + String(bme.readPressure() / 100.0F) + "
hPa");
Serial.println(" Humidity = " + String(bme.readHumidity(), 1) +
"%");
Serial.println(" Gas = " + String(gas_reference) + "
ohms\n");
Serial.print("Qualitative Air Quality Index");
humidity_score = GetHumidityScore();
gas_score = GetGasScore();
//Combine results for the final IAQ index value (0-100% where 100% is good
quality air)
float air_quality_score = humidity_score + gas_score;
Serial.println(" comprised of " + String(humidity_score) + "% Humidity and " +
String(gas_score) + "% Gas");
if ((getgasreference_count++) % 5 == 0) GetGasReference();
Serial.println(CalculateIAQ(air_quality_score));
if (sensor.read_sensor_value(buf, 29)) {
Serial.println("HM330X read result failed!!!");
}
parse_result_value(buf);
parse_result(buf);
print_result(*str, buf);
Serial.println("");
delay(2000);
if (airSensor.dataAvailable())
{
Serial.print("SCD30 Data - CO2(ppm):");
Serial.print(airSensor.getCO2());
Serial.print(" Temp(C):");
Serial.print(airSensor.getTemperature(), 1);
Serial.print(" Humidity(%):");
Serial.print(airSensor.getHumidity(), 1);
Serial.println();
}
else
Serial.println("Waiting for new data");
Serial.println("--------------------------------------------------------------");
void GetGasReference() {
// Now run the sensor for a burn-in period, then use combination of relative
humidity and gas resistance to estimate indoor air quality as a percentage.
Serial.println("Getting a new gas reference value");
int readings = 10;
for (int i = 1; i <= readings; i++) { // read gas for 10 x 0.150mS = 1.5secs
gas_reference += bme.readGas();
}
gas_reference = gas_reference / readings;
Serial.println("Gas Reference = "+String(gas_reference,3));
}
return NO_ERROR;
}