Arduino GPS GSM tracker

hello! I have build a GPS tracker with Arduino UNO board and SIM808 module. I have wrote the code below in the Arduino IDE window but i can't receive any data. I should save the data in a text file on an SD card, but all I can see there are zeros. Can anyone help me with a solution please?
thank you!

/*
Realtime GSM GPS Tracker

Created: 01/22/2016
by Sebastian Westerhold
KF5OBS

This example code is in the public domain.

SD Card uses SEED SD Card Shield v. 4.0
CS - pin 4

Connect GPS Module to PIN 7 on UNO
Connect GPS Module to Serial 1 RX on Due

*/
#include <SoftwareSerial.h>
#include <SD.h>

// Soft Serial for UNO, comment out for Due
//#include
SoftwareSerial Serial1(7, 8);

// Include GPS Library
#include "TinyGPS++.h"
TinyGPSPlus gps;

// Set up necessary variables
const int chipSelect = 4;
int counter = 100;
char message[160];
char latitude[12];
char longitude[12];

// Setup routine
void setup() {

// Initiate Serial at 4800 baud
Serial.begin(19200);

// Wait for serial to become available
while (!Serial) {
}

// Initiate serial for GPS module
Serial1.begin(19200);

// Iinitialize the SD card
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("done.");

// Set mode to text
Serial.print("AT+CMGF=1\r");

// Give GSM module some start-up time
delay(100);
}

// Function to send text message
void sendSMS(String message)
{
// AT command to initiate text message
Serial.print("AT+CMGF=1\r");
delay(100);
// AT command to set destination number
Serial.println("AT + CMGS = "+40721071002"");
delay(100);
// Message body
Serial.println(message);
delay(100);
// Termination character
Serial.println((char)26);
delay(100);
// \n
Serial.println();
}

// Main routine
void loop() {

// If there's serial data int he buffer, add to dataString
while(Serial1.available() >0)
{
// Feed it to the GPS engine
gps.encode(Serial1.read());
}

// If the location info is valid...
//if (gps.location.isValid()) {

// Open file on SD Card
File dataFile = SD.open("NMEA.txt", FILE_WRITE);

// IF the file is opened successfully...
if (dataFile) {

// Assemble SC Card Line
//** Assemble Date DD.MM.YYYY
dataFile.print(gps.date.day());
dataFile.print(".");
dataFile.print(gps.date.month());
dataFile.print(".");
dataFile.print(gps.date.year());

dataFile.print(",");

//** Assemble time HH:MM:SS
dataFile.print(gps.time.hour());
dataFile.print(":");
dataFile.print(gps.time.minute());
dataFile.print(":");
dataFile.print(gps.time.second());

dataFile.print(",");
dataFile.print(gps.location.lat());
dataFile.print(",");
dataFile.print(gps.location.lng());
dataFile.print(",");
dataFile.print(gps.speed.kmph());
dataFile.print(",");
dataFile.print(gps.course.deg());
dataFile.print(",");
dataFile.print(gps.altitude.meters());
dataFile.print(",");
dataFile.print(gps.satellites.value());
dataFile.print(",");
dataFile.print(gps.hdop.value());
dataFile.println("");

// Close the SD card file
dataFile.close();

// wait for 10 seconds
delay(10000);

}

// If there's any errors, so say via serial.
else {
Serial.println("error opening NMEA.txt");
}

// Only send texts every 30 cycles (~ 10 Minutes)
if (counter > 6*10)
{
// Assemble Text Message
strcpy(message, "http://maps.google.com/");
strcat(message, "maps?z=12&t=m&q=loc:");
dtostrf(gps.location.lat(), 1, 6, latitude);
strcat(message,latitude);
strcat(message,"+");
dtostrf(gps.location.lng(), 1, 6, longitude);
strcat(message,longitude);
strcat(message,"");

// Send via text
sendSMS(message);
counter=0;
}

//}

counter++;
}

all I can see there are zeros

Because you did not use code tags when posting your code I can see a smiley in it.

My guess is that your GPS doesn't have a valid position fix yet.

SoftwareSerial Serial1(7, 8);

Do you really have the GPS/GSM device connected to the smiley face pin?

It is NOT a Serial1 that you have connected to those pins. Why not use a name that reflects what you DO have connected?

gps.encode(Serial1.read());

The encode() method returns true or false. Why do you ignore that value?

// wait for 10 seconds
delay(10000);

Good idea, when the GPS sends data every second. NOT!

You DID take the GPS outside, didn't you?

