#include <LiquidCrystal.h> // includes the liquidCristal library
#include <dht.h>
#define dataPin 8 // defines pin number to whitch the sensor is connected
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // creates a LCD object.
// Parameters: (rs, enable, d4, d5, d6, d7)
dht DHT; // creats a DHT object
bool showcelciusorfarenheit = false;
void setup() {
lcd.begin(16, 2); // initializes the interface to the LCD screen, and specifies
// the dimensions (width and height) of the display
}
void loop() {
// uncomment whatever type sensor you're using (DHT11 or DHT22)!
// int readData = DHT.read11(dataPin); // DHT11
int readData = DHT.read22(dataPin); // DHT22/AM2302
float t = DHT.temperature; // gets the values of the temperature
float h = DHT.humidity; // gets the value of the humidity
lcd.setCursor(0,0); // sets the location at which subsequent text written
// to the LCD will be displayed
lcd.print("Temp.: "); // prints string "Temp." on the LCD
// print temperature value in Celcius and Fahrenheit every alternate cycle
if(showcelciusorfarenheit) {
lcd.print(t); // prints the temperature value from the sensor
lcd.print(" ");
lcd.print((char)223); //shows degrees character
lcd.print("C");
showcelciusorfarenheit = false;
}
else {
lcd.print((t * 9.0) / 5.0 + 32.0); // print the temperature in Fahrenheit
lcd.print(" ");
lcd.print((char)223); // shows degrees character
lcd.print("F");
showcelciusorfarenheit = true;
}
lcd.setCursor(0,1);
lcd.print("Humi.: ");
lcd.print(h);
lcd.print(" %");
delay(5000);
}