为什我的DSM501A大部分时间显示0.62~?-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 3853|回复: 0

[过期] 为什我的DSM501A大部分时间显示0.62~?

[复制链接]
发表于 2014-4-11 22:25 | 显示全部楼层 |阅读模式
是不是时间上有问题~


[mw_shl_code=cpp,true]
#include <LiquidCrystal.h>
#include <dht.h>  

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
dht DHT;
#define DHT11_PIN 6
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
void setup()
{
  Serial.begin(9600);  
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  pinMode(8,INPUT);
  starttime = millis();
}

void loop() {
  int chk = DHT.read11(DHT11_PIN);
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 0);
  lcd.print("T:");
  lcd.print( DHT.temperature,1 );
  lcd.print ("C");
  lcd.setCursor(9, 0);
  lcd.print("H:");
  lcd.print(DHT.humidity,1);
  lcd.print("%");
  
  //
  lcd.setCursor(0, 1);
  lcd.print("PM2.5:");
  lcd.setCursor(13, 1);
  lcd.print ("pcs");
  duration = pulseIn(pin, LOW);
  lowpulseoccupancy = lowpulseoccupancy+duration;

  if ((millis()-starttime) > sampletime_ms)
  {
    ratio = lowpulseoccupancy/(sampletime_ms*10.0);  // Integer percentage 0=>100
    concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
    //Serial.print(lowpulseoccupancy);
    //Serial.print(",");
   // Serial.print(ratio);
  // Serial.print(",");
    lcd.setCursor(6, 1);
    lcd.print(concentration);
    Serial.print("h1:");  
    Serial.print(DHT.humidity,1);  
    Serial.print(";");
    Serial.print("t1:");
    Serial.print(DHT.temperature,1);
    Serial.print(";");   
    Serial.print("c1:");  
    Serial.print(concentration);  
    Serial.println(";");
    lowpulseoccupancy = 0;
    starttime = millis();
  }
delay(1000);
}
[/mw_shl_code]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-5 03:35 , Processed in 0.099050 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表