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);
}
}
}
}
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.