#include <SoftwareSerial.h>
#include "TinyGPS.h"
SoftwareSerial gpsSerial(2, 3);
TinyGPS gps; // create gps object
const int timesTosend=1;
char phone_no[]="9870820167";
void setup() {
Serial.begin(9600);
gpsSerial.begin(9600); // connect gps sensor
delay(2000);
Serial.println("AT+CMGF=1");
delay(200);
}
void loop() {
static int count = 0;
static long lat=0,lon=0;
if (count < timesTosend) {
while(gpsSerial.available()) { // check for gps data
if(gps.encode(gpsSerial.read())) { // encode gps data
gps.get_position(&lat,&lon); // get latitude and longitude
Serial.print("AT+CMGS=\"");
Serial.print(phone_no);
Serial.println("\"");
// Wait for '>'
while(Serial.read() != '>');
Serial.print(lat);
Serial.print(", ");
Serial.print(lon);
Serial.write(0x0D); // Carriage Return in Hex
Serial.write(0x0A); // Line feed in Hex
Serial.write(0x1A); // sends ctrl+z end of message
count++;
//The 0D0A pair of characters is the signal for the end of a line and beginning of another.
delay(5000);
}
}
}
}
ayushptl:
I dont understand what was the problem. I think the error is in gps part. I would really like to know.
You don't say what 'the problem' is but you are not going to get good results when you store a long integer (like 'lat' and 'lon') into floating point variables (like 'LAT' and 'LON').
Floats can store very big numbers but when they do, the inaccuracy is worse. Do you remember "significant digits" from school? The float actually has very few significant digits.
Imagine we can store 5 significant digits. We can store a number like 0.012345 or we can store 1234500 But we can't store 1234500.012345 and that's the problem with GPS latitude and longitude - the numbers are large and we want high precision.