Arduino Air Quality Monitor for Beginners: Complete Guide

Arduino Air Quality Monitor for Beginners: Complete Guide

Objective: Build an Arduino Air Quality Monitor

This guide explains how to create an Arduino air quality monitor that measures temperature, humidity, and gas levels. This project is designed for beginners, using an OLED display, DHT11 sensor, and gas sensor.

Project Goals for Arduino Air Quality Monitor

  • Understand how to use sensors with Arduino for air quality monitoring.
  • Display sensor readings on an OLED screen.
  • Write and upload code to the Arduino for monitoring temperature, humidity, and gas levels.

Required Components for Arduino Air Quality Monitor

Below is a list of components needed to build this project, including descriptions and purchase links:

ComponentDescriptionLink
Arduino UnoMain microcontroller for air quality monitorAmazon Link
DHT11 SensorMeasures temperature and humidityAmazon Link
Gas Sensor (MQ Series)Detects gas levels for air qualityCheck Availability
OLED Display (128x64)Displays sensor readingsCheck Availability
Jumper WiresConnects components to ArduinoAmazon Link
BreadboardFor prototyping connectionsAmazon Link

Sensor Basics for Arduino Air Quality Monitor

DHT11 Sensor

The DHT11 sensor measures temperature and humidity. It has three pins: VCC, GND, and Data. It operates at 3.3V to 5V.

DHT11 Pinout

PinDescription
1 (VCC)Connects to 3.3V or 5V on Arduino
2 (Data)Connects to digital pin on Arduino
3 (NC)Not connected
4 (GND)Connects to GND on Arduino

Gas Sensor (MQ Series)

The gas sensor measures air quality by detecting gas levels. It outputs an analog signal that varies with gas concentration. It has four pins: VCC, GND, AOUT, and DOUT.

Gas Sensor Pinout

PinDescription
1 (VCC)Connects to 5V on Arduino
2 (GND)Connects to GND on Arduino
3 (AOUT)Analog output to Arduino
4 (DOUT)Digital output, not used in this project

Circuit Connection for Arduino Air Quality Monitor

ComponentArduino PinDetails
DHT11 SensorPin 2Reads temperature and humidity
Gas SensorPin A0Measures gas concentration
OLED DisplaySCL, SDA (I2C)Displays readings from sensors

How This Circuit Works

The Arduino reads data from the DHT11 sensor and gas sensor. It then displays the readings on an OLED display, showing temperature, humidity, and air quality levels. The OLED display is connected to the Arduino via I2C communication, while the sensors use analog and digital pins for data transmission.

Safety Tips for Arduino Air Quality Monitor

  • Ensure all connections are secure before powering the Arduino.
  • Handle sensors carefully to avoid damage.
  • Use a regulated power supply for the Arduino.

Arduino Code for Air Quality Monitor


#include 
#include 
#include 
#include 
#include 

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define sensor A0
#define DHT11PIN 2

int gasLevel = 0;
String quality = "";
dht DHT;

void sendSensor() {
  int readData = DHT.read11(DHT11PIN);
  float h = DHT.humidity;
  float t = DHT.temperature;

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setFont();
  display.setCursor(0, 43);
  display.println("Temp  :");
  display.setCursor(80, 43);
  display.println(t);
  display.setCursor(114, 43);
  display.println("C");
  display.setCursor(0, 56);
  display.println("RH    :");
  display.setCursor(80, 56);
  display.println(h);
  display.setCursor(114, 56);
  display.println("%");
}

void air_sensor() {
  gasLevel = analogRead(sensor);

  if (gasLevel < 151) {
    quality = "GOOD!";
  } else if (gasLevel > 151 && gasLevel < 200) {
    quality = "Poor!";
  } else if (gasLevel > 200 && gasLevel < 300) {
    quality = "Very bad!";
  } else if (gasLevel > 300 && gasLevel < 500) {
    quality = "Toxic!";
  } else {
    quality = "Toxic";
  }

  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(1, 5);
  display.setFont();
  display.println("Air Quality:");
  display.setTextSize(1);
  display.setCursor(5, 23);
  display.println(gasLevel);
  display.setCursor(20, 23);
  display.println(quality);
}

void setup() {
  Serial.begin(9600);
  pinMode(sensor, INPUT);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) {
    Serial.println(F("SSD1306 allocation failed"));
  }
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(2);
  display.setCursor(50, 0);
  display.println("Air");
  display.setTextSize(1);
  display.setCursor(23, 20);
  display.println("Quality monitor");
  display.display();
  delay(1200);
  display.clearDisplay();
  display.setTextSize(1.5);
  display.setCursor(20, 20);
  display.println("BY Circuit");
  display.setCursor(20, 40);
  display.println("Digest");
  display.display();
  delay(1000);
  display.clearDisplay();
}

void loop() {
  display.clearDisplay();
  air_sensor();
  sendSensor();
  display.display();
}

Steps to Upload Arduino Code

  • Connect the Arduino to your computer using a USB cable.
  • Open the Arduino IDE, paste the code above, and select the correct board and port.
  • Upload the code to the Arduino.

Check Output for Arduino Air Quality Monitor

  • Temperature, humidity, and gas levels should display on the OLED screen.
  • Gas levels will show a text-based quality indicator (e.g., GOOD, Poor, Toxic).

Troubleshooting Tips

  • If the display is blank, check the I2C connection and address settings.
  • Ensure that the DHT11 sensor is connected correctly.
  • Re-upload the code if issues persist.

Suggestions for Beginners

Start with basic Arduino projects like LED blinking and sensor readings before advancing to complex projects like air quality monitoring. This will help build confidence in coding and hardware setup.

Recommended Book for Learning Arduino

Arduino Programming for Absolute Beginners - This book offers easy-to-understand lessons for learning Arduino from scratch.

Explore more tutorials and projects at MechatronicsLab.net, where you’ll find resources for Arduino, ESP8266, ESP32, and Raspberry Pi.

No comments

Theme images by Dizzo. Powered by Blogger.