GPS Locator

I m working on GPS Locator

I m using GPS S1315RL , GSM SIM 300 and Arduino UNO in this project that sends lattitude and longitude value to the mobile via text msg.....

My interfacing work is completed..

My code:-

#include <SoftwareSerial.h>
#include "TinyGPS.h"
char phone_no[]="09870820167";
long lat,lon; // create variable for latitude and longitude object
SoftwareSerial gpsSerial(2, 3);
TinyGPS gps; // create gps object
void setup()
{
 Serial.begin(9600); // connect serial
gpsSerial.begin(9600); // connect gps sensor
delay(20000);
Serial.println("AT+CMGF=1");
delay(20000);
}

void loop()
{
Serial.print("AT+CMGS=\"");
Serial.print("098XXXXXXXXX");
Serial.println("\"");
while(Serial.read()!='>');
{
 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(lat);Serial.print(",");
Serial.print(lon);
delay(2000);
Serial.write(0x1A);  // sends ctrl+z end of message
Serial.write(0x0D);  // Carriage Return in Hex
Serial.write(0x0A);  // Line feed in Hex 

//The 0D0A pair of characters is the signal for the end of a line and beginning of another.
delay(50000);
}
}
}
}

O/P:-(Sends sms to the mobile)

AT+CMGS="098XXXXXXXXX"
AT+CMGS="098XXXXXXXXX"
AT+CMGS="098XXXXXXXXX"
AT+CMGS="098XXXXXXXXX"
AT+CMGS="098XXXXXXXXX"
AT+CMGS="098XXXXXXXXX"
19203318,72843402

i dont want this AT command in sms.....
i want only GPS value that seen in the last line of o/p

pls tell me the changes in code..

Please CLICK the MODIFY button.
highlight the code.
CLICK the "#" CODE button to create a scroll window for scrolling through the code.

May also want to remove the connect number!
phone_no[]

OMG! I love it ! XD

I remove that line ^^ "char Phone_no[]"

Still same o/p

LOOK AT THE UPPER RIGHT CORNER OF THE POST WINDOW .
DO YOU SEE THE "MODIFY" BUTTON ?

Please CLICK the MODIFY button.
highlight the code.
CLICK the "#" CODE button to create a scroll window for scrolling through the code.

The "#" is there to make your code easier for us to read. Not using it will only discourage people from even reading it.

Ajay1295:
i dont want this AT command in sms.....

I assume the problem is the repeated AT+CMGS="... lines before it sends an SMS. I think the cause is that the modem and GPS are sending and receiving independently and your control logic doesn't deal with that properly. If you only want to send an SMS when you have received a complete GPS message then don't start sending the SMS until you have received the GPS message. At the moment you're starting sending the SMS every time through loop, but most of the time you won't have any outstanding GPS input and won't have received the complete GPS message, so your code won't go through the 'while(gpsSerial.available())' loop at all and won't send the body of the SMS.

It would also be worth setting up a debug output stream and using that to print out the complete responses from the modem so you can see what it's doing about your commands.