forked from JayaSurya-27/GSM_Module
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsend_sms.txt
More file actions
67 lines (49 loc) · 1.33 KB
/
send_sms.txt
File metadata and controls
67 lines (49 loc) · 1.33 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
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define GPS_RX_PIN 10
#define GPS_TX_PIN 11
TinyGPSPlus gps;
SoftwareSerial gpsSerial(GPS_RX_PIN, GPS_TX_PIN);
#define SIM_RX_PIN 17
#define SIM_TX_PIN 16
SoftwareSerial simSerial(SIM_RX_PIN, SIM_TX_PIN);
void setup() {
Serial.begin(9600);
gpsSerial.begin(9600);
simSerial.begin(9600);
delay(1000);
sendSMS("+917680096031", "Initializing...");
}
void loop() {
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
}
if (gps.location.isUpdated()) {
Serial.print("Latitude: ");
Serial.print(gps.location.lat(), 6);
Serial.print(", Longitude: ");
Serial.println(gps.location.lng(), 6);
sendSMS("+917680096031", "Latitude: " + String(gps.location.lat(), 6) + ", Longitude: " + String(gps.location.lng(), 6));
delay(60000);
}
}
void sendSMS(String number, String message) {
simSerial.println("AT+CMGF=1");
delay(100);
while (simSerial.available()) {
Serial.write(simSerial.read());
}
simSerial.print("AT+CMGS=\"");
simSerial.print(number);
simSerial.println("\"");
delay(100);
while (simSerial.available()) {
Serial.write(simSerial.read());
}
simSerial.print(message);
simSerial.write((byte)26);
delay(100);
while (simSerial.available()) {
Serial.write(simSerial.read());
}
}