#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// Define I2C Address - change if reqiuired
const int i2c_addr = 0x27;
LiquidCrystal_I2C display(i2c_addr, 16, 2);
void setup() {
// put your setup code here, to run once:
Wire.begin();
display.init();
display.backlight();
display.clear();
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
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);
// Clear the display
display.clear();
//Set the cursor coordinates
display.setCursor(0,0);
if (isnan(h) || isnan(t) || isnan(f)) {
// Serial.println(F("Failed to read from DHT sensor!"));
display.print("Failed to read from DHT sensor!");
}
else{
display.print("Humid: ");
display.print(h);
display.print(" %");
display.setCursor(0,1);
display.print("Temp: ");
display.print(t);
display.print(" C");
// display.print(f);
// display.print("F");
}
digitalWrite(13, HIGH);
delay(50);
digitalWrite(13, LOW);
}