Building an Air Quality Monitor with Arduino

12 May 2023 Balmiki Mandal 0 µC - µP

Using Arduino to Monitor Air Quality

In today’s world, air pollution is a major concern. Although we can’t control the sources of air pollution, we can measure it with the help of devices like air quality monitors. Monitors are used to measure factors such as air temperature, humidity, carbon dioxide levels, and other gases. And with Arduino, you can now make one of your own.

An air quality monitor with Arduino is an affordable and reliable way to measure the air quality in your environment. Using a combination of sensors and Arduino boards, you can build a system to detect particulate matter, volatile organic compounds (VOCs), temperature, humidity, and more.

The first step is to choose the appropriate Arduino board and sensors. Arduino’s UNO board is the recommended one for this application. You will also need sensors to collect data from the environment. Popular ones include the MQ-135 gas sensor, which can detect VOCs, and the DHT11/22 temperature and humidity sensor.

The next step is to write code for the Arduino board to interpret the data collected. This is done using the C++ programming language. Once the code is written and compiled, it can be uploaded to the Arduino board. After that, your air quality monitor is ready to be used.

Finally, the data can be sent to a computer or a web-enabled device for analysis. This way, it’s possible to create graphs and charts showing the air quality over time. This can be useful for tracking changes in air pollution levels, as well as providing real-time alerts when levels go beyond safe limits.

So if you’re looking for an easy and cost-effective way to monitor air quality, consider building an Arduino-based air quality monitor. With the right hardware and software, you can create an efficient and reliable system that can keep track of air pollution levels in your area.

Here is a sample Arduino code for building an air quality monitor with Arduino:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>

#define LED_PIN 13 // Set the pin number to which the LED is connected

Adafruit_BME680 bme; // Create an instance of the BME680 sensor

void setup() {
  Serial.begin(9600); // Initialize the serial communication
  pinMode(LED_PIN, OUTPUT); // Set the LED pin as an output
  
  if (!bme.begin()) { // Initialize the BME680 sensor
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
  }
  
  bme.setTemperatureOversampling(BME680_OS_8X); // Set the temperature oversampling to 8x
  bme.setHumidityOversampling(BME680_OS_2X); // Set the humidity oversampling to 2x
  bme.setPressureOversampling(BME680_OS_4X); // Set the pressure oversampling to 4x
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3); // Set the filter size to 3
  bme.setGasHeater(320, 150); // Set the gas heater to 320 degrees Celsius for 150 milliseconds
}

void loop() {
  if (bme.performReading()) { // Perform a reading from the BME680 sensor
    float temperature = bme.temperature;
    float humidity = bme.humidity;
    float pressure = bme.pressure / 100.0;
    float gasResistance = bme.gas_resistance / 1000.0;
    
    Serial.print("Temperature = ");
    Serial.print(temperature);
    Serial.println(" °C");
    
    Serial.print("Humidity = ");
    Serial.print(humidity);
    Serial.println(" %");

    Serial.print("Pressure = ");
    Serial.print(pressure);
    Serial.println(" hPa");
    
    Serial.print("Gas resistance = ");
    Serial.print(gasResistance);
    Serial.println(" kOhms");
    
    if (gasResistance > 150) { // If the gas resistance is greater than 150 kOhms, turn on the LED
      digitalWrite(LED_PIN, HIGH);
    } else {
      digitalWrite(LED_PIN, LOW); // Otherwise, turn off the LED
    }
  } else {
    Serial.println("Failed to perform reading from BME680 sensor!");
  }
  
  delay(2000); // Wait for 2 seconds before taking the next reading
}

This code uses a BME680 sensor to measure temperature, humidity, pressure, and gas resistance and triggers an alarm if the gas resistance is too high. The LED is connected to pin 13.

In the setup() function, the code initializes the serial communication, sets the LED pin as an output, and initializes the BME680 sensor. The sensor oversampling and filter size are set, and the gas heater is turned on.

In the loop() function, the code performs a reading from the BME680 sensor and prints the temperature, humidity, pressure, and gas resistance values to the serial monitor. If the gas resistance is greater than 150 kOhms, the code turns on the LED. Otherwise, the LED is turned off.

Note that this code provides a basic framework for an air quality monitor and may require modifications to suit specific needs. For example, the gasResistance value can be used to calculate air quality index (AQI), and additional sensors and logic can be added to trigger different types of alarms or notifications.

Author
BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.