/* DHT-22 sensor with I2C 16x2 LCD with Arduino uno
Temperature and humidity sensor displayed on LCD
Based on: http://www.ardumotive.com/how-to-use-dht-22-sensor-en.html
and https://www.ardumotive.com/i2clcden.html for the I2C LCD library
by Michalis Vasilakis
Recompiled by adhitadhitadhit
Notes: Use the LCD I2C Library from the link above.
*/
#include <dht.h> // Library for DHT sensor
#include <LiquidCrystal_I2C.h> // LCD library for I2C
#include <Wire.h>
dht DHT;
// Constants
#define DHT22_PIN 2 // DHT 22 (AM2302) - pin used for DHT22
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
// Variables
float hum; // Stores humidity value
float temp; // Stores temperature value
void setup() {
Serial.begin(9600);
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
}
void loop() {
int chk = DHT.read22(DHT22_PIN);
// Read data and store it to variables hum and temp
hum = DHT.humidity;
temp = DHT.temperature;
// Print temp and humidity values to LCD
lcd.setCursor(0, 0);
lcd.print("Humidity: ");
lcd.print(hum);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C"); // "C" for Celsius
delay(2000); // Delay 2 sec between temperature/humidity check
}