Arduino Projects

How to Track my Car Location using Arduino, GPS, & GSM, Locate my Car

How to Track my Car Location using Arduino:

 

How to Track my Car Location- In this article, I am going to track my Car location using Arduino, Neo 6M GPS Module, and the GSM SIM900A Module. I have also added some other cool features, which I will practically test in a minute.

In my previous project, I implemented Geofencing technology in an attempt to reinforce my car security. As I have elaborated in my previous article, you can define a virtual boundary around any area with the help of Geofencing by means of using GPS coordinates.

Car Location

In a similar fashion, I built up a virtual fence for my car so that whenever my car happened to go out of that prescribed area, I received an alert message on my cell phone which prompted me that “the car is outside the fence”.


Car Location

Geofencing technology can be applied in order to track any sort of thing. It can indicate when does a car or any other vehicle or thing enters that particular area or leaves it. So if you are interested too to implement and take advantage of the all-important Geofencing technology, you must inevitably read my previous article. Anyhow, let us move toward our original topic “how to track my car location

Nowadays, the ratio of car stealing has enhanced to a shocking extent throughout the world. If a car has been stolen and no tracker was fixed on it, it virtually becomes impossible to locate that car.  You can do nothing about your stolen car, except that you have extraordinary level contacts and try and track your car through its number by means of checking each and every CCTV footage. However, it is hard for everyone to have access to these high-level contacts and utilize such a procedure in order to locate a pilfered car.

So, if we are not lucky enough to have contacts or huge approaches, then it is compulsory that we purchase or otherwise manufacture some type of a GPS tracking system, so as to track our car. As an engineer, I shall prefer, that I design a customized GPS tracking system for my car, where I may add some extra features according to my choice and needs.

Car Location

Here, is a prototype model of my Arduino-based GPS tracking system, the finalization work of which, is still in progress. When all the testing tasks have been finished, then I will design a PCB and an enclosure for it. Anyways, the features which I have added until now, include:



Features:

  1. Tracking a car location, however without any need for recourse to an internet service or any type of online dashboard. We can just find out the location of our car with the help of a cell phone. We have to send just an SMS from our cell phone and the tracking system will send us the Car’s GPS coordinates along with the Google’s map URL link. And then with the help of Google Map, we can track the exact location of our car. This is really an amazing feature, through which you can learn about the precise location of your car at any moment.
  2. I have also added a feature of speed monitoring into it. Mostly, my brothers drive the car and I do not want them to indulge in over-speeding. So, whenever they cross a certain speed limit, a buzzer will beep loudly in the car. It will keep honking until the car speed has been reduced to the desired limits.

If you want, that along with a buzzer, a message may also be passed on to the near and dears one back at home, you have to modify my program slightly, which can be done quite easily. When you study the code, you will have an idea of where the modification is going to be desired.

  1. The third feature is an extremely important one, which is accident monitoring. During accidents, people do not often have that much time to resort to their cell phones in order to get family members informed about the incident. Therefore, I have added this button for demonstration purposes. As soon as this button is pressed, an accident alert message will be delivered to family members who will also have GPS coordinates of the accident location. You can employ such buttons or limit switches or sensors anywhere on your car’s front, back, or along its sides. You have to do just a little adjustment in the program.

I think we have discussed the topic fairly well, now let’s practically check this system.


Altium Designer & Altium 365:

Car Location

Altium 365 lets you hold the fastest design reviews ever. Share your designs from anywhere and with anyone with a single click. it’s easy, leave a comment tagging your teammate and they’ll instantly receive an email with a link to the design. Anyone you invite can open the design using a web browser. Using the browser interface, you’re able to comment, markup, cross probe, inspect, and more. Comments are attached directly to the project, making them viewable within Altium designer as well as through the browser interface. Design, share, and manufacture, all in the same space with nothing extra to install or configure. Connect to the platform directly from Altium Designer without changing how you already design electronics. Altium 365 requires no additional licenses and comes included with your subscription plan. Start with Altium Designer and Activate Altium 365.


Practical Testing:

For the demonstration purposes, my brother is going to steal the car and after reaching a certain location, he will stop it. I have no idea about that location and so I will have to find out my car’s location with the help of my Arduino-based tracking system and smartphone. So let’s do it.

Twenty minutes have passed since my brother has driven away the car. Now, I am going to find the car’s location. I have done its programming in such a way that if I send a blank message or write any character in the message, the tracking system will respond in both situations.

Car Location

I have received a reply from my tracking system. You can see there is a Google map URL link. I can determine the exact location of my car by clicking on this link.

Car Location

I guide you along with my phone’s screen towards that location, so that you may understand and see everything by yourself. Here are the GPS coordinates of my car’s location. Now if I click on start, Google Map will show me the approximate time as well as indicate the approximate direction.

Car Location


So let us move on a bike towards the location. It took me around 3 minutes to get to my Car’s location.

Car Location

And here it is my car which we have located with the help of an Arduino-based GPS tracking system.

Car Location

As I have mentioned in the beginning, I have also introduced an accident location tracking feature in this system, it also works similarly. The only difference is that in case of an accident, it sends a message automatically. I have fixed a button on the front bumper of my car. As soon as it is pressed, I immediately receive an accident alert message.

Car Location

Now let us check our speed monitoring feature. For this purpose, I am about to sit in my car and practically see what happens when the car speed exceeds the speed limit, whether the buzzer turns ON or not.  I set the maximum speed limit of 50 Km/h. When the car speed exceeded 50km/h the buzzer was activated, you can practically watch this in the video which is given at the end of this article.

So far, my designed GPS car tracking system has done everything perfectly and I also feel delighted about it, in the future, I am planning to add some extra features to it. That’s when somebody tries to open a car’s door or its bonnet, I receive a message on my cell phone or maybe some other feature, you can also tell me in a comment, which features I need to add. Now, you have got an idea of what exactly you are going to learn after watching this video. So, without any further delay, let’s get started!!!



Amazon Links:

Arduino Nano

Neo 6M GPS

GSM SIM900A

Top GPS Trackers

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Arduino Neo 6M GPS module issue!

Car Location

You don’t have to be worried if you see something like this on your Arduino Serial monitor. Sometimes GPS module takes several minutes to connect with the Satellites. When using a GPS module, make sure you are not inside a big building, basement, etc. Try, find an open space. Sometimes GPS module even takes 30 minutes. If you can see the date and time then it’s a good signal that your GPS module has no issues. The same thing happened to me too. Anyways, I waited and then my GPS module started giving me the exact latitude and longitude values.

Car Location

GSM and GPS interfacing with Arduino:

Car Location

All the electronics are powered up using a 5Volts regulated power supply, make sure the power supply is around 2A. The RXD and TXD pins of the GSM Sim900A module are connected with the Arduino pins D8 and D7. The RXD and TXD pins of the Neo 6M GPS Module are connected with the Arduino pins D10 and D9 respectively. A pushbutton is connected with the Arduino Pin D12.


Car location Tracking Arduino Programming:

// Car Location Tracking using Arduino, GSM SIM900A, and Neo 6M GPS Module
// electroniclinic.com

#include <SoftwareSerial.h>
#include <stdlib.h>
#include <TinyGPS++.h>

static const int RXPin = 9, TXPin = 10;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin); // for gps
SoftwareSerial SIM900(7, 8); // for gsm module

  int A_Sensor = 12; // accident monitoring sensor, pushbutton or you can use any other digital sensor
  int Buzzer = 5;   // Buzzer is connected with pin 5 of the Arduino
  
  char inchar; // Will hold the incoming character from the GSM shield
  String textForSMS; // stores the alert message
  
  double longitude; // stores the longitude value
  double latitude;  // stores the Latitude value
  char buff[10];
  
  String mylong = ""; // for storing the longittude value
  String mylati = ""; // for storing the latitude value

   int gpsflag = 0;
  
   int mycounter = 0;
  

   
void setup()
{
  SIM900.begin(19200);
  Serial.begin(9600);
  ss.begin(GPSBaud);
  delay(5000);  // give time to log on to network. 
  Serial.println(" logging time completed!");
  randomSeed(analogRead(0));
  pinMode(A_Sensor, INPUT_PULLUP);
  pinMode(Buzzer, OUTPUT);

}
 

 
void sendSMS(String message)
{
  SIM900.print("AT+CMGF=1\r");                     // AT command to send SMS message
  delay(100);
 SIM900.println("AT + CMGS = \"+923339537499\"");  // recipient's mobile number, in international format
  delay(100);
  SIM900.println(message);                         // message to send
  delay(100);
  SIM900.println((char)26);                        // End AT command with a ^Z, ASCII code 26
  delay(100); 
  SIM900.println();
  delay(5000);                                     // give module time to send SMS
                                  
}
 
void loop()
{

 
    // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0)
    if ((gps.encode(ss.read())) && (gpsflag == 0))
    {
     displayInfo();    
    gpsflag = 1;
    }

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while(true);
  }
 // for the A_Sensor 
