-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotorControlGSM.ino
More file actions
166 lines (154 loc) · 3.2 KB
/
MotorControlGSM.ino
File metadata and controls
166 lines (154 loc) · 3.2 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <SoftwareSerial.h>
#include<LiquidCrystal.h>
#define motor1 3
#define motor2 4
#define motor3 5
String stringOne;
String stringTwo;
int temp=0,i=0;
int led=13;
int inPin=12;
int power;
char msg;
char str[15];
void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(power, INPUT);
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(motor3, OUTPUT);
Serial.println("AT+CNMI=2,2,0,0,0");
delay(500);
Serial.println("AT+CMGF=1");
delay(1000);
}
void loop()
{
if(temp==1)
{
check();
temp=0;
i=0;
delay(1000);
}
}
void powerCheck()
{
power=digitalRead(inPin);
if(power==HIGH){
stringOne="POWER IS IN ON STATE";
SendMessage();
}
if(power==LOW){
stringOne="POWER IS IN OFF STATE";
SendMessage();
}
}
void serialEvent()
{
while(Serial.available())
{
if(Serial.find("#"))
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
while (Serial.available())
{
char inChar=Serial.read();
str[i++]=inChar;
if(inChar=='*')
{
temp=1;
return;
}
}
}
}
}
void SendMessage()
{
Serial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
Serial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number
delay(1000);
Serial.println(stringOne);// The SMS text you want to send
delay(100);
Serial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void check()
{
if(!(strncmp(str,"motor1 on",9)))
{
digitalWrite(motor1, HIGH);
stringOne="motor1 is turned on";
SendMessage();
delay(200);
}
else if(!(strncmp(str,"motor1 off",10)))
{
digitalWrite(motor1, LOW);
stringOne="motor1 is turned off";
SendMessage();
delay(200);
}
else if(!(strncmp(str,"motor2 on",9)))
{
digitalWrite(motor2, HIGH);
stringOne="motor2 is turned on";
SendMessage();
delay(200);
}
else if(!(strncmp(str,"motor2 off",10)))
{
digitalWrite(motor2, LOW);
stringOne="motor2 is turned off";
SendMessage();
delay(200);
}
else if(!(strncmp(str,"motor3 on",9)))
{
digitalWrite(motor3, HIGH);
stringOne="motor3 is turned on";
SendMessage();
delay(200);
}
else if(!(strncmp(str,"motor3 off",10)))
{
digitalWrite(motor3, LOW);
stringOne="motor3 is turned off";
SendMessage();
delay(200);
}
else if(!(strncmp(str,"all on",6)))
{
digitalWrite(motor1, HIGH);
digitalWrite(motor2, HIGH);
digitalWrite(motor3, HIGH);
stringOne="all devices turned off";
SendMessage();
delay(200);
}
else if(!(strncmp(str,"all off",7)))
{
digitalWrite(motor1, LOW);
digitalWrite(motor2, LOW);
digitalWrite(motor3, LOW);
stringOne="all devices turned on";
SendMessage();
delay(200);
}
else if(!(strncmp(str,"status",6)))
{
SendMessage();
delay(200);
}
else if(!(strncmp(str,"powercheck",10)))
{
powerCheck();
delay(200);
}
}