-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSMSAlarm.ino
143 lines (128 loc) · 3.79 KB
/
SMSAlarm.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
#include "Timer.h" //http://github.com/JChristensen/Timer
Timer t, t1, t2; //Timers that will be used for launching functions at specific intervals
int once;//when a breach is detected send only one SMS
String trustedNo = "+40731491417";//This is the phone number that the system will send or receive SMS from
String password = "1234567890";//Password for ARM and DISARM
int stare = 0;//State of the system
int sensorValue;//Value of LDR
//a-gsm variables============================
#include <SoftwareSerial.h>
#define powerPIN 7//Arduino Digital pin used to power up / power down the modem
#define resetPIN 6//Arduino Digital pin used to reset the modem
#define statusPIN 5//Arduino Digital pin used to monitor if modem is powered
int state = 0, i = 0, powerState = 0, ready4SMS = 0, ready4Voice = 0;
#define BUFFDSIZE 240
SoftwareSerial SSerial(2, 3); //RX==>2 ,TX soft==>3
char ch;
char buffd[BUFFDSIZE];
char o_buffd[BUFFDSIZE];
int noSMS = 0, totSMS = 0;
char readBuffer[200];
///========================================
int effect[] = {13, 12, 11, 10, 9, 8};//Pins on wich are connected LED's for visual effect
int count, n = 0;//Various variables
void setup() {
//Timers initialization
t.every(250, alarmSMS);
t1.every(50, lightEffect);
t2.every(1, sensor);
//Led pin's initialization
for (int i = 0; i < 6; i++)
{
pinMode(effect[i], OUTPUT);
}
// a-gsm setup=====================================
SSerial.begin(9600);
Serial.begin(57600);//1ms
clearSSerial();
clearSerial();
delay(10);
pinMode(resetPIN, OUTPUT);
digitalWrite(resetPIN, LOW);
pinMode(powerPIN, OUTPUT);
pinMode(statusPIN, INPUT);
digitalWrite(powerPIN, LOW);
delay(100);
Serial.flush();
SSerial.flush();
if (!digitalRead(statusPIN)) restartMODEM();
clearBUFFD();
ready4SMS = 0;
ready4Voice = 0;
Serial.println("SMSAlarm ready");
//===================================================
}
void loop() {
t.update();//Check for SMS
t1.update();//Light effect
t2.update();//Check sensor status
}
//This function is responsable to check for SMS and change the state of the system
void alarmSMS() {
listSMS();
int cnt;
cnt = noSMS;
while (cnt > 0) {
readSMS(cnt);
if ((trustedNo == getValue(buffd, ',', 1).substring(1, 13)) && (password == getValue(buffd, ',', 4))) {
if (stare == 0) {
stare = 1;
Serial.println("ARMED");
sendSMS("+40731491417", "ARMED");
}
else if (stare == 1) {
stare = 0;
Serial.println("DISARMED");
sendSMS("+40731491417", "DISARMED");
}
else if (stare == 2) {
stare = 1;
Serial.println("ALARM CANCEL BUT STILL ARMED");
sendSMS("+40731491417", "ALARM CANCEL BUT STILL ARMED");
}
}
deleteSMS(cnt);
clearBUFFD();
clearSSerial();
cnt--;
}
}
//Function responsable for the LED effects
void lightEffect() {
if (stare == 0) {
for (int i = 0; i < 6; i++) {
digitalWrite(effect[i], HIGH);
delay(50);
digitalWrite(effect[i], LOW);
}
for (int i = 6; i >= 0; i--) {
digitalWrite(effect[i], HIGH);
delay(50);
digitalWrite(effect[i], LOW);
}
}
else if (stare == 1)
{ once = 0;
for (int i = 0; i < 6; i++) {
digitalWrite(effect[i], HIGH);
}
}
else if (stare == 2)
{
for (int i = 0; i < 6; i++) digitalWrite(effect[i], HIGH);
delay(50);
for (int i = 0; i < 6; i++) digitalWrite(effect[i], LOW);
}
}
//Function that is continuously checking the sensor value and in case of trigger it will send an alert
void sensor()
{
sensorValue = analogRead(A0);
if ((stare == 1) && (sensorValue <= 950))
{ stare = 2;
if ((sendSMS("+40731491417", "INTRUDER DETECTED") == 1) & (once == 0)) {
t1.update();//Light effect
once = 1;
}
}
}