//*****************************************************************
//****************************************************************
  if(digitalRead(A_Sensor) == LOW)
  {
 displayInfo();
 latitude = gps.location.lat(), 6 ;
 longitude = gps.location.lng(), 6 ;
// for latitude
  mylati = dtostrf(latitude, 3, 6, buff);
  mylong = dtostrf(longitude, 3, 6, buff);
  
 //textForSMS = textForSMS + "Latitude:" + "," + mylati + "," + "Longitude:  "+ mylong + ",";
 textForSMS = "Accident:\n ";
 textForSMS = textForSMS + "http://www.google.com/maps/place/" + mylati + "," + mylong ; 
  sendSMS(textForSMS);
    textForSMS = "";
  Serial.println(textForSMS);
  Serial.println("message sent.");
  delay(2000);
  }

 displayInfo();

 if (gps.speed.kmph() > 50 )
{
  digitalWrite(Buzzer, HIGH); 
}

 if (gps.speed.kmph() < 50 )
{
  digitalWrite(Buzzer, LOW); 
}

mycounter = mycounter + 1; 

if ( (mycounter > 50) && ( mycounter < 100))
{
  gpsflag = 0; 
  ss.begin(GPSBaud);
}



if ( mycounter > 100 )
mycounter = 0;



if(gpsflag == 1)  
 {

 SIM900.begin(19200); // we again activate the serial communication.
    if(SIM900.available() > 0)
  {
Serial.println("message received:");
   inchar=SIM900.read(); 
  Serial.println(inchar);
  
   displayInfo();
latitude = gps.location.lat(), 6 ;
longitude = gps.location.lng(), 6 ;

  mylati = dtostrf(latitude, 3, 6, buff);
  mylong = dtostrf(longitude, 3, 6, buff);
  
 textForSMS = textForSMS + "http://www.google.com/maps/place/" + mylati + "," + mylong ; 
  sendSMS(textForSMS);
    textForSMS = "";
  Serial.println(textForSMS);
  Serial.println("message sent.");
  inchar = 'z'; // garbage value
 
  delay(2000);
  gpsflag = 0; 
  ss.begin(GPSBaud); // we again activate the gps module, so now gps will work and gsm will not..
  delay(100);


    
  }


 }


}

 


void displayInfo()
{
  Serial.print(F("Location: ")); 
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
    Serial.print(" ");
    Serial.print(F("Speed:"));
    Serial.print(gps.speed.kmph());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.println();

}


Code explanation:

These are the same libraries I have been using in all of my GPS based projects.

#include <SoftwareSerial.h>

#include <stdlib.h>

#include <TinyGPS++.h>

Next, I defined pins for the GPS and GSM modules.

static const int RXPin = 9, TXPin = 10;

static const uint32_t GPSBaud = 9600;




// The TinyGPS++ object

TinyGPSPlus gps;


// The serial connection to the GPS device

SoftwareSerial ss(RXPin, TXPin); // for gps

SoftwareSerial SIM900(7, 8); // for gsm module

I also defined a pin to which a pushbutton is connected.

int A_Sensor = 12;

I also defined a pin for the Buzzer.

int Buzzer = 5;

Finally, I defined some variables which are well commented.

char inchar; // Will hold the incoming character from the GSM shield

  String textForSMS; // stores the alert message

  double longitude; // stores the longitude value

  double latitude;  // stores the Latitude value

  char buff[10];

  String mylong = ""; // for storing the longittude value

  String mylati = ""; // for storing the latitude value

   int gpsflag = 0;

   int mycounter = 0;

Inside the setup() function, we activate the GSM module, serial communication, and GPS module. I defined the pushbutton as the input and Buzzer as the output.

void setup()

{

  SIM900.begin(19200);

  Serial.begin(9600);

  ss.begin(GPSBaud);

  delay(5000);  // give time to log on to network.

  Serial.println(" logging time completed!");

  randomSeed(analogRead(0));

  pinMode(A_Sensor, INPUT_PULLUP);

  pinMode(Buzzer, OUTPUT);




}

sendSMS() function is a user-defined function which has no return type and takes only one variable as the argument which is of the type string. Inside this function, we define the number on which we want to send the message.

void sendSMS(String message)

{

  SIM900.print("AT+CMGF=1\r");                    // AT command to send SMS message

  delay(100);

 SIM900.println("AT + CMGS = \"+923339537499\"");  // recipient's mobile number, in international format

  delay(100);

  SIM900.println(message);                         // message to send

  delay(100);

  SIM900.println((char)26);                        // End AT command with a ^Z, ASCII code 26

  delay(100);

  SIM900.println();

  delay(5000);                                     // give module time to send SMS

                                  

}



