#include "DHT.h"
#include <LiquidCrystal_I2C.h>
#define DHTPIN A0
#define DHTTYPE DHT22
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 2
//create instances for the sensor and lcd
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
//begin the dht sensor and lcd
dht.begin();
lcd.init();
lcd.backlight();
}
void loop() {
// Wait a few seconds between measurements.
delay(2);
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);
char degree_symbol = 0x00+223;
char percent_symbol = 0x00+37;
if (isnan(h) || isnan(t) ){
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
//humidity output on lcd
lcd.setCursor(0, 0);
lcd.print(F("Humidity: "));
lcd.print(h);
lcd.print(percent_symbol);
//temperature output on lcd
lcd.setCursor(0, 1);
lcd.print(F("Temp: "));
lcd.print(t);
lcd.print((degree_symbol));
lcd.print(("C"));
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% \n Temperature: "));
Serial.print(t);
Serial.print("C ");
delay(200);
}