Sending SMS for Remote Control - SOLVED

Anybody here having experience with sending SMS to a GPRS Shield with SIM900 connected to Uno?

I have been trying with two different geeetech.com shields. Receiving appears to be the part not working, because sending SMS or voice is perfectly ok. I have been trying with different codes, but still not receiving SMS. I am using pin 7 and pin 8 for serial connection to Uno. Both module are connected to gnd of course and they are powered from each their 5V ps via Vin.

Below you see the code I'm using.
It should be waiting a SMS call (with a message with either ... #a0 ... or ... #a1 ... ) from the mobile phone and upon receipt reading/converting the SMS message to turn on/off pin 13 of Uno. The only reaction I get is, that the serial monitor on start op the shield, print the word Ready...

The below code looks simple, but do not work. I guess it should work with any GPRS shield with SIM900!
Link to the project: https://www.geeetech.com/wiki/index.php/GPRS_Shield_V2.0#Interface_Function

#include <SoftwareSerial.h>

char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(7,8);

int led = 13;

void setup()
{
Serial.begin(19200);
// set up the digital pins to control
pinMode(led, OUTPUT);
digitalWrite(led, LOW);

// wake up the GSM shield
SIM900.begin(19200);
delay(20000); // give time to log on to network.
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
// blurt out contents of new SMS upon receipt to the GSM shield's serial out
delay(100);
Serial.println("Ready...");
}

void loop()
{
//If a character comes in from the cellular module...
if(SIM900.available() >0)
{
inchar=SIM900.read();
if (inchar=='#')
{
delay(10);

inchar=SIM900.read();
if (inchar=='a')
{
delay(10);
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led, LOW);
}
else if (inchar=='1')
{
digitalWrite(led, HIGH);
}
delay(10);
SIM900.println("AT+CMGD=1,4"); // delete all SMS
}
}
}
}

I think it would be better to read every character in the SMS and then do something on whether the received characters are what you are expecting or not.

Thanks ieee488 for your kind commends. As I read the code, it takes each SMS character for check one by one in the if-statements. Is this the same as what you mean? I wonder whether the GPRS shield are missing (needs) a (AT) command to enter into listening (receiving) mode?

You are assuming that the first character you see will be a #

Instead of that just test
if(SIM900.available() >0)

If it is then read the character and print it out.
That way you will see what you are actually getting.

Many many thanks ardly for your suggestions. I did make a serial print out of each SMS characters in the "if" statements as you suggested - indeed they printed out - and the best, but I wonder how - the pin 13 LED can now be remotely turned on and off by the SMS I'm sending. Every things works NOW. I thank you again,ardly for your hints.

Fuksen:
..... and the best, but I wonder how - the pin 13 LED can now be remotely turned on and off by the SMS I'm sending.

Your original code checked for an available character and read it but then assumed that further characters would be available after a delay - which may or may not be true. Your new code is probably better structured.

If you post your working code people will probably highlight the key changes. If you are going to post code please put it inside the </> tags.