Categories
Examples

Arduino GPS Tracker with Real-Time Location Tracking

In this article we are going to implement a real time location tracking system with NEO GPS and a SIM800 GSM module. This is for the intention to track location of your vehicle or any other thing that you want to track and want to know the position on your mobile phone. There are many other possibilities to do the same, one of which is by using some IoT platform like ESP8266 or ESP32 to implement the same tracker with the live Firebase based location coordinates update. But in today’s tutorial all we going to do is to send the GPS coordinates via GSM module and to a specific number.

Note: If you are in Pakistan, you may need to register your GSM module with the PTA.

Components:

  • Arduino board
  • NEO-6M GPS module
  • SIM800L GSM module
  • Jumper wires
  • Breadboard

Connections:

  • GPS: VCC to 3.3V, GND to GND, TX to digital pin 4, RX to digital pin 3
  • GSM: VCC to 5V, GND to GND, TX to digital pin 6, RX to digital pin 7

Key Concepts:

  • GPS data parsing
  • GSM communication
  • Real-time location tracking

Arduino Libraries:

  • TinyGPS++
  • SoftwareSerial

Arduino code for GPS Tracker

Here is the complete code for the Arduino GPS Tracker with the above mentioned parts. You can compile this code after installing the required libraries which are mentioned in the above list. Once you downloaded and installed the libraries of SoftwareSerial and TinyGPS++ you are ready to upload the code after compiling into the Arduino Board. You can use Arduino UNO or Arduino Nano or even Arduino micro pro etc. Here is the complete code

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

TinyGPSPlus gps;
SoftwareSerial gpsSerial(4, 3);
SoftwareSerial gsmSerial(6, 7);

void setup() {
  Serial.begin(9600);
  gpsSerial.begin(9600);
  gsmSerial.begin(9600);
  delay(3000);
  gsmSerial.print("AT+CGNSPWR=1\r\n");
  delay(100);
}

void loop() {
  while (gpsSerial.available()) {
    gps.encode(gpsSerial.read());
  }

  if (gps.location.isUpdated()) {
    String lat = String(gps.location.lat(), 6);
    String lng = String(gps.location.lng(), 6);
    sendLocation(lat, lng);
    delay(30000);
  }
}

void sendLocation(String lat, String lng) {
  String command = "AT+HTTPPARA=\"URL\",\"http://yourserver.com/location.php?lat=" + lat + "&lng=" + lng + "\"\r\n";
  gsmSerial.print(command);
  delay(100);
}
Code language: PHP (php)

Key Functions:

  • setup(): Initializes GPS and GSM modules
  • loop(): Reads GPS data and sends location
  • sendLocation(): Sends latitude and longitude to the server

Tips:

  • Make sure to replace “yourserver.com” with your actual server URL.
  • Adjust the delay between location updates as needed.

This code-centric guide demonstrates how to build an Arduino GPS tracker with real-time location tracking using NEO-6M GPS and SIM800L GSM modules. By following the provided code and connections, you can create a functional GPS tracker for various applications.

By Abdul Rehman

My name is Abdul Rehman and I love to do Reasearch in Embedded Systems, Artificial Intelligence, Computer Vision and Engineering related fields. With 10+ years of experience in Research and Development field in Embedded systems I touched lot of technologies including Web development, and Mobile Application development. Now with the help of Social Presence, I like to share my knowledge and to document everything I learned and still learning.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.