#include "DHT.h"
#define DHTPIN 2// you can use
#define DHTTYPE DHT22//#define DHTTYPE DHT21
//#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);//you can also use pins 3, 4, 5, 12, 13 or 14
// Pin 15 can work but DHT must be disconnected during program upload
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(9600);
Serial.println("DHT22 test!");
dht.begin();// initialize the sensor
lcd.backlight();// turn on lcd backlight
lcd.init();// initialize lcd
lcd.setCursor(0, 0);
lcd.print("RPCA");
lcd.setCursor(2, 1);
lcd.print("DHT22 Test");
delay(2000);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp : ");
lcd.setCursor(7, 0);
lcd.print(t);
lcd.print(" C");
lcd.setCursor(0,1);
lcd.print("Humi : ");
lcd.setCursor(7,1);
lcd.print(h);
lcd.print(" %RH");
delay(2000);
}