Inside the loop function, we constantly check if any data is available from the GPS module, then we read and encode the data, and then immediately the displayInfo() function is called.

  while (ss.available() > 0)

    if ((gps.encode(ss.read())) && (gpsflag == 0))

    {

     displayInfo();   

    gpsflag = 1;

    }

Let’s take a look at the displayInfo() function. The purpose of the displayInfo() function is to read the Latitude, longitude, and speed in kilometers per hour. You can also use this other information but for now, I am only interested in latitude, longitude, and speed values.

void displayInfo()

{

  Serial.print(F("Location: "));

  if (gps.location.isValid())

  {

    Serial.print(gps.location.lat(), 6);

    Serial.print(F(","));

    Serial.print(gps.location.lng(), 6);

    Serial.print(" ");

    Serial.print(F("Speed:"));

    Serial.print(gps.speed.kmph());

  }

  else

  {

    Serial.print(F("INVALID"));

  }




  Serial.print(F("  Date/Time: "));

  if (gps.date.isValid())

  {

    Serial.print(gps.date.month());

    Serial.print(F("/"));

    Serial.print(gps.date.day());

    Serial.print(F("/"));

    Serial.print(gps.date.year());

  }

  else

  {

    Serial.print(F("INVALID"));

  }




  Serial.print(F(" "));

  if (gps.time.isValid())

  {

    if (gps.time.hour() < 10) Serial.print(F("0"));

    Serial.print(gps.time.hour());

    Serial.print(F(":"));

    if (gps.time.minute() < 10) Serial.print(F("0"));

    Serial.print(gps.time.minute());

    Serial.print(F(":"));

    if (gps.time.second() < 10) Serial.print(F("0"));

    Serial.print(gps.time.second());

    Serial.print(F("."));

    if (gps.time.centisecond() < 10) Serial.print(F("0"));

    Serial.print(gps.time.centisecond());

  }

  else

  {

    Serial.print(F("INVALID"));

  }




  Serial.println();




}

If the pushbutton is pressed, which I am using for the car hit detection, an accident alert message is sent to the concerned person. The message consists of Google’s map URL link and the latitude and longitude values.

if(digitalRead(A_Sensor) == LOW)

  {

 displayInfo();

 latitude = gps.location.lat(), 6 ;

 longitude = gps.location.lng(), 6 ;

// for latitude

  mylati = dtostrf(latitude, 3, 6, buff);

  mylong = dtostrf(longitude, 3, 6, buff);




 //textForSMS = textForSMS + "Latitude:" + "," + mylati + "," + "Longitude:  "+ mylong + ",";

 textForSMS = "Accident:\n ";

 textForSMS = textForSMS + "http://www.google.com/maps/place/" + mylati + "," + mylong ;

  sendSMS(textForSMS);

    textForSMS = "";

  Serial.println(textForSMS);

  Serial.println("message sent.");

  delay(2000);

  }




These lines of code are used for speed monitoring.




if (gps.speed.kmph() > 50 )

{

  digitalWrite(Buzzer, HIGH);

}




 if (gps.speed.kmph() < 50 )

{

  digitalWrite(Buzzer, LOW);

}




If the GSM module has received any message then the same data is sent to the concerned person.




    if(SIM900.available() > 0)

  {

Serial.println("message received:");

   inchar=SIM900.read();

  Serial.println(inchar);




   displayInfo();

latitude = gps.location.lat(), 6 ;

longitude = gps.location.lng(), 6 ;




  mylati = dtostrf(latitude, 3, 6, buff);

  mylong = dtostrf(longitude, 3, 6, buff);




 textForSMS = textForSMS + "http://www.google.com/maps/place/" + mylati + "," + mylong ;

  sendSMS(textForSMS);

    textForSMS = "";

  Serial.println(textForSMS);

  Serial.println("message sent.");

  inchar = 'z'; // garbage value




  delay(2000);

  gpsflag = 0;

  ss.begin(GPSBaud); // we again activate the gps module, 
                     //so now gps will work and gsm will not..

  delay(100);







   

  }

For the practical demonstration, watch the video tutorial given below.


Watch Video Tutorial:

 

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

One Comment

  1. Hi there,
    Nice project.
    Can you explain how you have plotted car GPS route in Google maps please?
    Or point me to a good project where you have explained this.
    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button