Control Led with Gsm shield

Hello ! I’m using uno +gsm shield to control a Led at pin13 by sms
I have modified the code from this project http://scuola.arduino.cc/lesson/LVEVK1a/Using_SMS_messages_to_control_LED_color
like this

#include <GSM.h> // This includes the GSM library, included in your Arduino IDE

 
#define PINNUMBER "" // declaration of the constant PINNUMBER used to push the pin number of the SIM card
#define PIN 13 // declaration of the constant PIN, and setting it to output nr. 6


GSM gsmAccess; // opens up GSM access on the shield.
GSM_SMS sms;
 
char remoteNumber[20]; // Variable to store the remote number from the modem.
char c; //Variable for reading the sms messages from the SIM card

int x=0; //Counter for the number of SMS messages processed
char lastm; //Variable to stop SMS replying
String lastMess; //for storing the whole message

// **** 2 Setup ****
 
void setup() {
  //Setup for SMS recieving. Serial setup makes it possible to monitor the status on your PC while connected
  Serial.begin(9600);
  Serial.println("SMS Recieving");
   

   
  boolean notConnected = true; // this defines a variable that indicates no GSM connection if true
  while(notConnected) {  // if there is no connection, the program runs gsmAcess. gsmAcess returns GSM_READY when connected
    if(gsmAccess.begin(PINNUMBER"0462")==GSM_READY) // If you have a PIN number on your SIM card, write it as parameters here in quotes. PINNUMBER"9876"
    notConnected = false;
    else {
      //messages printed on the serial monitor or LCD screen, then it tries again in 1000 milliseconds
      Serial.println("No connection");
 
    }
  }
  // if connection is established
  Serial.println("GSM connected"); //GSM connected
  Serial.println("Waiting"); //Waiting for SMS
   
}
 
// **** 3 The loop ****
 
void loop() {
 
  if (lastMess == "H")
    {
      digitalWrite(13,HIGH);
    }
    else if (lastMess == "L")
    {
      digitalWrite(13,LOW);
    }
  //reading messages
  if (sms.available()) // if there are SMS on the SIM card
  {
    x++; //message counter adds one
    sms.remoteNumber(remoteNumber, 20);   
     
    //Show the message on monitor
    Serial.println("Messages received from");
    Serial.println(remoteNumber); //Prints senders number on the serial monitor
    Serial.println("Message:");
 
     
    while(c=sms.read()) {
      String nextChar = String (c);
      String Mess = (lastMess + nextChar);
      lastMess = Mess;
      /*sms.read collects one digit of the messages at time and stores it in the variable c.
      This while loop builds a String variable "lastMess" from each byte in the messages for displaying.
      */
    }
     
    Serial.println(lastMess); // prints the whole messages on the monitor and LCD screen
   
     
  }//end for
   
    sms.flush(); //discards the SMS message

}

I didn’t have any errors at the uploading but when i send the sms " H" , the sms received but pin13 didn’t go to high
What’s going wrong? here is the photo with the serial monitor http://postimg.org/image/v121wnhwr/

      String nextChar = String (c);
      String Mess = (lastMess + nextChar);
      lastMess = Mess;

If you are going to abuse the Arduino using the String class, at least do it intelligently:

lastMess += c;

All those constructor, copy operator calls, and destructor calls are making swiss cheese of your memory,

If you want a one letter message to turn the LED on or off, don't use the String class at all.

Are you sure that the LED is wired correctly?

Finally with this code i managed to turn the led ON !

