Arnov Sharma
Published © MIT

Portable Air Quality Meter

Made a small handy air quality meter based around the MQ135 Air Quality sensor.

BeginnerFull instructions provided1 hour2,989
Portable Air Quality Meter

Things used in this project

Hardware components

Raspberry Pi Pico 2
Raspberry Pi Pico 2
×1
FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
DFRobot FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
×1
PCBWay MQ135 Senso
×1
PCBWay Custom PCB
PCBWay Custom PCB
×1

Software apps and online services

Fusion
Autodesk Fusion
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

cad file

Schematics

WIRING

Code

code

C/C++
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

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

const int analogPin = 35;  // A3
const int digitalPin = 2;  // D2

void setup() {
  Serial.begin(9600);
  pinMode(digitalPin, INPUT);

  // SSD1306 OLED display initialization
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  display.display();
  delay(2000); // Pause for 2 seconds
  display.clearDisplay();
}

void loop() {
  int analogValueRaw = analogRead(analogPin);
  int analogValue = map(analogValueRaw, 0, 4095, 0, 1023);  // Scale the value to match the Pico's range
  int digitalValue = digitalRead(digitalPin);
  String airQuality = getAirQuality(analogValue);

  Serial.print("Analog Value (Raw): ");
  Serial.print(analogValueRaw);
  Serial.print(", Scaled Value: ");
  Serial.print(analogValue);
  Serial.print(", Digital Value: ");
  Serial.println(digitalValue);

  // Display scaled analog value and air quality condition on OLED
  display.clearDisplay();
  display.setTextSize(2);      // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.setCursor(0, 10);    // Start at top-left corner
  display.print("Value: ");
  display.println(analogValue);

  display.setTextSize(1);
  display.setCursor(0, 40);
  display.print("Air Quality: ");
  display.println(airQuality);

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

String getAirQuality(int analogValue) {
  if (analogValue <= 200) {
    return "Excellent";
  } else if (analogValue <= 400) {
    return "Good";
  } else if (analogValue <= 600) {
    return "Moderate";
  } else if (analogValue <= 800) {
    return "Poor";
  } else {
    return "Very Poor";
  }
}

Credits

Arnov Sharma
313 projects • 313 followers
Just your average MAKER

Comments