Skip to content

Instantly share code, notes, and snippets.

@ericdcobb
Created November 6, 2013 05:31
Show Gist options
  • Save ericdcobb/7331403 to your computer and use it in GitHub Desktop.
Save ericdcobb/7331403 to your computer and use it in GitHub Desktop.
#include "DHT.h"
#include <LiquidCrystal.h>
#define DHTPIN 2
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
Serial.begin(9600);
dht.begin();
lcd.begin(16, 2);
delay(5000);
}
void loop() {
// 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();
float t = dht.readTemperature()*1.8+32;
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *F");
lcd.setCursor(0, 0);
lcd.print("T: ");
lcd.print(t);
lcd.print(" *F");
lcd.setCursor(0, 1);
lcd.print("H: ");
lcd.print(h);
lcd.print(" %");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment