Send GPS data via SMS

Hello all,

I have a question about sending GPS data via SMS. I am using the SIM800l module and the NEO-6m and I am trying to send an SMS with the GPS data. However, this does not work somehow. Although an SMS is sent, it does not contain any GPS data, but "0.000000" is displayed in the SMS.

This below is my code. Maybe you have an idea what exactly is wrong. Thank you!

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

#define PIN_RESET 3
#define PIN_TX 5
#define PIN_RX 6
#define PIN_RXD 7
#define PIN_TXD 8

const char TELEFONE_NUMBER[] = "XXxxxxxxxxxx";

SoftwareSerial mySerial(PIN_TX, PIN_RX);
SoftwareSerial gpsSerial(PIN_RXD, PIN_TXD);
TinyGPSPlus tinyGps;

void setup()
{
  pinMode(PIN_RESET, OUTPUT);
  digitalWrite(PIN_RESET, HIGH);

  Serial.begin(9600);
  mySerial.begin(9600);
  gpsSerial.begin(9600);

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

  // Once the handshake test is successful, it will back to OK
  mySerial.println("AT");
  updateSerial();

  // Configuring TEXT mode
  mySerial.println("AT+CMGF=1");
  updateSerial();

  mySerial.println("AT+CMGS=\""+String(TELEFONE_NUMBER)+"\"");
  updateSerial();

  // SMS text content
  mySerial.print("latitude: ");
  mySerial.println(tinyGps.location.lat(), 6);
  mySerial.print("longitude: ");
  mySerial.println(tinyGps.location.lng(), 6);
  updateSerial();
  mySerial.write(26);

}

void loop() {}

void updateSerial()
{
  delay(200);
  while (Serial.available()) {
    // Forward what Serial received to Software Serial Port
    mySerial.write(Serial.read());
  }
  while(mySerial.available()) {
    // Forward what Software Serial received to Serial Port
    Serial.write(mySerial.read());
  }
}

Welcome to the forum

SoftwareSerial mySerial(PIN_TX, PIN_RX);
SoftwareSerial gpsSerial(PIN_RXD, PIN_TXD);

2 instances of SoftwareSerial never works well, if at all because they share the same resources

Which Arduino board are you using ?

I use the Arduino Uno. What can I do instead?

3 problems I can see.

1). As per @UKHeliBob's comment. Using 2 instances of SoftwareSerial can be problematic... you need to use some extra functions to make it work... have a look at the following...

2). More importantly... nowhere in your code do you get anything from the GPS unit. You start the connection, but never read any data. I suggest you look at some of the examples that come with the TinyGPSPlus library... like this one.

3). You're running everything in setup. GPS units can often take a while to get a fix. You need the code in loop so you can keep trying.

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