Created
August 11, 2016 00:52
-
-
Save izumogeiger/510d9908c911c518db7632dcdf8223a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <DHT.h> | |
#define DHTTYPE DHT11 | |
#define DHTPIN 2 | |
DHT dht(DHTPIN, DHTTYPE); | |
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(3, 4, 5, 6, 7, 8); | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("DHTxx test!"); | |
dht.begin(); | |
lcd.begin(16, 2); | |
} | |
void loop() { | |
delay(2000); | |
// Reading temperature or humidity takes about 250 milliseconds! | |
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) | |
float h = dht.readHumidity(); | |
// Read temperature as Celsius (the default) | |
float t = dht.readTemperature(); | |
// Read temperature as Fahrenheit (isFahrenheit = true) | |
float f = dht.readTemperature(true); | |
// Check if any reads failed and exit early (to try again). | |
if (isnan(h) || isnan(t) || isnan(f)) { | |
Serial.println("Failed to read from DHT sensor!"); | |
return; | |
} | |
// Compute heat index in Fahrenheit (the default) | |
float hif = dht.computeHeatIndex(f, h); | |
// Compute heat index in Celsius (isFahreheit = false) | |
float hic = dht.computeHeatIndex(t, h, false); | |
Serial.print("Humidity: "); | |
Serial.print(h); | |
Serial.print(" %\t"); | |
Serial.print("Temperature: "); | |
Serial.print(t); | |
Serial.print(" *C "); | |
Serial.print(f); | |
Serial.print(" *F\t"); | |
Serial.print("Heat index: "); | |
Serial.print(hic); | |
Serial.print(" *C "); | |
Serial.print(hif); | |
Serial.println(" *F"); | |
lcd.setCursor(0,0); | |
lcd.print("T: "); | |
lcd.setCursor(3,0); | |
lcd.print(t); | |
lcd.setCursor(8,0); | |
lcd.print("*C"); | |
lcd.setCursor(0,1); | |
lcd.print("H: "); | |
lcd.setCursor(3,1); | |
lcd.print(h); | |
lcd.setCursor(8,1); | |
lcd.print("%"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment