0% found this document useful (0 votes)
12 views3 pages

Gps Tracker Sim808

This document contains code for an Arduino sketch that uses a SIM808 module to receive SMS messages. It defines variables and functions for communicating with the module via serial. The sketch checks for new SMS messages, extracts the phone number and message text from the latest message, and if the message matches a password string it will get the current GPS location from the module.

Uploaded by

aarushibawejaji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Gps Tracker Sim808

This document contains code for an Arduino sketch that uses a SIM808 module to receive SMS messages. It defines variables and functions for communicating with the module via serial. The sketch checks for new SMS messages, extracts the phone number and message text from the latest message, and if the message matches a password string it will get the current GPS location from the module.

Uploaded by

aarushibawejaji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <SoftwareSerial.

h>
#include <TinyGPS++.h>

boolean GetGPS_flag = false;


boolean Location_isValid_flag = false;
boolean Password_flag = false;

String value;
String phone_number;
String message_text;
String password = "Hello";
String Message;

#define PIN_TX 10
#define PIN_RX 11
SoftwareSerial mySerial(PIN_TX, PIN_RX);

TinyGPSPlus gps;

String SIM808(String value) {


String Out;

mySerial.println(value);
delay(10);
while (mySerial.available()) {
Out = (mySerial.readString());
}

Out.trim();
Out.remove(0, value.length() + 3);
return Out;
}
String SIM808(String value, int count) {
String Out;

mySerial.println(value);
delay(10);
while (mySerial.available()) {
Out = (mySerial.readString());
}

Out.trim();
Out.remove(0, value.length() + 3 + count);
return Out;
}

void setup() {
mySerial.begin(9600);
Serial.begin(9600);
}

void loop() {
// RECEIVING SMS
Serial.println("Start\n");

Serial.println("Power Down The GPS");


SIM808("AT+CGPSPWR=0");

Serial.println("Check AT Connection");
value = SIM808("AT");
Serial.println(value);
Serial.println("");

Serial.println("Put The Module in SMS Text Mode");


SIM808("AT+CMGF=1");
delay(1000);

Serial.println("Delete All Previous Messages");


SIM808("AT+CMGD=1,4");
delay(2000);

value = SIM808("AT+CMGL=\"REC UNREAD\"");


value = SIM808("AT+CMGL=\"REC UNREAD\"");
value = SIM808("AT+CMGL=\"REC UNREAD\"");

do {
delay(2000);
Serial.println("No new Messages Received");
Serial.println("Check for New Messages!");
value = SIM808("AT+CMGL=\"REC UNREAD\"");
//Serial.println("end");
} while (value == "OK");

SIM808("AT+CMGL=\"REC UNREAD\"");
Serial.println("Message Recieved");

value = SIM808("AT+CMGL=\"ALL\"");
Serial.println(value);
phone_number = value;
phone_number.remove(0, 20);
phone_number.remove(15, phone_number.length());
message_text = value;
message_text.remove(0, 63);
message_text.remove(message_text.length() - 6, message_text.length());

Serial.println("Phone Number:");
Serial.println(phone_number);

Serial.println("Message Text:");
Serial.println(message_text);

if (message_text == password) {
GetGPS_flag = true;
Password_flag = true;
Serial.println("password is correct!");
}

// GET GPS
if (GetGPS_flag) {
do {
Serial.println("Power Down The GPS");
SIM808("AT+CGPSPWR=0");
//Serial.println("end");

Serial.println("Check The GPS Power");


value = SIM808("AT+CGPSPWR?");
value.remove(11, 17);
Serial.println(value);
//Serial.println("end");

You might also like