user55933: I'm executing this code to control a LED with GSM SIM900 message but there are two problems. First, it receives messages sometimes and some times doesn't. The second is that it doesn't execute the if conditions that are on the GSM message when received. 
Is there a problem with my GSM module? Can any one help?
#include <SoftwareSerial.h>
SoftwareSerial gsm(9,10);
String msg;
const int LED = 13;

void setup() {
  gsm.begin(9600);
  Serial.begin(9600);
  Serial.println("PUMP CONTROL");
  Serial.println("t : to receive text");
  delay(1000);

  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
}

void loop() {
  if (Serial.available()>0)
  switch(Serial.read())
  {
    case 't':
    showSMS();
    break;
  }

  while(gsm.available() > 0)
  {
    Serial.write(gsm.read());
  }
  if ( msg == "ON")
  {
    Serial.println("ON");
    digitalWrite(LED, HIGH);
     Serial.println("ON1");
    delay(1000);
  } else if (msg == "OFF")
  {
    digitalWrite(LED, LOW);
    delay(1000);
  }
  if(msg != "") msg = "";
}

void showSMS()
{
 gsm.print("AT+CMGF=1\r");
 gsm.print("AT+CNMI=2,2,0,0,0\r");
 delay(1000);
 msg = "";
 while(gsm.available() > 0)
 {
  msg += gsm.read();
 }
 Serial.println(msg);
}


user55933: I’ve solved the condition problems by making the condition with the ASCII code of ON and OFF.
I replaced:
if ( msg == “ON”) 

with 
if(msg.indexOf("ON")>=0) 

and replaced: 
else if (msg == "OFF")

with
if(msg.indexOf("OFF")>=0) 


55933: <p>I'm executing this code to control a LED with GSM SIM900 message but there are two problems. First, it receives messages sometimes and some times doesn't. The second is that it doesn't execute the <code>if</code> conditions that are on the GSM message when received. </p>

<p>Is there a problem with my GSM module? Can any one help?</p>

<pre><code>#include &lt;SoftwareSerial.h&gt;
SoftwareSerial gsm(9,10);
String msg;
const int LED = 13;

void setup() {
  gsm.begin(9600);
  Serial.begin(9600);
  Serial.println("PUMP CONTROL");
  Serial.println("t : to receive text");
  delay(1000);

  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
}

void loop() {
  if (Serial.available()&gt;0)
  switch(Serial.read())
  {
    case 't':
    showSMS();
    break;
  }

  while(gsm.available() &gt; 0)
  {
    Serial.write(gsm.read());
  }
  if ( msg == "ON")
  {
    Serial.println("ON");
    digitalWrite(LED, HIGH);
     Serial.println("ON1");
    delay(1000);
  } else if (msg == "OFF")
  {
    digitalWrite(LED, LOW);
    delay(1000);
  }
  if(msg != "") msg = "";
}

void showSMS()
{
 gsm.print("AT+CMGF=1\r");
 gsm.print("AT+CNMI=2,2,0,0,0\r");
 delay(1000);
 msg = "";
 while(gsm.available() &gt; 0)
 {
  msg += gsm.read();
 }
 Serial.println(msg);
}
</code></pre>
 55933: <p>I’ve solved the condition problems by making the condition with the ASCII code of ON and OFF.</p>

<p>I replaced:</p>

<pre><code>if ( msg == “ON”) 
</code></pre>

<p>with </p>

<pre><code>if(msg.indexOf("ON")&gt;=0) 
</code></pre>

<p>and replaced: </p>

<pre><code>else if (msg == "OFF")
</code></pre>

<p>with</p>

<pre><code>if(msg.indexOf("OFF")&gt;=0) 
</code></pre>
