Don't you suppose that you should be reading from the device connected to the serial port? You never assign a value to smsbuffer, so it's a mystery why you expect it to equal "B" or "L".
hello,
want to control an outlet with a sms, but you can not.
I'm using Arduino UNO and SIM900 GPRS module v1.0.
the pins are 0.1 Tx Rx?
on the board SIM900 have led the net to flash.
My problem may be the code, I am getting crazy.
I put this code and nothing.
include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(0, 1);
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
}
}
}
}
if(SIM900.available() >0)
{
inchar=SIM900.read();
if (inchar=='#')
{
delay(10);
inchar=SIM900.read();
if (inchar=='a')
{
This not bullet prof. if someone dials to the sim card inserted on the SIM900 it will appear on the serial port "RING".
That string will trigger your if(SIM900.available() >0) and then all the ifs will fail
Your code must be waiting to see when an SMS has arrived, when arrived get the position of that SMS, read it and parse it to get the body of the message, who send it and finally execute something using a strcmp() according with the body of the message