/Air_Quality_Monitoring_System

Air Quality Monitoring System measures the concentration of gases such as CO, CO2, and NH3.

Primary LanguageC++MIT LicenseMIT

Air Quality Monitoring System

Description

This code is used to monitor air quality with a four-sensor system that measures the concentration of gases such as CO, CO2, and NH3. The system also measures temperature and humidity using a BME280 sensor.
2020

Hardware Required

- Arduino board
- 4 x Gas sensors
- BME280 Sensor

Prerequisites

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

Setup

The ESP32 is connected to four gas sensors and a BME280 sensor. The BME280 sensor is connected using the I2C protocol. The four gas sensors are connected to the four analog input pins A0, A1, A2, and A3.

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.

Variables

- '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

Functions

- '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.

Example Chamber

Excel auto graph

License

This program is licensed under the MIT License. See the LICENSE file for details.