Advertisement
Guest User

arduino past dht22

a guest
Jul 12th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. //
  2. // FILE: dht_test.ino
  3. // AUTHOR: Rob Tillaart
  4. // VERSION: 0.1.07
  5. // PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
  6. // URL: http://arduino.cc/playground/Main/DHTLib
  7. //
  8. // Released to the public domain
  9. //
  10.  
  11. #include <dht.h>
  12.  
  13. dht DHT;
  14.  
  15. #define DHT11_PIN 4
  16. #define DHT21_PIN 5
  17. #define DHT22_PIN 6
  18.  
  19. void setup()
  20. {
  21. Serial.begin(115200);
  22. Serial.println("DHT TEST PROGRAM ");
  23. Serial.print("LIBRARY VERSION: ");
  24. Serial.println(DHT_LIB_VERSION);
  25. Serial.println();
  26. Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
  27. }
  28.  
  29. void loop()
  30. {
  31. // READ DATA
  32. Serial.print("DHT22, \t");
  33. int chk = DHT.read22(DHT22_PIN);
  34. switch (chk)
  35. {
  36. case DHTLIB_OK:
  37. Serial.print("OK,\t");
  38. break;
  39. case DHTLIB_ERROR_CHECKSUM:
  40. Serial.print("Checksum error,\t");
  41. break;
  42. case DHTLIB_ERROR_TIMEOUT:
  43. Serial.print("Time out error,\t");
  44. break;
  45. default:
  46. Serial.print("Unknown error,\t");
  47. break;
  48. }
  49. // DISPLAY DATA
  50. Serial.print(DHT.humidity, 1);
  51. Serial.print(",\t");
  52. Serial.println(DHT.temperature, 1);
  53.  
  54. delay(1000);
  55.  
  56.  
  57. // READ DATA
  58. Serial.print("DHT21, \t");
  59. chk = DHT.read21(DHT21_PIN);
  60. switch (chk)
  61. {
  62. case DHTLIB_OK:
  63. Serial.print("OK,\t");
  64. break;
  65. case DHTLIB_ERROR_CHECKSUM:
  66. Serial.print("Checksum error,\t");
  67. break;
  68. case DHTLIB_ERROR_TIMEOUT:
  69. Serial.print("Time out error,\t");
  70. break;
  71. default:
  72. Serial.print("Unknown error,\t");
  73. break;
  74. }
  75. // DISPLAY DATA
  76. Serial.print(DHT.humidity, 1);
  77. Serial.print(",\t");
  78. Serial.println(DHT.temperature, 1);
  79.  
  80. delay(1000);
  81.  
  82. // READ DATA
  83. Serial.print("DHT11, \t");
  84. chk = DHT.read11(DHT11_PIN);
  85. switch (chk)
  86. {
  87. case DHTLIB_OK:
  88. Serial.print("OK,\t");
  89. break;
  90. case DHTLIB_ERROR_CHECKSUM:
  91. Serial.print("Checksum error,\t");
  92. break;
  93. case DHTLIB_ERROR_TIMEOUT:
  94. Serial.print("Time out error,\t");
  95. break;
  96. default:
  97. Serial.print("Unknown error,\t");
  98. break;
  99. }
  100. // DISPLAY DATA
  101. Serial.print(DHT.humidity,1);
  102. Serial.print(",\t");
  103. Serial.println(DHT.temperature,1);
  104.  
  105. delay(1000);
  106. }
  107. //
  108. // END OF FILE
  109. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement