-
Notifications
You must be signed in to change notification settings - Fork 1
/
automate.ino
136 lines (130 loc) · 2.56 KB
/
automate.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
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
128
129
130
131
132
133
134
135
136
String inputs;
#define relay1 2 //Connect relay1 to pin 2
#define relay2 3 //Connect relay2 to pin 3
#define relay3 4 //Connect relay3 to pin 4bbbb
#define relay4 5 //Connect relay4 to pin 5///////////////////////////
#define relay5 6
#define relay6 7
int val1=0;
int val2=0;
int val3=0;
int val4=0;
int val5=0;
int val6=0;
void setup()
{
Serial.begin(9600); //Set rate for communicating with phone
pinMode(relay1, OUTPUT); //Set relay1 as an output
pinMode(relay2, OUTPUT); //Set relay2 as an output
pinMode(relay3, OUTPUT); //Set relay1 as an output
pinMode(relay4, OUTPUT); //Set relay2 as an output
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
digitalWrite(relay1, HIGH); //Switch relay1 off
digitalWrite(relay2, HIGH); //Swtich relay2 off
digitalWrite(relay3, HIGH); //Switch relay3 off
digitalWrite(relay4, HIGH); //Swtich relay4 off
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
}
void loop()
{
while(Serial.available()) //Check if there are available bytes to read
{
delay(10); //Delay to make it stable
char c = Serial.read(); //Conduct a serial read
if (c == '#'){
break; //Stop the loop once # is detected after a word
}
inputs += c; //Means inputs = inputs + c
}
if (inputs.length() >0)
{
Serial.println(inputs);
if(inputs == "relay1")
{
if(val1==0)
{
digitalWrite(relay1,LOW);
val1=1;
}
else
{
digitalWrite(relay1,HIGH);
val1=0;
}
delay(100);
}
else if(inputs == "relay2")
{
if(val2==0)
{
digitalWrite(relay2,LOW);
val2=1;
}
else
{
digitalWrite(relay2,HIGH);
val2=0;
}
delay(100);
}
else if(inputs == "relay3")
{
if(val3==0)
{
digitalWrite(relay3,LOW);
val3=1;
}
else
{
digitalWrite(relay3,HIGH);
val3=0;
}
delay(100);
}
else if(inputs == "relay4")
{
if(val4==0)
{
digitalWrite(relay4,LOW);
val4=1;
}
else
{
digitalWrite(relay4,HIGH);
val4=0;
}
delay(100);
}
else if(inputs == "relay5")
{
if(val5==0)
{
digitalWrite(relay5,LOW);
val5=1;
}
else
{
digitalWrite(relay5,HIGH);
val5=0;
}
delay(100);
}
else if(inputs == "relay6")
{
if(val6==0)
{
digitalWrite(relay6,LOW);
val6=1;
}
else
{
digitalWrite(relay6,HIGH);
val6=0;
}
delay(100);
}
inputs="";
}
}