/*
Project : Arduino Uno is connected with Temperatur sensor (DHT22),
LCD I2C 2004 and LED.
*/
//call library LCD
#include <LiquidCrystal_I2C.h>
// call library DHT sensor
#include <DHT.h>
// definition DHT 22 sensor
#define DHTTYPE DHT22
// LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27,20,4);
// Pin for DHT22 and LED
const int dht_pin = 11;
const int led_pin = 9;
//initialize the DHT
DHT dht(dht_pin, DHTTYPE);
void setup() {
Serial.begin(9600);
// initialize the LCD
lcd.init();
lcd.backlight();
//print a massage to the LCD
lcd.setCursor(3,0);
lcd.print("Hello, World!");
lcd.setCursor(3,1);
lcd.print("Tell me");
lcd.setCursor(3,2);
lcd.print("The temperatur");
lcd.setCursor(3,3);
lcd.print("Right now");
dht.begin(); //initialize the DHT22
pinMode(led_pin, OUTPUT); //LED as output
delay(5000); // wait for 5s
lcd.clear(); //LCD will clear after 5s
}
void loop() {
// show the temperatur
lcd.setCursor(3,0);
lcd.print("Temperatur :");
lcd.setCursor(13,1);
lcd.print(String(dht.readTemperature()) + "C");
// show the humidity
lcd.setCursor(3,2);
lcd.print("Humidity :");
lcd.setCursor(13,3);
lcd.print(String(dht.readHumidity()) + "%");
//LED will light up after the temperatur and humidity is displayed
digitalWrite(led_pin, HIGH);
delay(1000);
digitalWrite(led_pin, LOW);
delay(5000); // wait for 5s off than the display will show again the temperatur
}