forked from passion-tech/Hello-tech
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dht_11_with_i2c_Lcd_display_Code.ino
61 lines (49 loc) · 1.49 KB
/
Dht_11_with_i2c_Lcd_display_Code.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <DHT.h>;
//I2C LCD:
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
//Constants
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
//Variables
//int chk;
int h; //Stores humidity value
int t; //Stores temperature value
void setup()
{
Serial.begin(9600);
Serial.println("itsmohsin Temperature and Humidity Sensor Test");
dht.begin();
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
}
void loop()
{
//Read data and store it to variables h (humidity) and t (temperature)
// Reading temperature or humidity takes about 250 milliseconds!
h = dht.readHumidity();
t = dht.readTemperature();
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %, Temp: ");
Serial.print(t);
Serial.println(" ° Celsius");
// set the cursor to (0,0):
// print from 0 to 9:
lcd.setCursor(0, 0);
lcd.println(" Now Tempeture");
lcd.setCursor(0, 1);
lcd.print("T:");
lcd.print(t);
lcd.print("C");
lcd.setCursor(6, 1);
lcd.println("2020 ");
lcd.setCursor(11, 1);
lcd.print("H:");
lcd.print(h);
lcd.print("%");
delay(1000); //Delay 1 sec.
}