Controlling LED's Using Sim908 and Arduino Mega2560

Hello …
I am using Sim908 Module and arduino mega2560 … by using this program in attachment i am able to read message on serial and also can turn on and off by giving command (#a1b1 or #a0b0) by serial… but when i send this command by sms … then my leds not go on and off . Please any body tell me what i have to include in code what changes are required ??\

char inchar; //Will hold the incoming character from the Serial Port.

int led1 = 9;
int led2 = 10;

void setup()
{
// prepare the digital output pins
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
//Initialize GSM module serial port for communication.

Serial.begin(9600);
Serial1.begin(9600);
delay(1000);
Serial.println(“Initializing…”);
Serial1.println(“AT+CNMI=2,2,0,0,0”); // AT Command to recieve a live SMS
delay(1000);

}

void loop()
{
if(Serial.available())
{
char a=Serial.read();
Serial1.print(a);

// Serial.print(a);
}

if(Serial1.available())
{

char b=Serial1.read();
Serial.print(b);
}
delay(100);

//If #a1b1c1d1 comes as sms, all led’s should light up.
if(Serial.available() >0)
{
inchar=Serial.read();
if (inchar==’#’)
{
delay(10);
inchar=Serial.read();

//first led
if (inchar==‘a’)
{
delay(10);
inchar=Serial.read();

if (inchar==‘0’)
{
digitalWrite(led1, LOW);
}
else if (inchar==‘1’)
{
digitalWrite(led1, HIGH);
}
delay(10);

//Second led
inchar=Serial.read();

if (inchar==‘b’)
{
inchar=Serial.read();
if (inchar==‘0’)
{
digitalWrite(led2, LOW);
}

else if (inchar==‘1’)
{
digitalWrite(led2, HIGH);
}
delay(10);

}
}
Serial.println(“AT+CMGD=1,4”); // delete all SMS
}
}
}

controlling.ino (1.5 KB)

char inchar; //Will hold the incoming character from the Serial Port.


 int led1 = 9;
 int led2 = 10;



void setup() 
{
  // prepare the digital output pins
 pinMode(led1, OUTPUT);
 pinMode(led2, OUTPUT);
 digitalWrite(led1, LOW);
 digitalWrite(led2, LOW);
 //Initialize GSM module serial port for communication.

  
  
  
  Serial.begin(9600);
  Serial1.begin(9600);
  delay(1000);
  Serial.println("Initializing...");
  Serial1.println("AT+CNMI=2,2,0,0,0"); // AT Command to recieve a live SMS
  delay(1000);
 
}

void loop()  
{
  if(Serial.available())
  {
    char a=Serial.read();
    Serial1.print(a);
    
//    Serial.print(a);
  }
  
  if(Serial1.available())
  {
     
    char b=Serial1.read();
    Serial.print(b);
  }
  delay(100);
  
  
  
  
  
  
  
  //If #a1b1c1d1 comes as sms, all led's should light up.
 if(Serial.available() >0)
 {
 inchar=Serial.read(); 
 if (inchar=='#')
   {
   delay(10);
   inchar=Serial.read(); 

 //first led
   if (inchar=='a')
     {
   delay(10);
   inchar=Serial.read();

 if (inchar=='0')
   {
   digitalWrite(led1, LOW);
   } 
 else if (inchar=='1')
   {
   digitalWrite(led1, HIGH);
   }
 delay(10);


 //Second led
 inchar=Serial.read(); 

 if (inchar=='b')
   {
   inchar=Serial.read();
 if (inchar=='0')
 {
 digitalWrite(led2, LOW);
 } 

 else if (inchar=='1')
 {
 digitalWrite(led2, HIGH);
 }
 delay(10);


 }
 }
 Serial.println("AT+CMGD=1,4"); // delete all SMS
 }
 }
 }

Hello …
I am using Sim908 Module and arduino mega2560 … by using this program in attachment i am able to read message on serial and also can turn on and off by giving command (#a1b1 or #a0b0) by serial… but when i send this command by sms … then my leds not go on and off . Please any body tell me what i have to include in code what changes are required ??

[code][/code] tags would improve the readability of your code immensely. You can edit your post to incorporate them.

Once you have done that you might want to reflect on which Serial port you are reading and writing to/from?

SIM908? Don't you need to explicitly put it into GSM mode?