2020 - Arduino board
- 4 x Gas sensors
- BME280 Sensor
Before using this program, make sure you have the following libraries installed:
- Wire.h - included with Arduino IDE
- SPI.h - included with Arduino IDE
- Adafruit_Sensor.h - install from the Arduino Library Manage
- Adafruit_BME280.h - install from the Arduino Library Manage
In the 'setup()' function, the BME280 sensor is initialized and a test message is printed on the serial monitor. The first line of data is printed to the serial monitor, which contains the labels of the columns of the data table.
The 'loop()' function starts by checking if 'runs' is equal to zero. If 'runs is zero, the system starts measuring data from the four gas sensors and the BME280 sensor. The measurement values are stored in an array named 'data'.
If 'runs' is not zero, the system enters a regression analysis function. The regression function calculates the regression line for each gas sensor using the measured data from the four gas sensors and a calibration dataset. After the regression analysis, the system enters a mode where it can calculate the gas concentration of each sensor using the regression lines.
If there is input data available on the serial monitor, the system reads it and stores it in a variable called 'key'. If 'key' is equal to "300", "200", "100", or "0", the system sets the variable 'j'to the appropriate value. If 'key' is equal to "G", the system prints the measured data to the serial monitor and enters the regression analysis mode. If 'key' is equal to "C", the system calculates and prints the gas concentration of each sensor using the regression lines.
- 'key': A variable that stores the input data from the serial monitor- 'runs': A counter variable used to keep track of the number of measurements
- 'i, 'j', and o: Counter variables used in the regression analysis
- 'data[4][4]': An array used to store the measured data
- 'sigmaX[4]', 'sigmaXY[4]', 'sigmaX2[4]', 'b[4]', 'a[4]', 'Xbar[4]', and 'Ybar': Variables used in the regression analysis
- 'Sen1', 'Sen2', 'Sen3', and 'Sen4': Variables used to control the timing of the sensor readings
- 'setup()': Initializes the BME280 sensor and prints a test message to the serial monitor.
- 'loop()': Reads the sensor data, performs regression analysis, and calculates the gas concentration of each sensor.
- 'regression()': Calculates the regression line for each gas sensor using the measured data from the four gas sensors and a calibration dataset.
This program is licensed under the MIT License. See the LICENSE file for details.