DN7C3CA001是夏普新发布的PM2.5传感器,次传感器能够切割滤除粒径大于2.5微米的粒子通过光传感器元件,从而真正实现对粒径小于等于2.5微米的颗粒物的监测,具体介绍请参考。
图1. 粒径切割原理图
拿到手的型号是DN7C3CA002改进版。根据传感器手册中的接线方法可以发现,除了物理排线线序相反以及需要接风扇的供电电路外,其它引脚接线方法与GP2Y1010AU0F相同。
图2. 接线原理图
DN7C3CA002与GP2Y1010AU0F的脉冲采样参数和采样时长都是一样的,猜测两者采用的是类似的光学器件。
图3. 采样脉冲
图4. 采样时间
传感器采用电压输出方式,手册中给出了输出电压与PM2.5质量浓度之间的关系:
图5. 输出电压与质量浓度关系
其中Vo是输出电压(电压单位都是mV),Vs是基准电压,Vs基准电压的获取有两种方式,一种方式是从传感器的序列号中读出,由于我拿到的这颗传感器无序列号,所以只有采用第二种方式,通过不接风扇电源将传感器垂直放置几分钟后读出的输出电压。
同时传感器需要对Vs基准电压进行温度补偿,修正参考值同样除了可以从传感器序列号中读出外也可以通过测量得到。
图6. 温度修正曲线
在-10~40℃约6mV/℃,40~60℃约1.5mV/℃。测量拿到的这颗传感器的Vs基准电压非常低,远远达不到图6中两条曲线的电压值,不知道是电路问题还是传感器自身的问题。
为了能够根据实时温度修正Vs基准电压,使用sht10获取温度和湿度数据。同时使用lcd1602作为显示输出,基于Arduino UNO组成主控电路。
图7. 装置运行
图8. 内部结构
程序代码在arduino IDE 0023上通过:
pmkit.rar
(1.47 KB, 下载次数: 9)
,需要sht1x库的支持。
- #include
- #include
- #define LCD_led 9
- #define clockPin A0
- #define dataPin A1
- #define DUSTOUTpin A2 //read dust value from this pin
- #define DUSTLEDpin A3 //control dust led through this pin
- LiquidCrystal lcd(2, 4, 5, 6, 7, 8);
- SHT1x sht1x(dataPin, clockPin);
- const int delayTime=280;
- const int delayTime2=40;
- const float offTime=9680;
- float temp_c=0.0;
- float humidity=0.0;
- double dustVal=0.0;
- double voteChange = 5000.0 /1024.0; //mV
- #define FREEPMVALUE 3
- #define FREEPMTEMP 31.0
- #define BASERATIO40 6 //mV
- #define BASERATIO60 1.5 //mV
- #define PMFIX 0 // 25 ug/m3
- #define PMRATIO 0.6
- #define DOBASEFIX false
- #define NSAMPLES 100
- uint8_t sampleCount = 0;
- int sampleSumPm = 0;
- int dustLevel=0;
- //moving average filter
- #define NULLVALUE -1.0
- #define MOVINGAVERAGECOUT 10
- double pm2_5[MOVINGAVERAGECOUT];
- uint8_t arrNewPoint = 0;
- static void initFilterArray()
- {
- for(int i=0;i<movingaveragecout;i++)
- {
- pm2_5[i]=NULLVALUE;
- }
- }
- int readPM(){
- // ledPower is any digital pin on the arduino connected to Pin 3 on the sensor
- digitalWrite(DUSTLEDpin,LOW);// power on the LED
- delayMicroseconds(delayTime);
- int Val = analogRead(DUSTOUTpin); // read the dust value via pin 5 on the sensor
- delayMicroseconds(delayTime2);
- digitalWrite(DUSTLEDpin,HIGH); // turn the LED off
- delayMicroseconds(offTime);
- return Val;
- }
- void setup() {
- pinMode(LCD_led, OUTPUT);
- digitalWrite(LCD_led, HIGH);
- pinMode(DUSTLEDpin,OUTPUT);
- digitalWrite(DUSTLEDpin,HIGH);// turn the LED off
- initFilterArray();
- lcd.begin(16, 2);
- lcd.print("System Warming!");
- //Serial.begin(9600);
- delay(5000);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("PM2.5:");
- lcd.setCursor(11, 0);
- lcd.print("ug/m3");
- lcd.setCursor(5, 1);
- lcd.print("C");
- lcd.setCursor(15, 1);
- lcd.print("%");
- }
- void loop() {
- dustLevel =readPM();
- sampleCount++;
- sampleSumPm = sampleSumPm + dustLevel;
- if(sampleCount==NSAMPLES)
- {
- showTempHumiData();
- getPMdata(sampleSumPm / sampleCount);
- sampleCount=0;
- sampleSumPm=0;
- }
- }
- void getPMdata(int avgPm) {
- double dustVolt = avgPm * voteChange; //mV
- if(DOBASEFIX)
- {
- double baseVot = FREEPMVALUE * voteChange; //mV
- double baseChg = 0.0;
- if(temp_c <= 40.0 && temp_c>= -10.0)
- {
- baseChg=BASERATIO40;
- }
- else if(temp_c > 40.0 && temp_c <= 60.0)
- {
- baseChg=BASERATIO60;
- }
- baseVot=baseVot + baseChg*(temp_c - FREEPMTEMP);
- dustVolt=dustVolt-baseVot;
- if(dustVolt<0)
- {
- dustVolt=0;
- }
- }
- dustVal = dustVolt * PMRATIO;
- dustVal = dustVal + PMFIX;
- // moving average
- getMovingAverage(pm2_5,&dustVal);
- lcd.setCursor(6, 0);
- lcd.print(" ");
- lcd.setCursor(6, 0);
- lcd.print(dustVal,0);
- }
- void showTempHumiData() {
- temp_c = sht1x.readTemperatureC();
- humidity = sht1x.readHumidity();
- lcd.setCursor(0, 1);
- lcd.print(" ");
- lcd.setCursor(0, 1);
- lcd.print(temp_c,1);
- lcd.setCursor(12, 1);
- lcd.print(" ");
- lcd.setCursor(12, 1);
- lcd.print(humidity,0);
- }
- static float getAverage(double vals[])
- {
- double sum=0.0;
- uint8_t cout=0;
- for(int i=0;i<movingaveragecout;i++)
- {
- if(vals[i] != NULLVALUE)
- {
- sum=sum+vals[i];
- cout++;
- }
- }
- if(cout>0)
- {
- return sum/cout;
- }
- else
- {
- return 0.0;
- }
- }
- static void getMovingAverage(double pms[],double* pm)
- {
- pms[arrNewPoint] = *pm;
- arrNewPoint++;
- if(arrNewPoint>=MOVINGAVERAGECOUT)
- {
- arrNewPoint=0;
- }
- *pm=getAverage(pms);
- }
复制代码
仪器未经标定,应用还需谨慎!
</movingaveragecout;i++)
</movingaveragecout;i++)
|