I have made a project that sends GPS coordinate but the problem is, when GPRS sends coordinates as 00.0000,00.000. So, I want to know if my code is wrong.

Thank you for your answer.

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

double latitude, longtitude;
char Received_SMS; //Here we store the full received SMS (with phone sending number and date/time) as char
short MSG_OK = -1; //Used later it shows if there's the word "DHT"/"MLX" within the received SMS "-1" means they are not found
String Data_SMS; //Here's the SMS that we gonna send to the phone number, it may contain DHT data or MLX data

TinyGPSPlus gps;
SoftwareSerial mySerial(2, 3); //gps
SoftwareSerial ss2(9, 10); //gprs

void setup() {
  mySerial.begin(9600); //Begin all the communications needed Arduino with PC serial and Arduino with all devices (SIM800L+DHT+MLX)
  Serial.println("GPS Tracking");
  Serial.println("Starting ...");
  delay(3000); //Delay to let the module connect to network, can be removed
  ReceiveMode(); //Calling the function that puts the SIM800L moduleon receiving SMS mode

void loop() {
  while (mySerial.available()) {
  if (gps.location.isUpdated()) {
    latitude = gps.location.lat();
    longtitude = gps.location.lng();
  String RSMS;
  while (ss2.available() > 0) { //When SIM800L sends something to the Arduino... problably the SMS received... if something else it's not a problem
    Received_SMS = ss2.read(); //"char Received_SMS" is now containing the full SMS received
    Serial.print(Received_SMS); //Show it on the serial monitor (optional)
    RSMS.concat(Received_SMS); //concatenate "char received_SMS" to RSMS which is "empty"
    MSG_OK = RSMS.indexOf("GET-GPS"); //And this is why we changed from char to String, it's to be able to use this function "indexOf"
  if (MSG_OK != -1) { //If "DHT" word is found within the SMS, it means that DHT_OK have other value than -1 so we can proceed
    Serial.println("found MSG"); //Shows on the serial monitor "found DHT" (optional)
    Data_SMS = ("http://www.google.com/maps/place/" + String(latitude, 6) + "," + String(longtitude, 6));
    Send_Data(); //This function set the sending SMS mode, prepare the phone number to which we gonna send, and send "Data_SMS" String
    ReceiveMode(); //Come back to Receving SMS mode and wait for other SMS
    MSG_OK = -1; //If the DHT is found the variable should be reset to -1 otherwise it will be kept as !=-1 and will send SMS over and over

void Serialcom() { //This is used with ReceiveMode function, it's okay to use for tests with Serial monitor
  while (Serial.available()) {
    ss2.write(Serial.read()); //Forward what Serial received to Software Serial Port
  while (ss2.available()) {
    Serial.write(ss2.read()); //Forward what Software Serial received to Serial Port

void ReceiveMode() { //Set the SIM800L Receive mode
  ss2.println("AT"); //If everything is Okay it will show "OK" on the serial monitor
  ss2.println("AT+CMGF=1"); // Configuring TEXT mode
  ss2.println("AT+CNMI=2,2,0,0,0"); //Configure the SIM800L on how to manage the Received SMS... Check the SIM800L AT commands manual

void Send_Data() {
  Serial.println("Sending Data..."); //Displays on the serial monitor...Optional
  ss2.print("AT+CMGF=1\r"); //Set the module to SMS mode
  ss2.print("AT+CMGS=\"+66xxxxxxxxx\"\r"); //Your phone number don't forget to include your country code example +212xxxxxxxxx"
  ss2.print(" You are here "); //This string is sent as SMS
  ss2.print(Data_SMS); //This string is sent as SMS
  ss2.print((char)26);//Required to tell the module that it can send the SMS
  Serial.println("Data Sent.");
  • if you want an answer, then perhaps you should ask a question – jsotola Mar 29 at 7:48
  • what coordinates is GPS providing? – jsotola Mar 29 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.