#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 2 // Defines pin number to which the sensor is connected
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
Serial.begin(9600);
Serial.println(F("DHT22 test!"));
dht.begin();
// Init
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(4, 0);
lcd.print("DHT22 TEST");
lcd.setCursor(2, 1);
}
void loop() {
delay(2000);
float t = dht.readTemperature();
float h = dht.readHumidity();
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.println(F("°C "));
lcd.setCursor(0,1); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Temp.: "); // Prints string "Temp." on the LCD
lcd.print(t); // Prints the temperature value from the sensor
lcd.print(" C");
lcd.setCursor(0,2);
lcd.print("Humidity.: ");
lcd.print(h);
lcd.print(" %");
delay(2000);
lcd.clear();
lcd.setCursor(8,2); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("BYE");
delay(2000);
lcd.clear();
}