Ticker

6/recent/ticker-posts

How to Integrate GSM 900A and GPS NEO-6M with Arduino for Real-Time Location Tracking

 

Integrating GSM 900A and GPS NEO-6M with Arduino to Send SMS Location URLs


In this blog post, we’ll walk you through how to integrate the GSM 900A module and the GPS NEO-6M module with an Arduino to send SMS messages containing map location URLs. By the end of this project, your system will be capable of sending the real-time GPS location of your device to a predefined phone number.


Components Required

  1. Arduino Uno (or any compatible board)
  2. GSM 900A module
  3. GPS NEO-6M module
  4. SIM card (with SMS plan activated)
  5. Jumper wires
  6. Breadboard (optional)
  7. Power supply for GSM and Arduino

Wiring Diagram

Before proceeding, let’s connect the components:

GSM 900A Connections:

  • VCC → 5V (External power supply preferred)
  • GND → GND
  • RX → Arduino Pin 2
  • TX → Arduino Pin 3

GPS NEO-6M Connections:

  • VCC → 3.3V or 5V
  • GND → GND
  • TX → Arduino Pin 4
  • RX → Arduino Pin 5

Ensure to use a common ground for all modules.


Arduino Code

Here’s the Arduino code for integrating both modules. This script will:

  1. Fetch GPS coordinates.
  2. Create a Google Maps URL.
  3. Send the URL via SMS using the GSM 900A module.
#include <SoftwareSerial.h>

// GSM and GPS pins
SoftwareSerial gsm(2, 3); // GSM RX, TX
SoftwareSerial gps(4, 5); // GPS RX, TX

String latitude = "";
String longitude = "";

void setup() {
  Serial.begin(9600);
  gsm.begin(9600);
  gps.begin(9600);

  Serial.println("Initializing...");

  // Initialize GSM module
  gsm.println("AT");
  delay(1000);
  gsm.println("AT+CMGF=1"); // Set SMS mode to text
  delay(1000);
  
  Serial.println("Initialization complete.");
}

void loop() {
  if (gps.available()) {
    String gpsData = gps.readStringUntil('\n');
    
    if (gpsData.startsWith("$GPGGA")) {
      parseGPSData(gpsData);
      sendLocationSMS();
      delay(30000); // Wait 30 seconds before next SMS
    }
  }
}

void parseGPSData(String data) {
  int latIndex = data.indexOf(",", 18) + 1;
  int latEndIndex = data.indexOf(",", latIndex);
  int longIndex = data.indexOf(",", latEndIndex + 1) + 1;
  int longEndIndex = data.indexOf(",", longIndex);

  latitude = convertToDecimalDegrees(data.substring(latIndex, latEndIndex));
  longitude = convertToDecimalDegrees(data.substring(longIndex, longEndIndex));

  Serial.print("Latitude: ");
  Serial.println(latitude);
  Serial.print("Longitude: ");
  Serial.println(longitude);
}

String convertToDecimalDegrees(String coord) {
  if (coord.length() < 10) return "0.0";
  
  String degrees = coord.substring(0, 2);
  String minutes = coord.substring(2);

  float decimalDegrees = degrees.toFloat() + (minutes.toFloat() / 60);
  return String(decimalDegrees, 6);
}

void sendLocationSMS() {
  if (latitude != "" && longitude != "") {
    String message = "Location: https://www.google.com/maps?q=" + latitude + "," + longitude;
    
    gsm.println("AT+CMGS=\"+1234567890\""); // Replace with your phone number
    delay(1000);
    gsm.print(message);
    delay(1000);
    gsm.write(26); // ASCII code for CTRL+Z
    delay(5000);

    Serial.println("SMS Sent: " + message);
  }
}

Working Principle

  1. The GPS module continuously sends NMEA sentences to the Arduino.
  2. The script extracts the latitude and longitude from the $GPGGA sentence.
  3. The extracted coordinates are converted into decimal degrees format.
  4. A Google Maps URL is generated.
  5. The GSM module sends the URL as an SMS to the specified phone number.

Sample Output

Serial Monitor:

Initializing...
Latitude: 37.774929
Longitude: -122.419416
SMS Sent: Location: https://www.google.com/maps?q=37.774929,-122.419416

SMS Received:

Location: https://www.google.com/maps?q=37.774929,-122.419416

Images

  1. Wiring Diagram


  1. The sms comes in phone looks like this



Troubleshooting Tips

  • GPS Module Not Responding: Ensure the GPS module has a clear view of the sky.
  • GSM Module Not Sending SMS: Verify SIM card functionality and ensure sufficient balance.
  • Data Parsing Issues: Double-check the $GPGGA format for your GPS module.

With this project, you can now track the location of your device and receive real-time updates via SMS. Feel free to customize and expand this project based on your requirements. Happy coding!

Post a Comment

0 Comments