/*
 SMS receiver
 
 This sketch, for the Arduino GSM shield, waits for a SMS message 
 and displays it through the Serial port. 
 
 Circuit:
 * GSM shield attached to and Arduino
 * SIM card that can receive SMS messages
 
 created 25 Feb 2012
 by Javier Zorzano / TD
 
 This example is in the public domain.
 
 http://arduino.cc/en/Tutorial/GSMExamplesReceiveSMS
 
*/

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER "0462"

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[20];  
int led=13;
void setup() 
{
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  } 

  Serial.println("SMS Messages Receiver");
    pinMode(led,OUTPUT);
  // connection state
  boolean notConnected = true;
  
  // Start GSM connection
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  
  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop() 
{
  char c;
  
  // If there are any SMSs available()  
  if (sms.available())
  {
    Serial.println("Message received from:");
    digitalWrite(led,HIGH);
    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal    
    // Any messages starting with # should be discarded
    if(sms.peek()=='#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
    }
    
    // Read message bytes and print them
    while(c=sms.read())
      Serial.print(c);
      
    Serial.println("\nEND OF MESSAGE");
    
    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}

What changes i have to do in order to being able turning OFF the LED ?

any help ??????

What changes i have to do in order to being able turning OFF the LED ?

Look at that code. What causes the LED to be turned on? Under what circumstances does that happen?

It has NOTHING to do with what is IN the message, so, there is lots more you need to do to make the LED come on correctly. When you understand that, it will be trivial to make the LED turn off correctly.

i need to set a string variable ,for example string smstext ; and a part of code like this :

if (smstext == "H")
    {
      digitalWrite(13,HIGH);
    }
    else if (smstext == "L")
    {
      digitalWrite(13,LOW);
    }

am i right ?? where i have to attach this part to the previous code ??

Why don't you try a few string functions on smstext to see exactly what you are comparing?

I would start by checking it's length. If it's longer than one character you need to figure out what the other characters are...

i need to set a string variable ,for example string smstext ; and a part of code like this :

No. Your instruction is one character.

if(c == 'H')
   // turn the LED on
else if(c == 'L')
   // turn the LED off

with this code :

#include <GSM.h> // This includes the GSM library, included in your Arduino IDE

 
#define PINNUMBER "0462" // declaration of the constant PINNUMBER used to push the pin number of the SIM card
#define PIN 13 // declaration of the constant PIN, and setting it to output nr. 6


GSM gsmAccess; // opens up GSM access on the shield.
GSM_SMS sms;
 
char remoteNumber[20]; // Variable to store the remote number from the modem.
char c; //Variable for reading the sms messages from the SIM card

int x=0; //Counter for the number of SMS messages processed
char lastm; //Variable to stop SMS replying
String lastMess; //for storing the whole message

// **** 2 Setup ****
 
void setup() {
  //Setup for SMS recieving. Serial setup makes it possible to monitor the status on your PC while connected
  Serial.begin(9600);
  Serial.println("SMS Recieving");
   

   
  boolean notConnected = true; // this defines a variable that indicates no GSM connection if true
  while(notConnected) {  // if there is no connection, the program runs gsmAcess. gsmAcess returns GSM_READY when connected
    if(gsmAccess.begin(PINNUMBER)==GSM_READY) // If you have a PIN number on your SIM card, write it as parameters here in quotes. PINNUMBER"9876"
    notConnected = false;
    else {
      //messages printed on the serial monitor or LCD screen, then it tries again in 1000 milliseconds
      Serial.println("No connection");
 
    }
  }
  // if connection is established
  Serial.println("GSM connected"); //GSM connected
  Serial.println("Waiting"); //Waiting for SMS
   
}
 
// **** 3 The loop ****
void loop() {
 

  //reading messages
  if (sms.available()) // if there are SMS on the SIM card
  {
    x++; //message counter adds one
    sms.remoteNumber(remoteNumber, 20);   
     
    //Show the message on monitor
    Serial.println("Messages received from");
    Serial.println(remoteNumber); //Prints senders number on the serial monitor
    Serial.println("Message:");
 
     
    while(c=sms.read()) {
  if (c == 'H')
    {
      digitalWrite(13,HIGH);
    }
    else if (c == 'L')
    {
      digitalWrite(13,LOW);
    }
      String nextChar = String (c);
      String Mess = (lastMess + nextChar);
      lastMess = Mess;
      /*sms.read collects one digit of the messages at time and stores it in the variable c.
      This while loop builds a String variable "lastMess" from each byte in the messages for displaying.
      */
    }
     
    Serial.println(lastMess); // prints the whole messages on the monitor and LCD screen
   
     
  }//end for
    sms.flush(); //discards the SMS message
}

i managed when sending ‘H’ to turn on the led at pin 13 , but with very low brightness ,and when sending ‘L’ to turn off the led !
Why does this happen ,blinking the led with low brightness ? I measured 5 V at pin 13 ! do i need a stronger power supply ? i use a 12 V ,800 mA

but with very low brightness

I'm sure that if you declared the LED pin to be an output pin, it would be brighter.

so you believe that the problem is on the code ?

so you believe that the problem is on the code ?

It's actually with what is NOT in the code. You need a call to pinMode() in setup(), for the LED pin, to make it an OUTPUT pin.