#include <LiquidCrystal_I2C.h> // includes the liquidCristal library
LiquidCrystal_I2C lcd(0x27,16,2);
#include <dht.h>
#define dataPin 8 // defines pin number to whitch the sensor is connected
dht DHT; // creats a DHT object
bool showcelciusorfarenheit = false;
void setup() {
lcd.init();
lcd.clear();
lcd.backlight(); // make sure backlight is on
}
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);
}