#include<DHT.h> // including the library of DHT11 temperature and humidity sensor
#define DHTTYPE DHT22 // type of using sensor
#include <LiquidCrystal_I2C.h>
int lcdRows = 2;
int lcdColumns = 16;
#define dht_dpin 4 // Digital pin connected to the DHT sensor
LiquidCrystal_I2C lcd(0x27, lcdRows, lcdColumns );
DHT dht(dht_dpin, DHTTYPE); // Initialize DHT sensor
void setup() // the setup function runs once when you press reset or power the board
{
dht.begin(); // sketch begins by including the DHT library
Serial.begin(115200); // establishes serial communication between your Arduino board and another device.
lcd.init();
lcd.backlight();
}
void loop() {
float t = dht.readTemperature(); // Variable 't' is assigned to read the data from DHT11
Serial.print("Tem= ");
Serial.print(t); // Prints ‘t’ data to the serial port
Serial.println("C "); // Prints ”C” to the serial port
lcd.setCursor(0, 0);
lcd.print("Tem = ");
lcd.print(t); // Prints ‘t’ data to the serial port
lcd.print(" C"); // Prints ”C” to the serial port
float h = dht.readHumidity(); // Variable 't' is assigned to read the data from DHT11
Serial.print("Hum = ");
Serial.print(h); // Prints ‘t’ data to the serial port
Serial.println("% "); // Prints ”C” to the serial port
lcd.setCursor(0, 1);
lcd.print("Hum = ");
lcd.print(h); // Prints ‘t’ data to the serial port
lcd.print("%");
delay(10); // delay 800 milliseconds
}