-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote-starter.ino
206 lines (183 loc) · 4.74 KB
/
remote-starter.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// Setup to talk to the Serial Terminal when connected to the computer
#include <SoftwareSerial.h>
SoftwareSerial GPRS(7, 8);
unsigned char buffer[256];
int count = 0;
// Setting up inicial door state
int last_door_value = -1;
int current_door_value = -1;
int total_delay = 0;
// Iniciating communication with the Serial Terminal and the PINS that are going to send and receive the pulses to the remote
void setup()
{
GPRS.begin(19200);
Serial.begin(19200);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, INPUT);
}
void loop()
{
current_door_value = digitalRead(5);
if (last_door_value == -1) {
// This will initialize our "What was the last thing we read?" variable
last_door_value = current_door_value;
}
delay(1000);
total_delay += 1000;
// This will send the SMS letting me know that a Door has been opened or closed
if (current_door_value != last_door_value) {
if (current_door_value == 0) {
GPRS.println("AT+CMGF=1");
delay(100);
GPRS.println("AT+CMGS = \"+12674671270\"");
delay(100);
GPRS.println("Door Closed");
delay(500);
GPRS.println((char)26);
delay(500);
GPRS.println();
delay(500);
readPrint();
clearBufferArray();
delay(3500);
} else {
GPRS.println("AT+CMGF=1");
delay(100);
GPRS.println("AT+CMGS = \"+12674671270\"");
delay(100);
GPRS.println("Door Opened");
delay(500);
GPRS.println((char)26);
delay(500);
GPRS.println();
delay(500);
readPrint();
clearBufferArray();
delay(3500);
}
last_door_value = current_door_value;
}
// Next several lines are for receiving the SMS and sending the signal to the Arduino to Start the car, Close or Open the door locks
if (total_delay > 5000 && GPRS.available())
{
total_delay = 0;
delay(5000);
readPrint();
clearBufferArray();
delay(1000);
GPRS.println("AT+CMGR=1");
delay(2000);
readPrint();
String str1 = (const char*)buffer;
int index = str1.lastIndexOf("\"");
String text = str1.substring(index + 1, str1.length() - 1);
String str2 = "Start";
String str3 = "Open";
String str4 = "Close";
if (text.indexOf(str2) != -1)
{
// Serial.write("\nStart\n");
for (int x = 0; x < 2; x++)
{
digitalWrite(2, HIGH);
delay(800);
digitalWrite(2, LOW);
delay(1500);
}
GPRS.println("AT+CMGF=1");
delay(100);
GPRS.println("AT+CMGS = \"+12674671270\"");
delay(100);
GPRS.println("Started");
delay(500);
GPRS.println((char)26);
delay(500);
GPRS.println();
delay(500);
readPrint();
clearBufferArray();
delay(3500);
}
else
{
if (text.indexOf(str3) != -1)
{
// Serial.write("\nOpen\n");
for (int x = 0; x < 2; x++)
{
digitalWrite(3, HIGH);
delay(600);
digitalWrite(3, LOW);
delay(600);
}
GPRS.println("AT+CMGF=1");
delay(100);
GPRS.println("AT+CMGS = \"+12674671270\"");
delay(100);
GPRS.println("Unlock Succesful");
delay(500);
GPRS.println((char)26);
delay(500);
GPRS.println();
delay(500);
readPrint();
clearBufferArray();
delay(3500);
}
else
{
if (text.indexOf(str4) != -1)
{
// Serial.write("\nClose\n");
for (int x = 0; x < 2; x++)
{
digitalWrite(4, HIGH);
delay(600);
digitalWrite(4, LOW);
delay(600);
}
GPRS.println("AT+CMGF=1");
delay(100);
GPRS.println("AT+CMGS = \"+12674671270\"");
delay(100);
GPRS.println("Lock Succesful");
delay(500);
GPRS.println((char)26);
delay(500);
GPRS.println();
delay(500);
readPrint();
clearBufferArray();
delay(3500);
}
else
Serial.write("\nnot found\n"); // If none was found print "not found" to the Serial Terminal
}
}
clearBufferArray();
delay(1000);
GPRS.println("AT+CMGD=1,4"); //Delete all messages in the SIM Card
delay(1000);
readPrint();
clearBufferArray();
}
}
void readPrint() // This function reads and puts together everything on the SIM Card and prints it to the Serial Port
{
while (GPRS.available())
{
buffer[count++] = GPRS.read();
if (count == 256)break;
}
Serial.write(buffer, count);
}
void clearBufferArray() // function to clear buffer array
{
for (int i = 0; i < count; i++)
{
buffer[i] = (unsigned char)0;
}
count = 0;
}