Advertisement
Guest User

Untitled

a guest
May 20th, 2012
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. // Example testing sketch for various DHT humidity/temperature sensors
  2. // Written by ladyada, public domain
  3. #include <LiquidCrystal.h>
  4. #include "DHT.h"
  5.  
  6. #define DHTPIN 3 // what pin we're connected to
  7. // Uncomment whatever type you're using!
  8. #define DHTTYPE DHT11 // DHT 11
  9. //#define DHTTYPE DHT22 // DHT 22 (AM2302)
  10. //#define DHTTYPE DHT21 // DHT 21 (AM2301)
  11.  
  12. // Connect pin 1 (on the left) of the sensor to +5V
  13. // Connect pin 2 of the sensor to whatever your DHTPIN is
  14. // Connect pin 4 (on the right) of the sensor to GROUND
  15. // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
  16.  
  17. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  18.  
  19. DHT dht(DHTPIN, DHTTYPE);
  20.  
  21. void setup() {
  22.  
  23. Serial.begin(9600);
  24.  
  25. lcd.begin(16,2);
  26. lcd.clear();
  27.  
  28. lcd.setCursor(0, 0);
  29.  
  30. Serial.println("Firmware version 1.0.6");
  31.  
  32. lcd.print("Firmware version");
  33.  
  34. lcd.setCursor(0, 1);
  35.  
  36. lcd.print("1.0.6");
  37.  
  38. delay(2000);
  39.  
  40. lcd.clear();
  41.  
  42. Serial.println(" _______ __ __ ");
  43. Serial.println("| _ |.----.--| |.--.--.|__|.-----.-----.");
  44. Serial.println("| || _| _ || | || || | _ |");
  45. Serial.println("|___|___||__| |_____||_____||__||__|__|_____|");
  46. Serial.println(" _____ __ __ __ __ ");
  47. Serial.println("| ||__|.-----.|__| |_.---.-.| |");
  48. Serial.println("| | || || _ || | _| _ || |");
  49. Serial.println("|_____||__||___ ||__|____|___._||__|");
  50. Serial.println(" |_____| ");
  51. Serial.println(" _______ __ ");
  52. Serial.println("| __|.--.--.-----.| |_.-----.--------.-----.");
  53. Serial.println("|__ || | |__ --|| _| -__| |__ --|");
  54. Serial.println("|_______||___ |_____||____|_____|__|__|__|_____|");
  55. Serial.println(" |_____| ");
  56. Serial.println(" ");
  57. Serial.println("Digital Thermometer/Hygrometer");
  58.  
  59. delay(2000);
  60.  
  61. Serial.println("Loading...");
  62.  
  63. lcd.print("Loading...");
  64.  
  65. delay(3000);
  66.  
  67. dht.begin();
  68.  
  69.  
  70. }
  71.  
  72.  
  73.  
  74. void loop() {
  75. // Reading temperature or humidity takes about 250 milliseconds!
  76. // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  77. float h = dht.readHumidity();
  78. float t = dht.readTemperature();
  79.  
  80. // check if returns are valid, if they are NaN (not a number) then something went wrong!
  81. if (isnan(t) || isnan(h)) {
  82. Serial.println(". Failed to read from DHT11 sensor");
  83. lcd.clear();
  84. lcd.setCursor(0, 0);
  85. lcd.print(" SENSOR ERROR");
  86. lcd.setCursor(0, 1);
  87. lcd.print(" Failed to read");
  88. delay(3000);
  89. } else {
  90. Serial.print("Humid: ");
  91. Serial.print(h);
  92. Serial.print("% ");
  93. Serial.print("Temp: ");
  94. Serial.print(t);
  95. Serial.println(" C");
  96.  
  97. lcd.clear();
  98.  
  99. lcd.setCursor(0, 0);
  100.  
  101. lcd.print("Humid: ");
  102.  
  103. lcd.print(h);
  104.  
  105. lcd.print("%");
  106.  
  107. lcd.setCursor(0, 1);
  108.  
  109. lcd.print("Temp: ");
  110.  
  111. lcd.print(t);
  112.  
  113. lcd.print("C");
  114.  
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement