Introduction: Share Location With SMS

About: Electronics Component - PCB [Design, Printing, Inserting] - Electronic Programming

This post will discuss how to send the location of GPS (longitude and latitude) with SIM800L v.2. The workflow of this tool is the GPS module reading the value of longitude and latitude, then they will be sent via SIM800l v.2. Since these 2 modules use serial communications, before reading this module, you must declare which serial port you want to activate by giving mySerial.listen () command.

Step 1: Material You Needs

Step 2: Schematic

Connect each components according to the schematic above.

Step 3: Step by Step

First, download Library Tiny GPS ++ here, then add to arduino libraries.

Then, enter the following program to test the function of GPS, do not forget to see the network indicator of GPS. If the LED indicator network is blinking then the GPS module has signal, if not wait until 5 minutes.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
SoftwareSerial serial_gps(3, 2); // RX = pin 10, TX = pin 11
TinyGPSPlus gps; double latitude, longitude;
void setup() {
Serial.begin(9600);
serial_gps.begin(9600);
Serial.println("GPS Mulai");
}
void loop() {
serial_gps.listen();
while(serial_gps.available()) {
gps.encode(serial_gps.read());
}
if(gps.location.isUpdated()) {
latitude = gps.location.lat();
longitude = gps.location.lng();
String link = "http://www.google.com/maps/place/" + String(latitude) + "," + String(longitude) ;
Serial.print("Link Google Maps : ");
Serial.println(link);
Serial.print("Satellite Count : ");
Serial.println(gps.satellites.value());
Serial.print("Latitude : ");
Serial.println(latitude, 6);
Serial.print("Longitude : ");
Serial.println(longitude, 6);
Serial.print("Speed MPH : ");
Serial.println(gps.speed.mph());
Serial.print("Altitude Feet : ");
Serial.println(gps.altitude.feet());
Serial.println("");
} }

If the longitude and latitude data of GPS are known, you can go to the next step, which is sending the SMS to the destination number. GSM SMS command only need 4 steps, namely set GSM module to text mode, then command fill destination number, enter contents of SMS, then send character ENTER to enter SMS contents and also to send SMS. First we create a function / method for parsing the response data from SIM800, and its function.

void atCommand(String iCommand, int timing, char myText[])
{ String onOff = String(myText); Serial.println("###Start###"); Serial.print("Command Ke ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "); Serial.print(counterCommand); Serial.print(" Kirim=>");Serial.println(iCommand); while(timing>z) { mySerial.println(iCommand); if(mySerial.find(myText)) { found = true; break; } Serial.print(z);Serial.print(","); z++; } if(found == true) { autoReset = false; counterCommand++; Serial.println("==============================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> oke"); } else { mySerial.write("AT+CMGF=1"); delay(1000); mySerial.write("AT+CMGD=1,4"); delay(1000); Serial.print("nautoReset=truen"); autoReset = true; Serial.println("--------============>>>>>>>> AT Command Error"); Serial.println("--------============>>>>>>>> Proses reset"); //digitalWrite(resetPin, HIGH); //delay(200); //digitalWrite(resetPin, LOW); //delay(15000); counterCommand = 0; } if(counterCommand >=100) { counterCommand = 0; } found = false; z=0; Serial.println("***end***"); }

The plot of the function is the serial software port sending commands from AT-Command until the specified time. If
the serial software port gets a reply in the form of a character corresponding to the desired one, then the command from the AT-command is considered successful. And if the reply given does not match the desire then SIM800L will be reset by providing low logic on pin RESET SIM800L.

The main program as follows:

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
SoftwareSerial serial_gps(3, 2); // RX = pin 10, TX = pin 11 SoftwareSerial mySerial(5, 4); TinyGPSPlus gps; double latitude, longitude;<br>int z,counterCommand; boolean found = false; boolean autoReset = false;<br>void setup() { Serial.begin(9600); serial_gps.begin(9600); mySerial.begin(9600); Serial.println("GPS Mulai"); //## order of AT-Command to remove when tool is first turned on ##//
mySerial.listen(); while(counterCommand<=3)// meaning that if the order at command is less than 3 then do below
{ switch(counterCommand) { case 0: atCommand("AT",1,"OK");break; // order at command 1: test micro communication with SIM case 1: atCommand("AT+CMGF=1",1,"OK");break;// order 2: setting SIM800 with mode text case 2: atCommand("AT+CMGL="ALL",0",2,"OK");break;//3: read all saved messages without changing the status. // the intent of the status is if the sms has not been read then it will not be changed to<br> // readable if using this at command case 3: atCommand("AT+CMGD=1,4",1,"OK");break; // delete the entire contents of the sms on the card (just in case when the sms operatore)<br> } } //############################## counterCommand = 0;// the order is made 0 to do the program that is in the loop<br>}<br>void loop() { serial_gps.listen(); while(serial_gps.available()) { gps.encode(serial_gps.read()); } if(gps.location.isUpdated()) { latitude = gps.location.lat(); longitude = gps.location.lng(); String valLat = String(latitude); String valLong = String(longitude); String link = "http://www.google.com/maps/place/" + String(latitude) + "," + String(longitude) ; Serial.print("Link Google Maps : "); Serial.println(link); Serial.print("Satellite Count : "); Serial.println(gps.satellites.value()); Serial.print("Latitude : "); Serial.println(latitude, 6); Serial.print("Longitude : "); Serial.println(longitude, 6); Serial.print("Speed MPH : "); Serial.println(gps.speed.mph()); Serial.print("Altitude Feet : "); Serial.println(gps.altitude.feet()); Serial.println(""); mySerial.listen(); atCommand("AT+CMGF=1",1,"OK"); atCommand("AT+CMGS="+6281553718364"",1,">"); atCommand("Latitude:""+valLat+"",Longitude""+valLong+""",1,">"); Serial.println("Mengirim Char Ctrl+Z / ESC untuk keluar dari menu SMS"); mySerial.write((char)26); delay(10000); } //delay(10000); } void atCommand(String iCommand, int timing, char myText[]) { String onOff = String(myText); Serial.println("###Start###"); Serial.print("Command Ke ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "); Serial.print(counterCommand); Serial.print(" Kirim=>");Serial.println(iCommand); while(timing>z) { mySerial.println(iCommand); if(mySerial.find(myText)) { found = true; break; } Serial.print(z);Serial.print(","); z++; } if(found == true) { autoReset = false; counterCommand++; Serial.println("==============================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> oke"); } else { mySerial.write("AT+CMGF=1"); delay(1000); mySerial.write("AT+CMGD=1,4"); delay(1000); Serial.print("nautoReset=truen"); autoReset = true; Serial.println("--------============>>>>>>>> AT Command Error"); Serial.println("--------============>>>>>>>> Proses reset"); //digitalWrite(resetPin, HIGH); //delay(200); //digitalWrite(resetPin, LOW); //delay(15000); counterCommand = 0; } if(counterCommand >=100) { counterCommand = 0; } found = false; z=0; Serial.println("***end***"); }

The program above will read and send the location (longitude and latitude ofGPS module) every 10 seconds.

Step 4: Check the Result

Step 5: Check the Result

Wireless Contest

Participated in the
Wireless Contest