TinyGPS + SIM900 + Arduino = Vehicle tracking device

Hi everyone,

I’ve been asked to implement a project that may be slightly above my station/ability. My uncle owns a landscaping business, last season his truck was stolen from the front of a clients house while he was working out back. Loss of vehicle = major loss of business revenue. There is a very nice Instructable http://www.instructables.com/id/Athena-The-Global-Car-Tracking-System/ on how to do just what I need, but I need to take it a little further…

Here is the original, unmodified code;

//Program written for Global Car Tracking System by Jayvis Gonsalves
#include <SoftwareSerial.h>
#include <string.h> 
#include <TinyGPS.h>
SoftwareSerial Sim900Serial(2, 3);
byte buffer[64];                             // buffer array for data recieve over serial port
int count=0;                                 // counter for buffer array
SoftwareSerial GPS(4, 5);
TinyGPS gps;
unsigned long fix_age;
long lat, lon;
float LAT, LON;
void gpsdump(TinyGPS &gps);
bool feedgps();
void getGPS();
void setup()
{
  Sim900Serial.begin(19200);     // the SIM900 baud rate
  GPS.begin(9600);                   // GPS module baud rate  
  Serial.begin(9600);                  // the Serial port of Arduino baud rate.
  delay(500);
  Sim900_Inti();
}
 
void loop()
{
  Sim900Serial.listen();
  if (Sim900Serial.available())                     // If date is comming from from GSM shield)
  {
    while(Sim900Serial.available())              // reading data into char array 
    {
      buffer[count ]=Sim900Serial.read();  // writing data into array
      if(count == 64)break;
     }
    Serial.write(buffer,count);                     // if no data transmission ends, write buffer to hardware serial port
    Cmd_Read_Act();                               //Read the 'COMMAND' sent to SIM900 through SMS
    clearBufferArray();                               // call clearBufferArray function to clear the storaged data from the array
    count = 0;                                          // set counter of while loop to zero
 
 
  }
  if (Serial.available())                       // if data is available on hardwareserial port ==> data is comming from PC or notebook
    Sim900Serial.println(Serial.read());       // write it to the GPRS shield
}
void clearBufferArray()                             // function to clear buffer array
{
  for (int i=0; i<count;i )
    { buffer[i]=NULL;}                                // clear all index of array with command NULL
}
void Sim900_Inti(void)
{
  Sim900Serial.println("AT CMGF=1");    // Set GSM shield to sms mode
  Serial.println("AT CMGF=1");
  delay(500);
  Sim900Serial.println("AT CNMI=2,2");
  Serial.println("AT CMGF=1");
  delay(500);
}
void Cmd_Read_Act(void)                       //Function reads the SMS sent to SIM900 shield.
{ 
  char buffer2[64];
  for (int i=0; i<count;i )
  { buffer2[i]=char(buffer[i]);}  
    
  if (strstr(buffer2,"INSTRUCTABLES"))    //Comparing password entered with password stored in program  
  {
      Serial.println("Password Authenticated.");
      Serial.println("Sending reply SMS. ");
      SendTextMessage();            
  }
  
}
void SendTextMessage()
{
  
  
Sim900Serial.print("AT CMGF=1\r");    //Sending the SMS in text mode
delay(100);
Sim900Serial.println("AT CMGS = \"**********\"");//The predefined phone number
delay(100);
Sim900Serial.println("Please wait while Module calculates position");//the content of the message
delay(100);
Sim900Serial.println((char)26);//the ASCII code of the ctrl z is 26
delay(100);
Sim900Serial.println();
int counter=0;
GPS.listen();


for (;;)
{
   long lat, lon;
   unsigned long fix_age, time, date, speed, course;
   unsigned long chars;
   unsigned short sentences, failed_checksum;
   long Latitude, Longitude;
    
   // retrieves /- lat/long in 100000ths of a degree
   gps.get_position(&lat, &lon, &fix_age);
   getGPS();
   Serial.print("Latitude : ");
   Serial.print(LAT/1000000,7);
   Serial.print(" :: Longitude : ");
   Serial.println(LON/1000000,7);
   if (LAT == 0 && LON == 0)
  {
    continue;    
  } 
  counter ;
  if (counter<30)
  {
    continue;    
  }
  
  Sim900Serial.print("AT CMGF=1\r");    //Sending the SMS in text mode
  delay(100);
  Sim900Serial.println("AT CMGS = \"**********\"");//The predefined phone number
  delay(100);
  Sim900Serial.print("Latitude : ");
  Sim900Serial.print(LAT/1000000,7);
  Sim900Serial.print(" :: Longitude : ");
  Sim900Serial.println(LON/1000000,7);//the content of the message
  delay(100);
  Sim900Serial.println((char)26);//the ASCII code of the ctrl z is 26
  delay(100);
  Sim900Serial.println();
  counter=0;
  break;
 }      
}

