//both madule working properly Separately
//but when i combine the code gsm sms recieve and sends properly but gsm is not working
#include <SoftwareSerial.h>//for gps
#include <TinyGPS.h>
SoftwareSerial gpsSerial(11, 12); //gps software Serial
TinyGPS gps;
float fkmph;
long flat, flon;
float fmps;
void setup(){
Serial.begin(9600); // connect GSM on Hardware Serial Rx 0 Tx 1
gpsSerial.begin(9600); // connect gps sensor
Serial.println("AT+CMGF=1");//set sms in text mode
Serial.println("AT+CNMI=2,2,0,0,0");//for recieving data live for gsm module
SendMessage();//sending sms for checking while gsm is working or not
delay(1000);
}
void loop(){
if(gpsSerial.available()>0)//this if statment is not truning true while gps is connected and blinking
{
// check for gps data
if(gps.encode(gpsSerial.read()))
{
Serial.println("Location is:");
gps.get_position(&flat,&flon); // get latitude and longitude
fkmph = gps.f_speed_kmph();
}
}
//code for gsm reading data
if(Serial.available() >=0)//code for gsm
{
String mytext(Serial.readString());//receiving sms
Serial.println(mytext);// printing sms incomming sms
}
}
//
void SendMessage()
{
Serial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
Serial.println("AT+CMGS="+92###########"\r"); // Replace x with mobile number
delay(1000);
Serial.println("Msg to be send");// The SMS text you want to send
delay(100);
Serial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}