-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.txt
127 lines (122 loc) · 2.79 KB
/
Code.txt
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <LiquidCrystal.h>
LiquidCrystal lcd (12,11,10,4,3,2);
float x,y,z,temp;
void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Home Automation System");
delay(3000);
lcd.clear();
pinMode(8, INPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(A5, INPUT);
pinMode(A4, INPUT);
Serial.begin(9600);
}
void loop()
{
x= digitalRead(8);
y= analogRead(A5);
z= analogRead(A4);
Serial.println(x);
Serial.println(y);
Serial.println(z);
temp = (double)z / 1024;
temp = temp * 5;
temp = temp - 0.5;
temp = temp * 100;
if ( (x>0) )
{
if ((y<550)&&(temp>30))
{
lcd.setCursor(0,0);
lcd.print("Movement");
lcd.setCursor(0,2);
lcd.print("Detected");
delay(1000);
lcd.clear();
digitalWrite(5, HIGH);
lcd.setCursor(0,0);
lcd.print("Bulb is ON");
delay(1000);
lcd.clear();
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
lcd.setCursor(0,0);
lcd.print("Fan Started");
delay(1000);
lcd.clear();
digitalWrite(6, HIGH);
}
else if((y<550)&&(temp<30))
{
lcd.setCursor(0,0);
lcd.print("Movement");
lcd.setCursor(0,2);
lcd.print("Detected");
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
digitalWrite(5, HIGH);
lcd.print("Only Bulb is ON");
delay(1000);
lcd.clear();
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
}
else if((y>550)&&(temp>30))
{
lcd.setCursor(0,0);
lcd.print("Movement");
lcd.setCursor(0,2);
lcd.print("Detected");
delay(1000);
lcd.clear();
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
lcd.setCursor(0,0);
lcd.print("Only Fan Started");
delay(1000);
lcd.clear();
digitalWrite(6, HIGH);
}
else if((y>550)&&(temp<30))
{
lcd.setCursor(0,0);
lcd.print("Movement");
lcd.setCursor(0,2);
lcd.print("Detected");
delay(1500);
lcd.clear();
digitalWrite(5, LOW);
lcd.setCursor(0,0);
lcd.print("Light Detected");
lcd.setCursor(0,2);
lcd.print("Bulb is Off");
delay(3000);
lcd.clear();
digitalWrite(5, LOW);
digitalWrite(6, LOW);
lcd.setCursor(0,0);
lcd.print("Temp is Low");
lcd.setCursor(0,2);
lcd.print("Fan is Off");
delay(3000);
lcd.clear();
digitalWrite(6, LOW);
}
}
else
{
lcd.setCursor(0,0);
lcd.print("No Movement");
lcd.setCursor(0,2);
lcd.print("Detected");
delay(1500);
lcd.clear();
digitalWrite(5, LOW);
digitalWrite(6, LOW);
}
}