void getGPS()
{
   bool newdata = false;
   unsigned long start = millis();
   while (millis() - start < 1000)
   {
      if (feedgps ())
      {
         newdata = true;
       }
     }
     if (newdata)
   {
      gpsdump(gps);
    }
}
bool feedgps()
{
   while (GPS.available())
 {
      if (gps.encode(GPS.read()))
        return true;
      }return 0;
}
void gpsdump(TinyGPS &gps)
{
   gps.get_position(&lat, &lon);
   LAT = lat;
   LON = lon;
   {
      feedgps(); 
    }
  }

I’ve been trying to make a few slight modifications to the code, one is. Seen as most phones these days are smartphones, I want to include a google maps link so you can click direct from the text to your vehicles location.

The google maps URL system is pretty straightforward, just

https://maps.google.com/maps?q=46.352524+N+7.22842

So I was hoping including this to the text message would generate a URL to point to the vehicles location. My code for that section is like this;

Sim900Serial.println("AT CMGS = \"**********\"");//The predefined phone number

delay(100);

Sim900Serial.print("LAT: ");

Sim900Serial.println(LAT/1000000,7" N");

Sim900Serial.print("LON : ");

Sim900Serial.println(LON/1000000,7" W");//the content of the message

Sim900Serial.println("");

Sim900Serial.println"Google maps URL: https://maps.google.com/q="LAT/1000000,7"+N+"LON/1000000,7"+W");

delay(100);

Sim900Serial.println((char)26);//the ASCII code of the ctrl z is 26

Hopefully that should generate a google maps URL to the vehicles location, unless anybody can spot any problems… (In Ireland the only co-ordinates are N&W, that covers the whole country)

Then the final 2 modifications I wished to make are;

  1. To include the Speed and Heading in response the text.
  2. To add a continuous mode, ie the info is sent every 5 (or whatever variable) mins.

I would like to be able to text “locate” to the SIM900 and receive the current Lat & Lon, Speed (if any), Course/Heading, and a google maps URL that contains the data.

Then if stolen/missing texting “stolen” or “continuous” will keep feeding this info, until “stop” is received, then the unit reverts to standby.

I would greatly appreciate some help here, they are probably fairly minor code changes for one who knows what he/she is doing. Either way, thank you for reading and anything you have to offer…

Not a specific answer to your question, but just a few subjects below is this one:

http://forum.arduino.cc/index.php?topic=236595.msg1700978

dannable: Not a specific answer to your question, but just a few subjects below is this one:

http://forum.arduino.cc/index.php?topic=236595.msg1700978

Thanks,

Sorry, I've had the Arduino Forums page open on my computer for about a week before I posted so didn't see that one.

I haven't encountered any problems yet, all tests have gone ok.

So if this thread could be used to address the questions I asked, and the aachally's thread could be used to help him diagnose his issues.

Of course I will check in from time to time and make sure there is nothing of use to me there!!

Hi everyone, my car was stolen from the front of my home. There is a very nice Instructable http://www.instructables.com/id/Athena-The-Global-Car-Tracking-System/ , but I i doesnt work properly...the compilation completed without errors but the gsm module cant receive the any sms...am using 1.sim900a gsm 2.tiny gps 3.arduino uno it doesnt work.....ANYONE PLZZZ HELP ME

am using 1.sim900a gsm 2.tiny gps 3.arduino uno it doesnt work.....ANYONE PLZZZ HELP ME

Something like that has to be broken into pieces.

And, while working with "the pieces", be careful that no pin is being used for more than one job in the overall eventual goal.

So...

1) A program to send "hello world" via the Sim9000 (Ah! The Sim900*A* may not work outside of the far east. I don't KNOW this, but I've heard it said you need the "A-less" variant, if not in the far east.)

2) A program to send the current lat/long to the serial monitor. What's serial monitor? A marvelous tool for MANY things...

http://sheepdogguides.com/arduino/aht1serimoni.htm

=== Using shields? You may find that shield "A" and shield "B" BOTH use one or more specific pins... and that the usage by the two shields conflict.

As suggested in the 'sticky' at the top of the page, 'How to use the forum', post the code you are using and links to the components (and any third party libraries).

OK, i know im a little late to the party on this one, but i have just a few questions that i cannot find answers to if someone would be so kind as to answer please.

Did anybody have any success with posting a google link in the message as you mentioned in your initial post? I'd like to do this too, or alternatively just have a web address or app that i can use and see the location.

And finally, lets say i have my arduino uno, my gps module, and my SIM900 gsm/gprs module all hooked up to a power source with my sim card insterted etc. and i want to use my iphone to track the gps device i've built - will it cost me in data/sms when the device is relaying the NMEA data? So in other words will i have to keep topping up the PAYG sim?

Cheers, Tom-