#include <dht.h>
#define dataPin 8 // Defines pin number to which the sensor is connected
dht Sensor; // Create an object named Sensor to access the functions in dht Lib
#include <LiquidCrystal_I2C.h>//add the library
LiquidCrystal_I2C display(0x27, 16,2);//createan object & set the dimension and address
//create variables:
String temp = "24.00C";
String hum = "40.00%";
void setup()
{
Serial.begin(9600);//establish serial connection
display.init();//initiate the LCD
display.clear();//clear any display
display.backlight(); //turnonthebacklight
}
void loop()
{
int readData = Sensor.read22(dataPin); // initialize the connection 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
// Printing the results on the serial monitor
Serial.print("Temperature = ");
Serial.print(t);
Serial.println(" C");
Serial.print("Humidity = ");
Serial.print(h);
Serial.println(" % ");
delay(2000); // Delays 2 seconds
display.setCursor(0,0); //set the cursor in this coordinates
display.print("The temp is:"); //display text
display.setCursor(0,1); //set cursor to the 2nd row
display.print(temp);
delay(4000); //wait for 4 secs
display.clear(); //clear the display
display.setCursor(0,0); //set the cursor in this coordinates
display.print("The humidity is:"); //display text
display.setCursor(0,1); //set cursor to the 2nd row
display.print(hum);
delay(4000); //wait for 4 secs
display.clear(); //clear the display
}