Another guess would be that the GPS is not working.

SoftwareSerial Serial1(7, 8 ); sorry, this is the real line

yes, i went with the gps outside, and still zeros. i checked and i don't get a fix location. i do not now why. i may have problems with the GPS receiver or can be something else?

can be something else?

Yes. Instead of ignoring whether encode() returns true or false, pay attention.

Instead of doing anything with the data you get from the GPS, simply print it. Show us what you actually get from the GPS, if anything.

that is what i can see in the serial monitor

Madalina:
that is what i can see in the serial monitor

But that is not what the GPS is putting out.

The Serial.print() statements you added in the picture are, of course, nonsense.

The loop() function should look like this. NOTHING more, until you KNOW that you are getting data from the GPS.

// Main routine
void loop()
{
   while(Serial1.available() >0)
   {
       char c = Serial1.read();
       Serial.print(c);

       // Feed it to the GPS engine
       // gps.encode(Serial1.read());
   }
}

Here is the equivalent for softerial;

/*
******************************************************************************************************
http://www.LoRaTracker.uk
The purpose of this program is to check that a Serial GPS is working. Characters are read from the GPS
and sent to the Serial monitor at 115200 baud
Set the GPS baud and softserial pins as used on your board 
******************************************************************************************************
*/

#define GPSTX A2                              //pin number for TX output - RX into GPS
#define GPSRX A3                              //pin number for RX input - TX from GPS

#include <SoftwareSerial.h>
SoftwareSerial GPSserial(GPSRX, GPSTX);       //Create the serial connection to the GPS device


void loop()                    
{
  while (GPSserial.available() > 0)
  Serial.write(GPSserial.read());
}


void setup()
{
  Serial.begin(115200);                        //connect at 115200 so we can read the GPS fast enough and also spit it out
  GPSserial.begin(4800);                      //make sure GPS baud is correct !!! 
}

i did the changes but that is all i can see.

and i also tried the code from srnet and i didn't receive anything in the serial monitor... the baud rate for the gps how can be checked if it is 4800?

i did the changes but that is all i can see.

Do NOT post pictures of text. Post text AS TEXT.

Post your code, so we can see that you made the changes correctly.

If you are seeing nothing from the GPS, then it isn't working. Nothing you do in the code can make up for the fact that you are not getting data from it.

"
/*
Realtime GSM GPS Tracker

This example code is in the public domain.

SD Card uses SEED SD Card Shield v. 4.0
CS - pin 4

Connect GPS Module to PIN 7 on UNO
Connect GPS Module to Serial 1 RX on Due

*/
#include <SoftwareSerial.h>
#include <SD.h>

// Soft Serial for UNO, comment out for Due
//#include
SoftwareSerial Serial1(7, 8);

// Include GPS Library
#include "TinyGPS++.h"
TinyGPSPlus gps;

// Set up necessary variables
const int chipSelect = 4;
int counter = 100;
char message[160];
char latitude[12];
char longitude[12];

// Setup routine
void setup() {

// Initiate Serial at 4800 baud
Serial.begin(19200);

// Wait for serial to become available
while (!Serial) {
}

// Initiate serial for GPS module
Serial1.begin(19200);

// Iinitialize the SD card
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("done.");

// Set mode to text
Serial.print("AT+CMGF=1\r");

// Give GSM module some start-up time
delay(100);
}

// Function to send text message
void sendSMS(String message)
{
// AT command to initiate text message
Serial.print("AT+CMGF=1\r");
delay(100);
// AT command to set destination number
Serial.println("AT + CMGS = "+40721071002"");
delay(100);
// Message body
Serial.println(message);
delay(100);
// Termination character
Serial.println((char)26);
delay(100);
// \n
Serial.println();
}

