Is SMS format depends on the sender mobile?

I want to read the SMS using Arduino and GSM module, I want to perform conditional programming based on the received SMS.

What I found really interesting is SMS format is different if I send message from different phones.

Output of my code is

Case1:(From Smart Phone)

Mobile Number is: +919542081456
Message Text: 5+22" Hello Arduino

Case2:(From normal phone)

Mobile Number is: +919848275606
Message Text: Hello Arduino

Is it really depends on the sender mobile phone? If yes how to move further to make my code independent on the sender mobile.

My code is

//===final code

char RcvdMsg[200] = "";
int RcvdCheck = 0;
int RcvdConf = 0;
int index = 0;
int RcvdEnd = 0;
char MsgMob[15];
char MsgTxt[50];
int MsgLength = 0;

void Config() // This function is configuring our SIM900 module i.e. sending the initial AT commands
{
delay(1000);
Serial.print("ATE0\r");
Response();
Serial.print("AT\r");
Response();
Serial.print("AT+CMGF=1\r");
Response();
Serial.print("AT+CNMI=1,2,0,0,0\r");
Response();
}


void setup()
{
  Serial.begin(9600);
  Config();
}

void loop()
{
  RecSMS();
}


void Response() // Get the Response of each AT Command
{
int count = 0;
Serial.println();
while(1)
{
if(Serial.available())
{
char data =Serial.read();
if(data == 'K'){Serial.println("OK");break;}
if(data == 'R'){Serial.println("GSM Not Working");break;}
}
count++;
delay(10);
if(count == 1000){Serial.println("GSM not Found");break;}

}
}

void RecSMS() // Receiving the SMS and extracting the Sender Mobile number & Message Text
{
if(Serial.available())
{
char data = Serial.read();
if(data == '+'){RcvdCheck = 1;}
if((data == 'C') && (RcvdCheck == 1)){RcvdCheck = 2;}
if((data == 'M') && (RcvdCheck == 2)){RcvdCheck = 3;}
if((data == 'T') && (RcvdCheck == 3)){RcvdCheck = 4;}
if(RcvdCheck == 4){RcvdConf = 1; RcvdCheck = 0;}

if(RcvdConf == 1)
{
if(data == '\n'){RcvdEnd++;}
if(RcvdEnd == 3){RcvdEnd = 0;}
RcvdMsg[index] = data;

index++;
if(RcvdEnd == 2){RcvdConf = 0;MsgLength = index-2;index = 0;}
if(RcvdConf == 0)
{
Serial.print("Mobile Number is: ");
for(int x = 4;x < 17;x++)
{
  MsgMob[x-4] = RcvdMsg[x];
  Serial.print(MsgMob[x-4]);
}
  Serial.println();
  Serial.print("Message Text: ");
for(int x = 46; x < MsgLength; x++)
{
  MsgTxt[x-46] = RcvdMsg[x];
  Serial.print(MsgTxt[x-46]);
}

Serial.println();

//****Resetting all the variables*****//

//RcvdMsg[200]={0};
RcvdCheck = 0;
RcvdConf = 0;
index = 0;
RcvdEnd = 0;
MsgMob[15];
MsgTxt[50];
MsgLength = 0;

Serial.flush();


}
}
}
}

You appear to be using Serial to talk to both Serial monitor AND the GSM unit?

@dannable I did n't get you.

What GSM device are you using? How is it connected to the Arduino?

What is the Serial Monitor supposed to so with:

Serial.print("ATE0\r");
Serial.print("AT\r");
Serial.print("AT+CMGF=1\r");
Serial.print("AT+CNMI=1,2,0,0,0\r");

Nothing. So, obviously you are using Serial to talk to the phone.

What is the phone supposed to do with:

if(Serial.available())
{
char data =Serial.read();
if(data == 'K'){Serial.println("OK");break;}
if(data == 'R'){Serial.println("GSM Not Working");break;}

Nothing, so apparently, you are reading from, and writing to, the Serial Monitor.

Isn't it obvious that that is schizophrenic? It should be obvious that that is NOT going to work.

Dear sir,

@Pauls,

The two code snippets you have quoted above are to configure the GSM module used. As we don't we use a RS232 cable, we can't use software to configure it. So we print AT commands on to serial monitor, and we get the response of the AT command through response() function. And also we are printing that output on to serial monitor for our sake. Truly they don't do any thing with incoming SMS. Those things are only to configure the module to our task.

Sir, Do I need to clarify any other things.

I understand that you are talking only about this configuration. I am successfully receiving the SMS's,
but format of the SMS is different if they are sent from normal phone and smartphone.

Thank you sir.

@dannable

My connections are

Tx pin of Arduino to Rx pin of GSM module
Rx pin of Arduino to Tx pin of GSM module

Vcc, GND of the GSM module are connected to 5V,GND on the arduino respectively.

  • I am not using official Arduino GSM Shield. I am using GSM SIM COM SIM900 Module.