#include <dht.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#define dataPin 8 // Defines pin number to which the sensor is connected
#define DHTPIN 2 //Defines DHT pin 2
#define DHTTYPE DHT22 //Define type
dht Sensor; // create an object named Sensor to access the functions in DHT lib
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
Serial.begin(9600); //establish serial connection
dht.begin();
lcd.init();
lcd.backlight();
}
void loop()
{
int readData = Sensor.read22(dataPin); //initialize the collection of reading from the datapin
float t = Sensor.temperature; // Gets the values of the temperature and store it in t float variable
float h = Sensor.humidity; // Gets the values of the humidity & store it in h float variable
float f = dht.readTemperature(true); //reads temperature from dht
lcd.setCursor(0,0); lcd.print("TEMP: "); lcd.print(t); //display temp
lcd.setCursor(0,1); lcd.print("HUMID: "); lcd.print(h); //display humid
// Printing the results on the serial monitor
Serial.print("Humidity: ");
Serial.print(h,1);
Serial.print("% Temperature: ");
Serial.print(t,1);
Serial.print("C & ");
Serial.print(f,1);
Serial.println("F");
}