-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomeAutomation.ino
101 lines (101 loc) · 1.66 KB
/
homeAutomation.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
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
#include<SoftwareSerial.h>
#include <Servo.h>
Servo myservo;
int pos = 0;
SoftwareSerial BT(10,11);
String state;
int count=0;
int x=0;
void setup()
{
BT.begin(9600);
Serial.begin(9600);
myservo.attach(9);
myservo.write(15);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(6,OUTPUT);
}
void home_auto(String state)
{
int flag=0;
if(state=="light on")
flag=1;
else if(state=="light off")
flag=2;
else if(state=="TV on")
flag=3;
else if(state=="TV off")
flag=4;
else if(state=="cool")
flag=5;
else if(state=="hot")
flag=6;
switch(flag)
{
case 1:digitalWrite(13,HIGH);break;
case 2:digitalWrite(13,LOW);break;
case 3:digitalWrite(12,HIGH);break;
case 4:digitalWrite(12,LOW);break;
case 5:digitalWrite(6,HIGH);break;
case 6:digitalWrite(6,LOW);break;
}
count=0;
}
void error()
{
int i=0;
for(i=0;i<10;i++)
{
digitalWrite(12,HIGH);
delay(500);
digitalWrite(12, LOW);
delay(500);
}
count=0;
}
void loop(){
while(BT.available()){
delay(10);
char c=BT.read();
state+=c;
}
if(state.length()>0)
{
if(state=="light on"||state=="light off"||state=="TV on"||state=="TV off"||state=="cool"||state=="hot")
{
home_auto(state);
state="";
}
else
{
Serial.println(state);
if(state=="turn on")
{
//digitalWrite(13,HIGH);
delay(1000);
myservo.write(110);
}
else if(state=="turn off")
{
//digitalWrite(13,LOW);
delay(1000);
myservo.write(15);
}
if(state!="turn on" and state!="turn off" )
{count+=1;}
else if(state=="turn on" or state=="turn off")
{count=0;}
if(count>=3)
{error();}
//else
//{digitalWrite(12,LOW);}
state="";
if(count!=x)
{
x=count;
Serial.println(x);
}
}
}
}