//// Main routine
//void loop() {
//
//// If there's serial data int he buffer, add to dataString
//while(Serial1.available() >0)
//{
//// Feed it to the GPS engine
//gps.encode(Serial1.read());
// Serial.print(gps.location.lat(), 6);
// Serial.print(", ");
// Serial.print(gps.location.lng(), 6);
// Serial.print(", ");
//}
//
//// If the location info is valid...
////if (gps.location.isValid()) {
//
//// Open file on SD Card
//File dataFile = SD.open("NMEA.txt", FILE_WRITE);
//
//// IF the file is opened successfully...
//if (dataFile) {
//
//// Assemble SC Card Line
////** Assemble Date DD.MM.YYYY
//dataFile.print(gps.date.day());
//dataFile.print(".");
//dataFile.print(gps.date.month());
//dataFile.print(".");
//dataFile.print(gps.date.year());
//
//dataFile.print(",");
//
////** Assemble time HH:MM:SS
//dataFile.print(gps.time.hour());
//dataFile.print(":");
//dataFile.print(gps.time.minute());
//dataFile.print(":");
//dataFile.print(gps.time.second());
//
//dataFile.print(",");
//dataFile.print(gps.location.lat());
//dataFile.print(",");
//dataFile.print(gps.location.lng());
//dataFile.print(",");
//dataFile.print(gps.speed.kmph());
//dataFile.print(",");
//dataFile.print(gps.course.deg());
//dataFile.print(",");
//dataFile.print(gps.altitude.meters());
//dataFile.print(",");
//dataFile.print(gps.satellites.value());
//dataFile.print(",");
//dataFile.print(gps.hdop.value());
//dataFile.println("");
//
//// Close the SD card file
//dataFile.close();
//
//// wait for 10 seconds
//delay(10000);
//
//}
//
//// If there's any errors, so say via serial.
//else {
//Serial.println("error opening NMEA.txt");
//}
//
//// Only send texts every 30 cycles (~ 10 Minutes)
//if (counter > 6*10)
//{
//// Assemble Text Message
//strcpy(message, "http://maps.google.com/");
//strcat(message, "maps?z=12&t=m&q=loc:");
//dtostrf(gps.location.lat(), 1, 6, latitude);
//strcat(message,latitude);
//strcat(message,"+");
//dtostrf(gps.location.lng(), 1, 6, longitude);
//strcat(message,longitude);
//strcat(message,"");
//
//// Send via text
//sendSMS(message);
//counter=0;
//}
//
////}
//
//counter++;
//}

void loop()
{
while(Serial1.available() >0)
{
char c = Serial1.read();
Serial.print(c);

// Feed it to the GPS engine
// gps.encode(Serial1.read());
}
}

"

that is the code i tried. sorry, and thank you for your time!

that is the code i tried.

That appears to be getting no data from the GPS. No amount of wishing is going to make something useful out of nothing. You need to figure what AT commands to send it to make it send GPS data.

Yes, I have tried some AT commands but I had no result as well.

Thank you a lot for helping me! I will try this code with another GPS device.

Hello!
I am trying to build a GPS tracker with an Arduino UNO board and a SIM808 device. I want to receive data, store them on a SD card and send a SMS with the latitude and longitude.
I have a code but I have problems receiving data. I have tried another code and I can receive data. I think I have to turn on the SIM808 with the AT command but it doesn't work. I am new in this.
Can anyone help me please with some suggestions?

Thank you!!

/*
Realtime GSM GPS Tracker

This example code is in the public domain.

SD Card uses SEED SD Card Shield v. 4.0
CS - pin 4

Connect GPS Module to PIN 7 on UNO
Connect GPS Module to Serial 1 RX on Due

*/
#include <SoftwareSerial.h>
#include <SD.h>


// Soft Serial for UNO, comment out for Due
//#include 
SoftwareSerial Serial1(7, 8);

// Include GPS Library
#include "TinyGPS++.h"
TinyGPSPlus gps;

// Set up necessary variables
const int chipSelect = 4;
int counter = 100;
char message[160];
char latitude[12];
char longitude[12];

// Setup routine
void setup() {

// Initiate Serial at 4800 baud
Serial.begin(9600);

// Wait for serial to become available
while (!Serial) {
}

// Initiate serial for GPS module
Serial1.begin(9600);

// Iinitialize the SD card
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
return;
}
Serial.println("done.");

// Set mode to text
Serial.print("AT+CGPSPWR=1\r");

Serial.print("AT+CMGF=1\r");

// Give GSM module some start-up time
delay(100);
}

// Function to send text message
void sendSMS(String message)
{
// AT command to initiate text message
Serial.print("AT+CMGF=1\r");
delay(100);
// AT command to set destination number
Serial.println("AT + CMGS = \"+40721071002\"");
delay(100);
// Message body
Serial.println(message);
delay(100);
// Termination character
Serial.println((char)26);
delay(100);
// \n
Serial.println();
}

