存个pm2.5传感器的资料
技术规格工作电压:4.95 ~ 5.05V
最大工作电流 : 120mA
测量范围: 0.3~1.0、1.0~2.5、2.5~10微米(um)
量程:0~500 ug/m3
待机电流: ≤200 微安(uA)
响应时间: ≤10 s
工作温度范围 : -20 ~ 50摄氏度
工作湿度范围 : 0~99% RH
最大尺寸: 65×42×23(mm)
平均无故障时间 : >=5年
主要特性:
响应迅速
标准串口输字输出
二阶曲线多点校准
最小分辨粒径0.3微米
供电电源质量要求:
1、 纹波小于100mV。
2、 电源电压稳定度:4.95~5.05V。
3、 电源功率:大于1W (电流大于200mA)。
4、 上下电电压冲击小于系统电源电压的50%。
串口波特率:9600; 校验位:无; 停止位:1位; 数据包长度固定为32字节。
//******************************
//*Abstract: Read value of PM1,PM2.5 and PM10 of air quality
//*Product Link: https://www.dfrobot.com.cn/goods-1113.html
//
//*Version:V3.1
//*Author:Zuyang @ HUST
//*Modified by Cain for Arduino Hardware Serial port compatibility
//*Date:March.25.2016
//******************************
#include <Arduino.h>
#define LENG 31 //0x42 + 31 bytes equal to 32 bytes
unsigned char buf;
int PM01Value=0; //define PM1.0 value of the air detector module
int PM2_5Value=0; //define PM2.5 value of the air detector module
int PM10Value=0; //define PM10 value of the air detector module
void setup()
{
Serial.begin(9600); //使用串口0
Serial.setTimeout(1500); //设置超时时间为1500毫秒(大于传感器传送数据周期1秒)
}
void loop()
{
if(Serial.find(0x42)){ //检测到0x42时,开始读取
Serial.readBytes(buf,LENG);
if(buf == 0x4d){
if(checkValue(buf,LENG)){
PM01Value=transmitPM01(buf); //count PM1.0 value of the air detector module
PM2_5Value=transmitPM2_5(buf);//count PM2.5 value of the air detector module
PM10Value=transmitPM10(buf); //count PM10 value of the air detector module
}
}
}
static unsigned long OledTimer=millis();
if (millis() - OledTimer >=1000)
{
OledTimer=millis();
Serial.print("PM1.0: ");
Serial.print(PM01Value);
Serial.println("ug/m3");
Serial.print("PM2.5: ");
Serial.print(PM2_5Value);
Serial.println("ug/m3");
Serial.print("PM1 0: ");
Serial.print(PM10Value);
Serial.println("ug/m3");
Serial.println();
}
}
char checkValue(unsigned char *thebuf, char leng)
{
char receiveflag=0;
int receiveSum=0;
for(int i=0; i<(leng-2); i++){
receiveSum=receiveSum+thebuf;
}
receiveSum=receiveSum + 0x42;
if(receiveSum == ((thebuf<<8)+thebuf))//check the serial data
{
receiveSum = 0;
receiveflag = 1;
}
return receiveflag;
}
int transmitPM01(unsigned char *thebuf)
{
int PM01Val;
PM01Val=((thebuf<<8) + thebuf); //count PM1.0 value of the air detector module
return PM01Val;
}
//transmit PM Value to PC
int transmitPM2_5(unsigned char *thebuf)
{
int PM2_5Val;
PM2_5Val=((thebuf<<8) + thebuf);//count PM2.5 value of the air detector module
return PM2_5Val;
}
//transmit PM Value to PC
int transmitPM10(unsigned char *thebuf)
{
int PM10Val;
PM10Val=((thebuf<<8) + thebuf); //count PM10 value of the air detector module
return PM10Val;
}
页:
[1]