Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
The PMS5003 is a particulate matter sensor that can measure the concentration of particles in the air, making it an essential component for air quality monitoring systems. This sensor can detect PM1.0, PM2.5, and PM10 particles, which are critical for assessing air pollution levels. Integrating the PMS5003 with an Arduino allows hobbyists and engineers to create custom air quality monitoring solutions. This article will guide you through the process of interfacing the PMS5003 with an Arduino, providing code examples and a detailed list of components.
Project: In this project, we will create an air quality monitoring system using the PMS5003 sensor and an Arduino. The objective is to measure the concentration of particulate matter in the air and display the readings on an LCD screen. This project will help you understand how to read data from the PMS5003 sensor and display it in a user-friendly format.
Components List:
Examples:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with the I2C address 0x27
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int PMS5003_RX_PIN = 2; // PMS5003 RX pin connected to Arduino pin 2
const int PMS5003_TX_PIN = 3; // PMS5003 TX pin connected to Arduino pin 3
// Structure to store PMS5003 data
struct PMS5003Data {
uint16_t pm1_0;
uint16_t pm2_5;
uint16_t pm10;
};
PMS5003Data pmsData;
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 baud rate
lcd.begin(); // Initialize the LCD
lcd.backlight(); // Turn on the LCD backlight
lcd.setCursor(0, 0);
lcd.print("PMS5003 Sensor");
// Initialize software serial for PMS5003 communication
SoftwareSerial pmsSerial(PMS5003_RX_PIN, PMS5003_TX_PIN);
pmsSerial.begin(9600);
}
void loop() {
if (readPMS5003Data()) {
displayData();
}
delay(1000); // Wait for 1 second before reading again
}
bool readPMS5003Data() {
// Check if data is available from the PMS5003
if (pmsSerial.available()) {
// Read the data and store it in the pmsData structure
pmsData.pm1_0 = read16();
pmsData.pm2_5 = read16();
pmsData.pm10 = read16();
return true;
}
return false;
}
uint16_t read16() {
// Read two bytes from the PMS5003 and combine them into a 16-bit value
uint16_t value = pmsSerial.read();
value <<= 8;
value |= pmsSerial.read();
return value;
}
void displayData() {
// Display the PMS5003 data on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("PM1.0: ");
lcd.print(pmsData.pm1_0);
lcd.setCursor(0, 1);
lcd.print("PM2.5: ");
lcd.print(pmsData.pm2_5);
lcd.setCursor(0, 2);
lcd.print("PM10: ");
lcd.print(pmsData.pm10);
}
In this example, we use the SoftwareSerial
library to communicate with the PMS5003 sensor. The sensor's RX and TX pins are connected to Arduino pins 2 and 3, respectively. The LiquidCrystal_I2C
library is used to control the LCD. The readPMS5003Data
function reads data from the sensor and stores it in a structure, while the displayData
function displays the readings on the LCD.