user41481: How can I turn the LED on and off using a received text message?
The sim card is able to receive the message but I can't change the pin status. I also can't see anything in the serial monitor upon reception of the message.  
Below is my code.
#include <SoftwareSerial.h>
SoftwareSerial gsm(2,3);
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, HIGH);
}

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

  if ( msg == "ON")
  {
    digitalWrite(LED, HIGH);
    delay(1000);
  }
  if (msg == "OFF")
  {
    digitalWrite(LED, LOW);
    delay(1000);
  }
}

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


user38949: Try this code.
#include <SoftwareSerial.h>
SoftwareSerial gsm(2,3);
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, HIGH);
}

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

  while(gsm.available() > 0)
  {
    Serial.write(gsm.read());
  }

  if ( msg == "ON")
  {
    digitalWrite(LED, HIGH);
    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);
}


41481: <p>How can I turn the LED on and off using a received text message?</p>

<p>The sim card is able to receive the message but I can't change the pin status. I also can't see anything in the serial monitor upon reception of the message.  </p>

<p>Below is my code.</p>

<pre><code>#include &lt;SoftwareSerial.h&gt;
SoftwareSerial gsm(2,3);
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, HIGH);
}

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

  if ( msg == "ON")
  {
    digitalWrite(LED, HIGH);
    delay(1000);
  }
  if (msg == "OFF")
  {
    digitalWrite(LED, LOW);
    delay(1000);
  }
}

void showSMS()
{
 gsm.print("AT+CMGF=1\r");
 gsm.print("AT+CNMI=2,2,0,0,0\r");
 delay(1000);
 if (gsm.available()&gt;0)
 {
  msg=gsm.read();
  Serial.print(msg);
 }
}
</code></pre>
 38949: <p>Try this code.</p>

<pre><code>#include &lt;SoftwareSerial.h&gt;
SoftwareSerial gsm(2,3);
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, HIGH);
}

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")
  {
    digitalWrite(LED, HIGH);
    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>
