How to Build a DIY Air Quality Sensor with Arduino

Photo of author

By Jackson Taylor

In this guide, you will build a home air quality sensor with Arduino. You can track room toxins with low cost parts. You get complete control over your data. This project helps keep your air safe. You will learn sensor choices, wiring, and programming. The guide is simple and fun. Enjoy each step as I share my own project stories.

What You’ll Learn

  • How to choose sensors for air quality.
  • How to wire sensors to an Arduino board.
  • How to write and run Arduino code.
  • Tips on data display and troubleshooting.

Introduction: Why Monitor Your Air Quality?

I remember my first build with an Arduino. I felt a thrill when it worked. Poor air quality can make you sleep unwell. It can also affect your mood and thinking. You do not need a pricey monitor. You can build one at home. Plus, it gives you control over your data. This guide offers simple steps and clear instructions. It is for everyone from beginners to hobbyists.

Understanding Air Quality Measurements

Air quality means many things. It measures particles and gases in the air. You may sense dust, gas, and humidity levels. Here are common measures:

  • Particulate Matter (PM): Tiny particles like PM2.5.
  • Volatile Organic Compounds (VOCs): Gases from paints or cleaners.
  • Carbon Dioxide (CO2): Indicates the breathability of air.
  • Carbon Monoxide (CO): A dangerous gas with no smell.
  • Temperature and Humidity: Affect comfort and sensor readings.
  • Air Pressure: Helps show changes in weather.

A simple table can show impacts:

Pollutant Effects Safe Level
PM2.5 Breathing issues Below 12 μg/m³
VOCs Irritation, headache Varies
CO2 Drowsiness Below 1000 ppm
CO Head pain, dizziness Below 9 ppm

These details give you clues on how to act if readings are high.

Choosing the Right Air Quality Sensors for Arduino

There are many sensors that work with Arduino. I tried a few in my projects. Here are some popular choices:

See also
Using Arduino Sleep Mode to Save Battery Life
Sensor What It Measures Price Pros Cons
MQ135 VOCs, CO2, and other gases $5 Cheap and common Needs special calibration
BME680 Temp, humidity, pressure, VOCs $20 All-in-one setup Not gas-specific
PMSA003I Particulate matters (PM1, PM2.5) $35 Accurate on particles Only measures particulates
SCD40 CO2, temp, and humidity $45 High precision Price is a bit high
SGP30 VOCs and equivalent CO2 $20 Good gas detection Needs humidity data

Each sensor has its place. For starters, consider an MQ135 with a DHT11 for temp and humidity. For finer data, mix a particulate unit like the PMSA003I with a gas sensor.

Points to Check

  • Power needs: Many sensors use 5V.
  • Warm-up: Some need hours of use to get stable.
  • Lifespan: Gas sensors may work a year or more.
  • Data format: Some output analog readings; others use I2C.

Hardware Components Needed

Gather your parts. Here is a typical list:

  1. An Arduino Uno or Nano.
  2. Air quality sensor(s) of your choice.
  3. An optional display (like a small OLED).
  4. A USB cable or power adapter.
  5. A breadboard and jumper wires.
  6. An enclosure to protect your project.

For extra features, you might add:

  • An SD card module for logging.
  • A real-time clock for timestamps.
  • A WiFi module for online data.

A rough cost breakdown is:

Component Approximate Cost
Arduino Board $10-25
Air Quality Sensor $5-45
Display $5-10
Breadboard/Wires $5-10
Add-ons $5-15
Total $30-120

Wiring Your Air Quality Sensor to Arduino

Wiring is the backbone of a stable system. Check each connection twice before you power up. For the MQ135, use this simple diagram:

Arduino     MQ135
5V   ------> VCC
GND   ------> GND
A0   ------> Analog Output

For I2C sensors (such as PMSA003I or BME680):

Arduino     Sensor
5V   ------> VCC
GND   ------> GND
A4   ------> SDA
A5   ------> SCL

For a display (like a 0.96″ OLED):

