基于 Arduino 与 DSM501A 传感器的空气质量监测仪
零部件与物料
| 零部件 | 数量 | 备注 |
|---|---|---|
| Arduino Nano R3 | 1 | 主控板 |
| DSM501A 粉尘传感器模块 | 1 | 检测 PM2.5 与 PM10 |
| 16×2 字符型 LCD 显示屏 | 1 | 兼容 HD44780 |
| 40mm 散热风扇套件 | 1 | 改善传感器采样准确性 |
| LED 灯(通用) | 5 | 指示空气质量等级 |
| 220Ω 电阻 | 1 | LCD 背光限流 |
| 10kΩ 单圈电位器 | 1 | 调节 LCD 对比度 |
所需工具
- 电烙铁(通用)
软件与在线服务
- Arduino IDE
项目简介
空气质量监测技术始于 20 世纪 80 年代,早期设备庞大昂贵。如今得益于现代技术,监测设备变得更精准、更快速、更小巧、更实惠。本项目采用 Samyoung DSM501A 粉尘传感器,该传感器价格极低(速卖通仅需几美元),却能同时检测 PM2.5 与 PM10 颗粒物。
传感器引脚说明
DSM501A 引脚布局如下图所示(注意:实际导线颜色可能与图示不同):
电路连接
电路非常简单:
- Vout1 (PM2.5) → Arduino D2
- Vout2 (PM10) → Arduino D3
- Vcc → Arduino 5V
- GND → Arduino GND
- 5 个 LED 分别接入 A1–A5(代码中定义为输出)
- LCD 16×2 显示屏按标准 HD44780 接线
显示与指示逻辑
LCD 显示 PM10 浓度(单位:pcs/0.01cf)及 5 级空气质量状态:
- Clean(优):PM10 < 1000 —— 白灯亮
- Good(良):1000 ≤ PM10 < 10000 —— 绿灯亮
- Acceptable(可接受):10000 ≤ PM10 < 20000 —— 黄灯亮
- Heavy(重度):20000 ≤ PM10 < 50000 —— 红灯亮
- Hazard(危险):PM10 ≥ 50000 —— 蓝灯亮
PM10 与 PM2.5 浓度均可通过串口监视器查看。安装风扇从传感器出风口抽气,能显著改善峰值干扰,提升测量稳定性。整套装置组装在电气安装用塑料盒内。
后续计划
未来计划测试更多低价粉尘传感器,并在后续项目中对比评测结果。
代码
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int pin2 = 3; // PM10
int pin1 = 2; // PM2.5
unsigned long duration1, duration2;
unsigned long starttime;
unsigned long sampletime_ms = 30000; // 采样周期 30 秒
unsigned long lowpulseoccupancy1 = 0;
unsigned long lowpulseoccupancy2 = 0;
float ratio1 = 0, ratio2 = 0;
float concentration1 = 0, concentration2 = 0;
int wLed = A1; // 白 - Clean
int gLed = A2; // 绿 - Good
int yLed = A3; // 黄 - Acceptable
int rLed = A4; // 红 - Heavy
int bLed = A5; // 蓝 - Hazard
void setup() {
Serial.begin(9600);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(wLed, OUTPUT);
pinMode(gLed, OUTPUT);
pinMode(yLed, OUTPUT);
pinMode(rLed, OUTPUT);
pinMode(bLed, OUTPUT);
starttime = millis();
lcd.begin(16, 2);
}
void loop() {
duration1 = pulseIn(pin1, LOW);
duration2 = pulseIn(pin2, LOW);
lowpulseoccupancy1 += duration1;
lowpulseoccupancy2 += duration2;
if ((millis() - starttime) > sampletime_ms) {
ratio1 = lowpulseoccupancy1 / (sampletime_ms * 10.0);
concentration1 = 1.1 * pow(ratio1, 3) - 3.8 * pow(ratio1, 2) + 520 * ratio1 + 0.62;
ratio2 = lowpulseoccupancy2 / (sampletime_ms * 10.0);
concentration2 = 1.1 * pow(ratio2, 3) - 3.8 * pow(ratio2, 2) + 520 * ratio2 + 0.62;
lcd.setCursor(0, 0);
lcd.print("PM10 ");
lcd.setCursor(6, 0);
lcd.print(concentration1, 3);
Serial.print("concentration1 = ");
Serial.print(concentration1);
Serial.print(" pcs/0.01cf - ");
Serial.print("concentration2 = ");
Serial.print(concentration2);
Serial.println(" pcs/0.01cf - ");
// 清空第二行
lcd.setCursor(0, 1);
for (int i = 0; i < 16; ++i) lcd.write(' ');
// 根据 PM10 浓度显示等级并点亮对应 LED
if (concentration1 < 1000) {
lcd.setCursor(4, 1); lcd.print("CLEAN");
setLED(wLed);
} else if (concentration1 < 10000) {
lcd.setCursor(4, 1); lcd.print("GOOD");
setLED(gLed);
} else if (concentration1 < 20000) {
lcd.setCursor(3, 1); lcd.print("ACCEPTABLE");
setLED(yLed);
} else if (concentration1 < 50000) {
lcd.setCursor(4, 1); lcd.print("HEAVY");
setLED(rLed);
} else {
lcd.setCursor(4, 1); lcd.print("HAZARD");
setLED(bLed);
}
lowpulseoccupancy1 = 0;
lowpulseoccupancy2 = 0;
starttime = millis();
}
}
void setLED(int activePin) {
digitalWrite(wLed, activePin == wLed);
digitalWrite(gLed, activePin == gLed);
digitalWrite(yLed, activePin == yLed);
digitalWrite(rLed, activePin == rLed);
digitalWrite(bLed, activePin == bLed);
}
原理图
制造工艺
- 使用 OpenSensors 监测空气质量:Arduino 与 Python 实战指南
- 基于 Helium 网络的太阳能供电空气质量监测站:设计与部署全指南
- Arduino Nano 与 MPU-6050 构建实时陀螺仪游戏
- 多位置温度传感器系统,助力智能家居集成
- K30 CO₂ 传感器:室内空气质量实时监测
- 自制简易红外避障传感器:IR LED + 光电二极管 + Arduino
- DFRobot 电容指纹传感器 (ID809) 接入 Arduino/ESP8266 完整教程
- 基于 Arduino、Yaler 与 IFTTT 构建 Web 化 IoT 仪表盘
- Arduino 简易排斥式磁悬浮:电路与 DIY 指南
- 高性能 Arduino 气象气球数据记录器
- 高精度空气质量监测仪:Sharp GP2Y1010AU0F 粉尘传感器 + Arduino Nano
- 先进碳基 NO₂ 传感器提升室内空气质量监测水平