标题: 上传一个显示温湿度的arduino代码 [打印本页]

作者: 醉乡民谣    时间: 2018-4-15 11:54
标题: 上传一个显示温湿度的arduino代码
double Fahrenheit(double celsius)
{
       return 1.8 * celsius + 32;
}   //摄氏温度度转化为华氏温度

double Kelvin(double celsius)
{
       return celsius + 273.15;
}    //摄氏温度转化为开氏温度

// 露点(点在此温度时,空气饱和并产生露珠)
// 参考:wahiduddin点net/calc/density_algorithms.htm
double dewPoint(double celsius, doublehumidity)   //humidity是湿度,celsius是摄氏温度
{
       double A0= 373.15/(273.15 + celsius);
       double SUM = -7.90298 * (A0-1);
       SUM += 5.02808 * log10(A0);
       SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
       SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
       SUM += log10(1013.246);
       double VP = pow(10, SUM-3) * humidity;
       double T = log(VP/0.61078);   //temp var
       return (241.88 * T) / (17.558-T);
}

// 快速计算露点,速度是5dewPoint()(上面函数的结果)
double dewPointFast(double celsius, doublehumidity)
{
       double a = 17.271;
       double b = 237.7;
       double temp = (a * celsius) / (b + celsius) + log(humidity/100);
       double Td = (b * temp) / (a - temp);
       return Td;
}

#include <dht11.h>

dht11 DHT11;

#define DHT11PIN 2

void setup()  //设置一些参数
{
Serial.begin(9600);  
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();
}

void loop()
{
Serial.println("\n"); //换行

  intchk = DHT11.read(DHT11PIN);

Serial.print("Read sensor: "); //读取传感器
switch (chk)
  {
   case DHTLIB_OK:
                Serial.println("OK");
                break;
   case DHTLIB_ERROR_CHECKSUM:
                Serial.println("Checksumerror");
                break;
   case DHTLIB_ERROR_TIMEOUT:
                Serial.println("Time outerror");
                break;
   default:
                Serial.println("Unknownerror");
                break;
  }

Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);

Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, 2);

Serial.print("Temperature (oF): ");
Serial.println(Fahrenheit(DHT11.temperature), 2);

Serial.print("Temperature (K): ");
Serial.println(Kelvin(DHT11.temperature), 2);

Serial.print("Dew Point (oC): ");
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

Serial.print("Dew PointFast (oC): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

delay(2000);
}

作者: 15616200407    时间: 2019-12-5 18:33
我运行了一下   错误是说没有dht11.h 这个文件 怎么解决 刚接触arduino什么都不懂...求教





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1