-
Notifications
You must be signed in to change notification settings - Fork 3
/
dht11.ino
69 lines (64 loc) · 1.56 KB
/
dht11.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
62
63
64
65
66
67
68
69
#include <LiquidCrystal_I2C.h>
#include <SimpleDHT.h>
#include <avr/sleep.h>
#include <avr/power.h>
#define buzzer 1
#define pinDHT11 3
LiquidCrystal_I2C lcd(0x3F, 16, 2); // set the LCD address to 0x3F for a 16 chars and 2 line display (Green)
//LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display (Blue)
SimpleDHT11 dht11;
void setup()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
pinMode(buzzer, OUTPUT);
lcd.init();
lcd.display();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(F("Weather Station"));
lcd.setCursor(0, 1);
lcd.print(F("By: HA4ever ^_*"));
delay(2000);
}
void loop()
{
byte temperature = 0, humidity = 0;
int err = SimpleDHTErrSuccess;
for (byte i = 0; i < 10; i++) {
if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Read failed!"));
lcd.setCursor(0, 1);
lcd.print(F("Error code: "));
lcd.print(err);
delay(1000);
return;
}
tone(buzzer, 500, 50);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("Temp: "));
lcd.print((int)temperature);
lcd.print(F(" *C"));
lcd.setCursor(0, 1);
lcd.print(F("Humidity: "));
lcd.print((int)humidity);
lcd.print(F("%"));
delay(1000);
}
enterSleep();
}
void enterSleep(void)
{
tone(buzzer, 300, 50);
lcd.noBacklight();
lcd.noDisplay();
delay(50);
power_usi_disable();
power_timer1_disable();
power_adc_disable();
power_all_disable();
sleep_enable();
sleep_cpu();
}