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++;
}

