Facebook
From Harmless Parakeet, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 272
  1. // DHT code from:
  2. // Example testing sketch for various DHT humidity/temperature sensors
  3. // Written by ladyada, public domain
  4.  
  5. #include "DHT.h"
  6.  
  7. #define DHTPIN 2     // what pin we're connected to
  8.  
  9. // Uncomment whatever type you're using!
  10. #define DHTTYPE DHT11   // DHT 11
  11. // #define DHTTYPE DHT22   // DHT 22  (AM2302)
  12. //#define DHTTYPE DHT21   // DHT 21 (AM2301)
  13. DHT dht(DHTPIN, DHTTYPE);
  14.  
  15. // LCD
  16. // LCD RS=3, EN=4, DS4=5, DS5=6, DS6=7, DS7=8
  17. #include <LiquidCrystal.h>
  18. LiquidCrystal lcd( 3, 4, 5, 6, 7, 8);
  19.  
  20.  
  21.  
  22. void setup() {
  23.   Serial.begin(9600);
  24.   // set up the LCD's number of columns and rows:
  25.   lcd.begin(16,2);
  26.   dht.begin();
  27. }
  28.  
  29. void loop() {
  30.  
  31.   // Reading temperature or humidity takes about 250 milliseconds!
  32.   // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  33.   int h = dht.readHumidity();
  34.   int t = dht.readTemperature();
  35.  
  36.     // set the cursor to (0,0):
  37.   lcd.setCursor(0, 0);
  38.   // print from 0 to 9:
  39.  
  40.    lcd.print("Temp: ");
  41.    lcd.print(t);
  42.    lcd.print("C");
  43.   // set the cursor to (16,1):
  44.   lcd.setCursor(0,1);
  45.   lcd.print("Humidity: ");
  46.   lcd.print(h);
  47.   lcd.print("%");
  48.     delay(200);
  49. }
  50.