Realtime GPS Tracker w. SD Card Logger Part 2 | Google Maps Link

This article shows how to build a realtime text message GPS tracker with integrated SD card logger. It allows coarse realtime tracking and more precise post analysis through the logged data.

Not too long ago I wrote an article featuring a Realtime GPS Tracker w. SD Card Logger. That project sends raw NMEA [1] sentences via text message and logs them onto a SD card as well. This project is taking it a bit further. Not only is the logging frequency and text frequency independent now, but it also sends a clickable Google maps link via text message.

20160122_202315

The circuit is quite simple. It utilizes the seed SD card shield V4.0 and the GPRS Shield V2.0. The GPRS shield needs to be set to hardware serial via jumper. Pin 7 of the arduino needs to be connected to the TX line of the GPS module. In my case the GPS has a bitrate of 4800 bps. It’s a very common bitrate for navigation instruments as per NMEA 0183 standard.

The code utilizes a library called TinyGPS++ [2]. It ingests GPS messages and parses them. It makes the Google Maps link assembly a whole lot easier. IT also allows for a custom logging format for the SD card file.


/*
Realtime GSM GPS Tracker

Created: 01/22/2016
by Sebastian Westerhold
KF5OBS

This example code is in the public domain.

SD Card uses SEED SD Card Shield v. 4.0
CS - pin 4

Connect GPS Module to PIN 7 on UNO
Connect GPS Module to Serial 1 RX on Due

*/

#include
#include

// Soft Serial for UNO, comment out for Due
#include
SoftwareSerial Serial1(7, 8);

// Include GPS Library
#include "TinyGPS++.h"
TinyGPSPlus gps;

// Set up necessary variables
const int chipSelect = 4;
int counter = 100;
char message[160];
char latitude[12];
char longitude[12];

// Setup routine
void setup() {

// Initiate Serial at 4800 baud
Serial.begin(19200);

// Wait for serial to become available
while (!Serial) {
}

// Initiate serial for GPS module
Serial1.begin(4800);

// Iinitialize the SD card
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("done.");

// Set mode to text
Serial.print("AT+CMGF=1\r");

// Give GSM module some start-up time
delay(10000);
}

// Function to send text message
void sendSMS(String message)
{
// AT command to initiate text message
Serial.print("AT+CMGF=1\r");
delay(100);
// AT command to set destination number
Serial.println("AT + CMGS = \"+15015559350\"");
delay(100);
// Message body
Serial.println(message);
delay(100);
// Termination character
Serial.println((char)26);
delay(100);
// \n
Serial.println();
}

// Main routine
void loop() {

// If there's serial data int he buffer, add to dataString
while(Serial1.available() >0)
{
// Feed it to the GPS engine
gps.encode(Serial1.read());
}

// If the location info is valid...
if (gps.location.isValid()) {

// Open file on SD Card
File dataFile = SD.open("NMEA.txt", FILE_WRITE);

// IF the file is opened successfully...
if (dataFile) {

// Assemble SC Card Line
//** Assemble Date DD.MM.YYYY
dataFile.print(gps.date.day());
dataFile.print(".");
dataFile.print(gps.date.month());
dataFile.print(".");
dataFile.print(gps.date.year());

dataFile.print(",");

//** Assemble time HH:MM:SS
dataFile.print(gps.time.hour());
dataFile.print(":");
dataFile.print(gps.time.minute());
dataFile.print(":");
dataFile.print(gps.time.second());

dataFile.print(",");
dataFile.print(gps.location.lat());
dataFile.print(",");
dataFile.print(gps.location.lng());
dataFile.print(",");
dataFile.print(gps.speed.kmph());
dataFile.print(",");
dataFile.print(gps.course.deg());
dataFile.print(",");
dataFile.print(gps.altitude.meters());
dataFile.print(",");
dataFile.print(gps.satellites.value());
dataFile.print(",");
dataFile.print(gps.hdop.value());
dataFile.println("");

// Close the SD card file
dataFile.close();

// wait for 10 seconds
delay(10000);

}

// If there's any errors, so say via serial.
else {
Serial.println("error opening NMEA.txt");
}

// Only send texts every 30 cycles (~ 10 Minutes)
if (counter > 6*10)
{
// Assemble Text Message
strcpy(message, "http://maps.google.com/");
strcat(message, "maps?z=12&t=m&q=loc:");
dtostrf(gps.location.lat(), 1, 6, latitude);
strcat(message,latitude);
strcat(message,"+");
dtostrf(gps.location.lng(), 1, 6, longitude);
strcat(message,longitude);
strcat(message,"");

// Send via text
sendSMS(message);
counter=0;
}

}

counter++;
}

You can download the code here: GSM_Track_SD_Card_UNO_GPS__

Please remember to change the target phone number!

If everything is connected correctly and the GPS signal is valid, it’ll log a GPS position about every 10 seconds and send a position text about every 10 minutes.

GPS_Logger_Text

The text messages contain a clickable Google Maps link.

Screenshot_2016-01-23-13-06-54

Links and Sources:

[1] NMEA 0183, Wikipedia: https://en.wikipedia.org/wiki/NMEA_0183

[2] TinyGPS++: http://arduiniana.org/libraries/tinygpsplus/

Leave a Reply