// Main routine
void loop() {

// If there's serial data int he buffer, add to dataString
while(Serial1.available() >0)
{
// Feed it to the GPS engine
gps.encode(Serial1.read());
 
}

// If the location info is valid...
//if (gps.location.isValid()) {

// Open file on SD Card
File dataFile = SD.open("NMEA.txt", FILE_WRITE);

// IF the file is opened successfully...
if (dataFile) {

// Assemble SC Card Line
//** Assemble Date DD.MM.YYYY
dataFile.print(gps.date.day());
dataFile.print(".");
dataFile.print(gps.date.month());
dataFile.print(".");
dataFile.print(gps.date.year());

dataFile.print(",");

//** Assemble time HH:MM:SS
dataFile.print(gps.time.hour());
dataFile.print(":");
dataFile.print(gps.time.minute());
dataFile.print(":");
dataFile.print(gps.time.second());

dataFile.print(",");
dataFile.print(gps.location.lat());
dataFile.print(",");
dataFile.print(gps.location.lng());
//dataFile.print(",");
//dataFile.print(gps.speed.kmph());
//dataFile.print(",");
//dataFile.print(gps.course.deg());
dataFile.print(",");
dataFile.print(gps.altitude.meters());
dataFile.print(",");
//dataFile.print(gps.satellites.value());
//dataFile.print(",");
//dataFile.print(gps.hdop.value());
//dataFile.println("");

// Close the SD card file
dataFile.close();

// wait for 10 seconds
delay(10000);

}

// If there's any errors, so say via serial.
else {
Serial.println("error opening NMEA.txt");
}

// Only send texts every 30 cycles (~ 10 Minutes)
if (counter > 6*10)
{
// Assemble Text Message
strcpy(message, "http://maps.google.com/");
strcat(message, "maps?z=12&t=m&q=loc:");
dtostrf(gps.location.lat(), 1, 6, latitude);
strcat(message,latitude);
strcat(message,"+");
dtostrf(gps.location.lng(), 1, 6, longitude);
strcat(message,longitude);
strcat(message,"");

// Send via text
sendSMS(message);
counter=0;
}

//}

counter++;
}

//void loop()
//{
//   while(Serial1.available() >0)
//   {
//       char c = Serial1.read();
//       Serial.print(c);
//
//       // Feed it to the GPS engine
//       // gps.encode(Serial1.read());
//   }
//}

I have also this code which makes the gps to receive data. Can anyone help me please to change it, so it saves data in a text file on the card and sends a SMS?

#include <SoftwareSerial.h>
#include<stdio.h>
#include<string.h>
#define DEBUG true

SoftwareSerial mySerial(7,8); 
        
void setup()
{
  Serial.begin(9600);
 mySerial.begin(9600); 
}

void loop()
{
   getgps();
   while(1)
   {
        sendData( "AT+CGNSINF",1000,DEBUG);   
        delay(1000);
        
   }
 
}
void getgps(void)
{
   sendData( "AT+CGPSPWR=1",1000,DEBUG); 
   sendData( "AT+CGPSSEQ=RMC",1000,DEBUG); 
   sendData( "AT+CREG?",1000,DEBUG); 
   sendData( "AT+CMGF=1",1000,DEBUG);
   sendData( "AT+CSQ",1000,DEBUG); 
   sendData( "AT+CSMP=17,167,0,16",1000,DEBUG); 
//   sendData( "AT+CMGS=\"+40721071002\"\r ",1000,DEBUG);
   
//   mySerial.println("AT+CGPSPWR=1");
//   mySerial.println("AT+CREG?");
//   mySerial.println("AT+CMGF=1");
//   mySerial.println("AT+CMGS=\"+40721071002\"");
//   while (mySerial.read()!=">");
//   mySerial.print("TEST BLA BLA");
//   mySerial.write(0x1A);  // sends ctrl+z end of message
//   mySerial.write(0x0D);  // Carriage Return in Hex
//   mySerial.write(0x0A);  // Line feed in Hex


}


String sendData(String command, const int timeout, boolean debug)
{
    String response = "";    
    mySerial.println(command); 
    long int time = millis();   
    while( (time+timeout) > millis())
    {
      while(mySerial.available())
      {       
        char c = mySerial.read(); 
        response+=c;
      }  
    }    
    if(debug)
    {
      Serial.print(response);
    }    
    return response;
}

Madalina:
Can anyone help me please to change it, so it saves data in a text file on the card and sends a SMS?

Yes, I can help.

Rather than trying to get all the functions working at once, reduce the code so that you test individual bits.

  1. Have you written a program that reads the GPS and prints the location to serial monitor ?

  2. Have you written a program that writes text to an SD card ?

  3. Combine 1 and 2, can you write the GPS location to SD card ?

etc.