Arduino     OLED
5V   ------> VCC
GND   ------> GND
A4   ------> SDA
A5   ------> SCL

I built my own circuit on a breadboard first. It helped me see correct parts and wiring. Always check your wires with a multimeter if you doubt.

See also
PRODUCTS Visit Our ebay store to buy or contact directlyCLICK HERE TO GO Arduino bootloader-programmed chip (ATMEGA328) (RS -190) Arduino bootloader-programmed chip (ATMEGA8) (RS -110) LVDT - for academic projects only (RS -1000) Ultra sonic sensor (RS - 200) Coming Soon 433MHz RF transmitter + Receiver Module (RS - 200) IR obstacle sensor (RS - 50)

Programming Your Air Quality Monitor

This section gives you two code examples to get your sensor running. Begin with the simple code for the MQ135 sensor.

Basic Code Sample

Below is an Arduino sketch that reads from the MQ135 sensor:

const int airQualityPin = A0;

void setup() {
 Serial.begin(9600);
 Serial.println("Air Quality Sensor Start");
 delay(1000);
}

void loop() {
 int airValue = analogRead(airQualityPin);
 Serial.print("Air value: ");
 Serial.println(airValue);

 if (airValue < 200) {
  Serial.println("Air is clean");
 } else if (airValue < 400) {
  Serial.println("Air is average");
 } else if (airValue < 600) {
  Serial.println("Air is poor");
 } else {
  Serial.println("Air is very poor");
 }

 delay(1000);
}

Advanced Code for Multiple Sensors and Display

If you choose to add a display and extra sensors, try this sketch:

#include 
#include 
#include 
#include 
#include 

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET   -1

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_PM25AQI pmSensor = Adafruit_PM25AQI();
Adafruit_BME680 bme;

void setup() {
 Serial.begin(9600);

 // Start display
 if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
  Serial.println("Display failed");
  while (true);
 }
 display.clearDisplay();
 display.setTextSize(1);
 display.setTextColor(WHITE);

 // Start PM sensor
 if (!pmSensor.begin_I2C()) {
  Serial.println("PM sensor missing");
 }

 // Start BME680 sensor
 if (!bme.begin()) {
  Serial.println("BME680 sensor missing");
 }

 delay(1000);
}

void loop() {
 int airValue = analogRead(A0);
 display.clearDisplay();
 display.setCursor(0, 0);
 display.print("Air Value: ");
 display.println(airValue);

 // Show a basic message
 if (airValue < 200) {
  display.println("Clean air");
 } else if (airValue < 400) {
  display.println("Average air");
 } else if (airValue < 600) {
  display.println("Poor air");
 } else {
  display.println("Very poor air");
 }

 // Update display
 display.display();
 delay(1000);
}

This code is a starting point. You can modify the texts and sensor pins as needed. Testing each part separately helps when things do not work.

Frequently Asked Questions

How do I choose the best sensor for my project?

Try to match the sensor type to your needs. For general indoor checks, an MQ135 works well. For dust monitoring, a particle sensor is best.

What is the best Arduino board to use?

Many beginners use Arduino Uno. It is simple and available. You can also use the Nano for compact projects.

How long should I run my sensor before it gives good readings?

Some gas sensors may need a day or two of use to settle. This process warms up the sensor for better results.

See also
Wireless OTA Updates for Arduino using a Raspberry Pi

Can this project work outdoors?

Yes, but you must protect the sensor from rain and dirt. Use a weatherproof case if needed.

Why does my display show flickering?

The display update might be too fast. Try adding a small delay after each screen update.

How do I improve my sensor reading stability?

Add a simple averaging filter in your code. This will smooth out rapid changes in the sensor values.

Conclusion

I hope you enjoyed this build guide. You now have the tools to create an air quality sensor at home. Building projects like these brings joy and useful data. Each step is a chance to learn and experiment. I loved working on mine, and I bet you will too.

I can’t wait to see your project and hear your feedback. Give this guide a try and share your results with our community. Happy building!