-
Notifications
You must be signed in to change notification settings - Fork 0
/
WMS-Code.ino
180 lines (142 loc) · 4.04 KB
/
WMS-Code.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
#include<dht.h>
#include <SoftwareSerial.h>
#define DHT11_PIN 3
#define pirPin 2
dht DHT;
SoftwareSerial mySerial(9, 10);
const int sensor=A1;
float tempc; //variable to store temperature in degree Celsius
float tempf; //variable to store temperature in Fahreinheit
float vout; //temporary variable to hold sensor reading
int PIRValue = 0;
const int gasPin = A0; //GAS sensor output pin to Arduino analog A0 pin
char msg;
void setup() {
pinMode(sensor,INPUT);
pinMode(pirPin, INPUT);
Serial.begin(9600);
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.println("send message");
Serial.println();
delay(100);
}
char sense_humidity(){
int chk = DHT.read11(DHT11_PIN);
Serial.println(" Humidity " );
Serial.println(DHT.humidity);
Serial.println(" Temparature ");
Serial.println(DHT.temperature);
if(DHT.temperature>100.00){
return 'b';
}
if(DHT.temperature<15.00||DHT.temperature>30.00){
return 't';
}
else if(DHT.humidity<12.00||DHT.humidity>13.00){
return 'h';
}
else{
return '0';
}
}
char sense_motion(){
PIRValue = digitalRead(pirPin);
//Serial.println(PIRValue);
if(PIRValue>0){
Serial.println("Motion Detected");
return 'm';
}
else{
return '0';
}
}
char sense_gas(){
Serial.println(analogRead(gasPin));
delay(1000); // Print value every 1 sec.
if(analogRead(gasPin)>300)
{
return 'g';
}
else
{
return '0';
}
}
void SendMessage_Motion(){
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"x\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("Motion Alert!");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void SendMessage_Gas(){
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"x\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("Smoke Alert!");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void SendMessage_Temperature(){
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"x\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("Temperature Alert!");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void SendMessage_Humidity(){
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"x\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("Humidity Alert!");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void SendMessage_Fire(){
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"x\"\r"); // Replace x with mobile number
delay(1000);
mySerial.println("Fire Alert!");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void loop() { // READ DATA
char h = sense_humidity();
char g = sense_gas();
char m = sense_motion();
Serial.println(h);
Serial.println(g);
Serial.println(m);
if(h=='t'){
SendMessage_Temperature();
delay(5000);
}
else if(g=='g'){
SendMessage_Gas();
delay(5000);
}
else if(m=='m'){
SendMessage_Motion();
delay(5000);
}
else if(h=='h'){
SendMessage_Humidity();
delay(5000);
}
else if(h=='b'){
SendMessage_Fire();
delay(5000);
}
}