Facing issues connecting gsm and gps at the same time want to send messages and receive messages with google map link

so want to send a message and recieve links with latitude and longitude attached to the google maps link

**my coonections **
SoftwareSerial gsm(8, 9);
SoftwareSerial gpsSerial(10, 11); // RX, TX

am using sim900A gsm and neo6gps

in serial monitor i see

Connecting...

Connecting...

but with code to only gsm works fine

my code

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

SoftwareSerial gsm(8, 9);
SoftwareSerial gpsSerial(10, 11); // RX, TX

TinyGPSPlus gps;
String inputString;

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

  while (!gsm.available()) {
    gsm.println("AT");
    delay(1000);
    Serial.println("Connecting...");
  }
  Serial.println("Connected!");
  gsm.println("AT+CMGF=1");  // Set SMS to Text Mode
  delay(1000);
  gsm.println("AT+CNMI=1,2,0,0,0");  // Procedure to handle newly arrived messages
  delay(1000);
  gsm.println("AT+CMGL=\"REC UNREAD\""); // Read Unread Messages

  while (!gpsSerial.available()) {
    gpsSerial.println("AT+CGNSPWR=1"); // Enable GPS
    delay(1000);
  }
}

void loop() {
  char incomingByte; // Declare incomingByte variable

  if (gsm.available()) {
    delay(100);

    // Serial Buffer
    while (gsm.available()) {
      incomingByte = gsm.read();
      inputString += incomingByte;
    }

    delay(10);

    Serial.println(inputString);
    inputString.toUpperCase(); // Uppercase the Received Message

    // Turn LED ON or OFF
    if (inputString.indexOf("LOC") > -1) {
      Serial.println("Success Location");
      SendMessage("");
    }
    if (inputString.indexOf("STATUS") > -1) {
      Serial.println("Success Status");
      SendStatus("");
    }

    if (inputString.indexOf("ALL") > -1) {
      Serial.println("Success ALL");
      SendAll("");
    }

    delay(50);

    // Delete Messages & Save Memory
    if (inputString.indexOf("OK") == -1) {
      gsm.println("AT+CMGDA=\"DEL ALL\"");
      delay(1000);
    }

    inputString = "";
  }

  while (gpsSerial.available() > 0) {
    if (gps.encode(gpsSerial.read())) {
      if (gps.location.isValid()) {
        float latitude = gps.location.lat();
        float longitude = gps.location.lng();
        updateGoogleMapsLink(latitude, longitude);
      }
    }
  }
}

void SendMessage(String googleMapsLink) {
  Serial.println ("Sending Message"); 
  gsm.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode   
  delay(1000);   
  Serial.println ("Set SMS Number");   
  gsm.println("AT+CMGS=\"+263781840930\"\r"); //Write Mobile number to send message   
  delay(1000);   
  Serial.println ("Set SMS Content");   
  gsm.println(googleMapsLink);   
  delay(100);   
  Serial.println ("Finish");   
  gsm.println((char)26);// ASCII code of CTRL+Z   
  delay(1000);   
  Serial.println ("Message has been sent ->LATS System");   
}

void SendStatus(String googleMapsLink) {
  Serial.println ("Sending Message");   
  gsm.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode   
  delay(1000);   
  Serial.println ("Set SMS Number");   
  gsm.println("AT+CMGS=\"+263781840930\"\r"); //Write Mobile number to send message   
  delay(1000);   
  Serial.println ("Set SMS Content");   
  gsm.println("System started successfully");// Messsage content   
  gsm.println("Pivot active");
  gsm.println("All Animals In Range");
  delay(100);   
  Serial.println ("Finish");   
  gsm.println((char)26);// ASCII code of CTRL+Z   
  delay(1000);   
  Serial.println ("Message has been sent ->LATS System");   
}

void SendAll(String googleMapsLink) {
  Serial.println ("Sending Message");   
  gsm.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode   
  delay(1000);   
  Serial.println ("Set SMS Number");   
  gsm.println("AT+CMGS=\"+263781840930\"\r"); //Write Mobile number to send message   
  delay(1000);   
  Serial.println ("Set SMS Content");   
  gsm.println("Pivot Location");
  gsm.println(googleMapsLink);   
  gsm.println("Tag 12/17");
  gsm.println(googleMapsLink);   
  delay(100);   
  Serial.println ("Finish");   
  gsm.println((char)26);// ASCII code of CTRL+Z   
  delay(1000);   
  Serial.println ("Message has been sent ->LATS System");   
}

void updateGoogleMapsLink(float latitude, float longitude) {
  String googleMapsLink = "https://maps.google.com/maps?q=" + String(latitude, 6) + "," + String(longitude, 6);
  // Update the Google Maps link in your SMS messages
  SendMessage(googleMapsLink);
  SendStatus(googleMapsLink);
  SendAll(googleMapsLink);
}

Thanks for posting your code properly in the first post!

What hardware are you using, and what issues are you facing? Please add links to the hardware, and a wiring diagram.

SoftwareSerial gsm(8, 9);
SoftwareSerial gpsSerial(10, 11); // RX, TX

Whilst you can use two instances of software serial, it not really a good idea at all and you have to make sure you switch between them with listen() mode, check the referance;

https://docs.arduino.cc/learn/built-in-libraries/software-serial/

Much better idea to switch to an Arduino that has enoubgh hardware serial ports.

i get the message GPS module not responding

but my gps location led is blinking and my gsm is blinking after 3 seconds showing it sconnected my gps is connected rx 0 and tx 1 of arduino nano

my code

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

SoftwareSerial gsm(8, 9);
TinyGPSPlus gps;

void setup() {
  Serial.begin(9600);
  gsm.begin(9600);
  Serial.println("Gps Start");
}

void loop() {
  while (gsm.available()) {
    char c = gsm.read();
    gps.encode(c);
    Serial.write(c); // echo the character back to serial
  }

  if (gps.location.isUpdated()) {
    Serial.println("\nLocation received!");
    Serial.print("Latitude: ");
    Serial.println(gps.location.lat(), 6);
    Serial.print("Longitude: ");
    Serial.println(gps.location.lng(), 6);

    gsm.println("AT+CMGF=1"); // Set SMS mode to text
    delay(100);
    gsm.println("AT+CMGS=\"+263781840930\""); // Replace this number with the recipient's number
    delay(100);
    gsm.print("I am lost here is my location: https://maps.google.com/maps/place/");
    gsm.print(gps.location.lat(), 6);
    gsm.print(",");
    gsm.print(gps.location.lng(), 6);
    gsm.println((char)26); // End the SMS
    delay(100);
  }

  if (gps.charsProcessed() < 10) {
    Serial.println("GPS module not responding...");
  }
}


I have merged your topics due to them having too much overlap on the same subject matter @fatsoe.

In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.

The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Thanks in advance for your cooperation.

TinyGPS++ is specific for NMEA location sentences emitted by a standard GPS module, and cannot interpret data from a GSM module.

See TinyGPS++ | Arduiniana

You provided two codes

This was addressed in the second reply (post #3).

Pins 0 and 1 are also used for communication with the PC. This might interfere with the gps.

As advised in post #3, use an Arduino that has multiple serial ports. A Mega if size does not matter, a Nano Every if size does matter. With those you don't have to use SoftwareSerial; with the Nano Evevry you will have to do some work to get the 3rd serial or use one SoftwareSerial).

Alternatively use a Leonardo/Micro/ProMicro which have one free serial port and the second one can be implemented using SoftwareSerial).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.