极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12642|回复: 2

求帮忙编写后面的程序

[复制链接]
发表于 2017-3-23 17:48:26 | 显示全部楼层 |阅读模式
电路图如图所示,当温度<15摄氏度时,加热器导通,开始加热。当温度>25摄氏度时,加热器断开,停止加热.
以下是湿温度传感器dht11测温度的程序,传送在arduino串口2上,求大神帮忙编写后面的程序,把2脚的温度数据传给4脚实现温控,谢谢!

  1. double Fahrenheit(double celsius)
  2. {
  3.         return 1.8 * celsius + 32;
  4. }    //摄氏温度度转化为华氏温度

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

  9. // 露点(点在此温度时,空气饱和并产生露珠)
  10. // 参考: [url]http://wahiduddin.net/calc/density_algorithms.htm[/url]
  11. double dewPoint(double celsius, double humidity)
  12. {
  13.         double A0= 373.15/(273.15 + celsius);
  14.         double SUM = -7.90298 * (A0-1);
  15.         SUM += 5.02808 * log10(A0);
  16.         SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
  17.         SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
  18.         SUM += log10(1013.246);
  19.         double VP = pow(10, SUM-3) * humidity;
  20.         double T = log(VP/0.61078);   // temp var
  21.         return (241.88 * T) / (17.558-T);
  22. }

  23. // 快速计算露点,速度是5倍dewPoint()
  24. // 参考: [url]http://en.wikipedia.org/wiki/Dew_point[/url]
  25. double dewPointFast(double celsius, double humidity)
  26. {
  27.         double a = 17.271;
  28.         double b = 237.7;
  29.         double temp = (a * celsius) / (b + celsius) + log(humidity/100);
  30.         double Td = (b * temp) / (a - temp);
  31.         return Td;
  32. }

  33. #include <dht11.h>

  34. dht11 DHT11;

  35. #define DHT11PIN 2

  36. void setup()
  37. {
  38.   Serial.begin(9600);
  39.   Serial.println("DHT11 TEST PROGRAM ");
  40.   Serial.print("LIBRARY VERSION: ");
  41.   Serial.println(DHT11LIB_VERSION);
  42.   Serial.println();
  43. }

  44. void loop()
  45. {
  46.   Serial.println("\n");

  47.   int chk = DHT11.read(DHT11PIN);

  48.   Serial.print("Read sensor: ");
  49.   switch (chk)
  50.   {
  51.     case DHTLIB_OK:
  52.                 Serial.println("OK");
  53.                 break;
  54.     case DHTLIB_ERROR_CHECKSUM:
  55.                 Serial.println("Checksum error");
  56.                 break;
  57.     case DHTLIB_ERROR_TIMEOUT:
  58.                 Serial.println("Time out error");
  59.                 break;
  60.     default:
  61.                 Serial.println("Unknown error");
  62.                 break;
  63.   }

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

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

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

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

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

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

  76.   delay(2000);
  77. }
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2017-3-24 12:01:29 | 显示全部楼层
联系我QQ18476403
回复 支持 反对

使用道具 举报

发表于 2017-3-24 12:02:07 | 显示全部楼层
这个很简单啊
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 13:20 , Processed in 0.055840 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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