-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmart_Home_Control.ino
More file actions
54 lines (45 loc) · 1017 Bytes
/
Smart_Home_Control.ino
File metadata and controls
54 lines (45 loc) · 1017 Bytes
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
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int LED_Pin = 9;
const int LDR_Pin = A0;
const int TEMP_Pin = A1;
const int FAN_Pin = 5;
int lightThreshold = 500;
int tempThreshold = 24;
void setup()
{
pinMode(LED_Pin, OUTPUT);
pinMode(LDR_Pin, INPUT);
pinMode(TEMP_Pin, INPUT);
pinMode(FAN_Pin, OUTPUT);
lcd.init();
lcd.clear();
lcd.backlight();
}
void loop()
{
int LDR_Value = analogRead(LDR_Pin);
lcd.setCursor(0,0);
lcd.print("Light: ");
lcd.setCursor(7, 0);
lcd.print(LDR_Value);
lcd.print(" LUX");
if (LDR_Value <= lightThreshold) {
digitalWrite(LED_Pin, HIGH);
} else {
digitalWrite(LED_Pin, LOW);
}
int tempVal = analogRead(TEMP_Pin);
float temperature = (tempVal * 0.48828125);
lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.setCursor(6, 1);
lcd.print(temperature);
lcd.print(" C");
if (temperature >= tempThreshold) {
digitalWrite(FAN_Pin, HIGH);
} else {
digitalWrite(FAN_Pin, LOW);
}
delay(1000);
}