กลับหน้าหลัก
views
How to Use Arduino with PMS7003 G7 Sensor to Measure PM2.5 and Display on OLED
Last updated on

How to Use Arduino with PMS7003 G7 Sensor to Measure PM2.5 and Display on OLED


How to Use Arduino with PMS7003 G7 Sensor to Measure PM2.5 and Display on OLED

This project is a solid foundation for anyone wanting to build a simple air quality monitoring device. The PMS7003 G7 sensor provides accurate PM2.5 readings, and the small OLED display shows the results in real-time.

Required Components

  • Arduino UNO R3 with USB cable
  • PMS7003 G7 Dust Sensor Module
  • 0.96 inch 128x64 I2C OLED Display
  • MB-102 Breadboard 830 points
  • Jumper wires: Male-Male, Male-Female, Female-Female (at least 40 each)
  • 9V 2A Power Adapter for supplementary power
Circuit diagram showing Arduino UNO connected to PMS7003 and OLED display on a breadboard

Wiring Instructions

Connect PMS7003 G7 to Arduino UNO

Arduino UNOPMS7003 G7
5VVCC
GNDGND
Pin 2 (TX)RX
Pin 3 (RX)TX

Note: Arduino TX (Pin 2) connects to sensor RX, and Arduino RX (Pin 3) connects to sensor TX.

Connect OLED to Arduino UNO

Arduino UNOI2C OLED
5VVCC
GNDGND
A4SDA
A5SCL
Close-up of jumper wire connections at SDA/SCL pins of Arduino going to OLED display

Important: Common Ground

All GND connections must be shared. Arduino, PMS7003, and OLED must share a common ground. Without this, signal communication will fail.

Library Installation

  1. Download the library from the link in the original article
  2. Extract the RAR file (requires WinRAR or WinZip installed)
  3. Copy the library folder to Documents/Arduino/libraries/
Screenshot of Arduino IDE libraries folder showing PMS7003 and OLED libraries installed

Arduino Code for Reading PM2.5

#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// Define pins for PMS7003 communication
SoftwareSerial pmsSerial(2, 3); // RX, TX

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

// Buffer for sensor data
unsigned char pmsBuffer[32];

void setup() {
  Serial.begin(9600);
  pmsSerial.begin(9600);
  
  // Initialize OLED display
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("OLED allocation failed"));
    for(;;);
  }
  display.clearDisplay();
  display.setTextColor(SSD1306_WHITE);
}

void loop() {
  if (readPMS()) {
    int pm25 = (pmsBuffer[12] << 8) | pmsBuffer[13];
    
    // Display on Serial Monitor
    Serial.print("PM2.5 = ");
    Serial.print(pm25);
    Serial.println(" ug/m3");
    
    // Display on OLED screen
    display.clearDisplay();
    display.setTextSize(2);
    display.setCursor(10, 10);
    display.print("PM2.5");
    display.setTextSize(3);
    display.setCursor(10, 35);
    display.print(pm25);
    display.setTextSize(1);
    display.setCursor(85, 45);
    display.print("ug/m3");
    display.display();
  }
  delay(1000);
}

bool readPMS() {
  if (pmsSerial.available() >= 32) {
    if (pmsSerial.read() == 0x42 && pmsSerial.read() == 0x4D) {
      for (int i = 0; i < 30; i++) {
        pmsBuffer[i] = pmsSerial.read();
      }
      return true;
    }
  }
  return false;
}

Adjustments needed: If PM2.5 values don’t appear, verify that Adafruit_SSD1306 and Adafruit_GFX libraries are properly installed. Check via Sketch > Include Library > Manage Libraries.

How to Upload and View Results

  1. Open Arduino IDE and paste the code above
  2. Go to Tools > Port and select the connected port
  3. Go to Tools > Board and select Arduino UNO
  4. Click Upload (right arrow icon)
  5. When “Done Uploading” appears, go to Tools > Serial Monitor
  6. Change Baud Rate to 9600
  7. You’ll see PM2.5 values displayed on both Serial Monitor and OLED screen

Testing the Sensor with Smoke

An easy way to verify the circuit works correctly:

  1. Open Serial Monitor
  2. Hold a soldering iron near the PMS7003 air intake
  3. PM2.5 values will spike immediately when smoke is present
  4. Wait for values to gradually decrease as smoke dissipates

[image: Graph showing PM2.5 values changing when smoke from soldering iron is introduced]

Reference Video

Summary

This project uses SoftwareSerial on pins 2 and 3 to communicate with PMS7003, which is separate from Hardware Serial (pins 0,1) used for uploading and debugging. This makes it convenient for development. If you want to expand this project to send data to the cloud or add alerts, the foundation is ready for those extensions.

อยากทำโปรเจคแบบนี้?

รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน

If you need Arduino project service or urgent IoT development, see full service details on the services page

จ้างทำโปรเจคเลย

Project estimate

Want something like this? Open the estimate page.

The long form is now on a separate estimate page, so this article stays clean.

ความคิดเห็น

รีวิวจากคนใช้งานจริง

รีวิวจากลูกค้าและคนที่เคยใช้งาน

ถ้าเคยสั่งงาน เคยอ่านหน้านี้แล้วได้ประโยชน์ หรือมีข้อเสนอแนะ ฝากรีวิวไว้ได้เลย

กำลังโหลดรีวิว...