基于DSM501A的空气质量指数(AQI)计算装置

基于DSM501A的空气质量指数(AQI)计算装置
作者:Espruino中文社区 lawrencedon

使用的模块:DSM501A
接线方法:
DSM501A     Espruino
pin1 ——– 不用接
pin2 ——– A1
pin3 ——– Bat
pin4 ——– A0
pin5 ——– GND
这里用A0,A1其实是有点不妥的,因为这两个针脚是3.3v tolerant,而DSM501的输出高电平可以达到4.7v。
可以使用5v tolerant的针脚来做该实验。在下面链接里的PINOUT图中没有标注3.3v的针脚都是5v tolerant的。
http://www.espruino.com/ReferenceESPRUINOBOARD
计算颗粒浓度和AQI的公式来自https://github.com/alexjx/AqiMon
//基于DSM501A的空气质量指数(AQI)计算装置
//使用的模块:DSM501A
//接线方法:
// DSM501A       Espruino
// pin1 -------- 不用接
// pin2 -------- A1
// pin3 -------- Bat
// pin4 -------- A0
// pin5 -------- GND
//计算颗粒浓度和AQI的公式来自https://github.com/alexjx/AqiMon
//作者:Espruino中文社区 lawrencedon

var pm10 = 0;
var pm25 = 0;
var pm10_weight = 0;
var pm25_weight = 0;
var aqi = 0;
var P25Weight = 0;
setWatch(function(e){
  var lowtime0=(e.time-e.lastTime)*1000;
  if(lowtime0>=10 && lowtime0<=90)
  {
    //console.log("pm10: " + lowtime0);
    pm10+=lowtime0;
  }
},A1,{repeat:true,edge:"rising"});
setWatch(function(e){
  var lowtime1=(e.time-e.lastTime)*1000;
  if(lowtime1>=10 && lowtime1<=90)
  {
    //console.log("pm25: " + lowtime1);
    pm25+=lowtime1;
  }
},A0,{repeat:true,edge:"rising"});
setInterval(function(e){
  pm10_weight = 0.30473 * Math.pow((pm10/30000)*100, 3) - 2.63943 * Math.pow((pm10/30000)*100, 2) + 102.60291 * (pm10/30000)*100 - 3.49616;

  pm25_weight = 0.30473 * Math.pow((pm25/30000)*100, 3) - 2.63943 * Math.pow((pm25/30000)*100, 2) + 102.60291 * (pm25/30000)*100 - 3.49616;

    P25Weight = pm10_weight - pm25_weight;

   if (P25Weight>= 0 && P25Weight <= 15.4) {
  aqi = 0 +(50.0 / 15.5 * P25Weight);
} else if (P25Weight > 15.5 && P25Weight <= 40.5) {
  aqi = 50 + (50.0 / 25.0 * (P25Weight - 15.5));
} else if (P25Weight > 40.5 && P25Weight <= 65.5) {
  aqi = 100 + (50.0 / 25.0 * (P25Weight - 40.5));
} else if (P25Weight > 65.5 && P25Weight <= 150.5) {
  aqi = 150 + (50.0 / 85.0 * (P25Weight - 65.5));
} else if (P25Weight > 150.5 && P25Weight <= 250.5) {
  aqi = 200 + (100.0 / 100.0 * (P25Weight - 150.5));
} else if (P25Weight > 250.5 && P25Weight <= 350.5) {
  aqi = 300 + (100.0 / 100.0 * (P25Weight - 250.5));
} else if (P25Weight > 350.5 && P25Weight <= 500.0) {
  aqi = 400 + (100.0 / 150.0 * (P25Weight - 350.5));
} else if (P25Weight > 500.0) {
  aqi = 500 + (500.0 / 500.0 * (P25Weight - 500.0));
} else {
  aqi = 0;
}
  console.log("__________AQI:" + aqi + "__________");
    pm10=0;pm25=0;
},30000);

发表回复