#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
dht.begin();// initialize the sensor
lcd.backlight();// turn on lcd backlight
lcd.init();// initialize lcd
}
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();
// 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(F("Failed to read from DHT sensor!"));
return;
}
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("Teplota: ");
//lcd.setCursor(9,0);
lcd.print(t);
if (t < 10) {lcd.print((char)223); lcd.print("C ");} else {lcd.print((char)223); lcd.print("C");}
lcd.setCursor(0,1);
lcd.print("Vlhkost: ");
//lcd.setCursor(9,1);
lcd.print(h);
if (h < 10) {lcd.print("% ");} else { lcd.print("%");}
}