Receive sms with gsm module

Hello everybody. I have bought a bit time ago a siemens tc35 gsm module and i have tried to do the operations of calling and sending of sms and i haven’t had problems. Now, i would want that Arduino “do something” when it received a certain sms who contain, for now, only a single character. The sketch i had wrote is:

#include <SoftwareSerial.h> 
SoftwareSerial gsmSerial(2,3);
char gsm_sms = 0; 


void setup(){
  pinMode(13, OUTPUT);
  gsmSerial.begin(9600);
  Serial.begin(9600);
}

void loop(){
  if(Serial.available()>0) { 
    gsm_sms=gsmSerial.read();
    if (gsm_sms == 'A'){
      digitalWrite(13,HIGH);
    }
    else if (gsm_sms == 'a'){
      digitalWrite(13,LOW);
    }
    }
}

that doesn’t work. My objective is, simply, turn on the led connect to the pin 13 with an sms who contain ‘A’ and turn off it with ‘a’. I think that the not operative mode is caused by the not presence of AT commands. I have tried to use also this sketch but it doesn’t work the same:

void setup(){
  Serial.begin(9600);
}

void loop (){
  
while(Serial.available()){
  Serial.println("AT");
  delay(100);
  Serial.println("AT+CMGR");
  delay(100);
  gsm_char = Serial.read();
  Serial.print("Received char is: ");
  Serial.println(gsm_char);
}
}

Can someone help me with the reception of sms with arduino and a gsm module? Thanks a lot.

Your second piece of code won't even compile.

error: 'gsm_char' was not declared in this scope

If you do declare gsm_char then open serial monitor and type something, press return and it works. However I don't think it's doing what you want it to do as you don't actually talk to the modem.

Sorry, i haven't copied the declaration:

char  gsm_char

in my previous post.

What you suggest for my objective?

Look at the link in my signature. It's all standard instructions that should work on most modems.

i have read the link in your signature and i have tried to upload this sketch for testing the AT commands.

#include <SoftwareSerial.h>

SoftwareSerial GPRS(7, 8);

unsigned char buffer[64];  // buffer array for data receive over serial port
int count=0;               // counter for buffer array 

void setup()
{
  GPRS.begin(19200);
  Serial.begin(19200);
}

void loop()
{
  if (GPRS.available())
  {
    while(GPRS.available())
    {
      buffer[count++]=GPRS.read();
      if(count == 64)break;
    }
    Serial.write(buffer,count);
    clearBufferArray();
    count = 0;
  }
  if (Serial.available())
    GPRS.write(Serial.read());
}

void clearBufferArray()
{
  for (int i=0; i<count;i++)
  {
    buffer[i]=NULL;
  }
}

But when i enter “AT” in the serial monitor i haven’t any answer, instead to receive “OK” as answer.

That means it is responding but you have echo turned off.

Try replacing void setup() with:

void setup()
{
  GPRS.begin(19200);
  GPRS.print("ATE1\r");  // Echo on
  Serial.begin(19200);
}

Nothing happened

Nothing?

No, only that on the serial monitor i see "ATE1".

And then what happens if you type AT, and press return?

Nothing, i don't receive answer

Not even OK?

Not even OK. However the module works well: i don’t have any problem in sending sms or making call.

All you really needed to do was merge the two pieces of code you have, and listen for the modem talking, not Serial Monitor:

#include <SoftwareSerial.h> 
SoftwareSerial gsmSerial(2,3);
char gsm_sms = 0; 

void setup(){
  pinMode(13, OUTPUT);
  gsmSerial.begin(9600);
  Serial.begin(9600);
  delay(20000); // give time to log on to network.
  gsmSerial.print("AT+CMGF=1\r"); 
  delay(100);
  gsmSerial.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
  Serial.println("Ready...");
}

void loop(){
  if(gsmSerial.available()) { 
    gsm_sms=gsmSerial.read();
    if (gsm_sms == 'A'){
      digitalWrite(13,HIGH);
    }
    else if (gsm_sms == 'a'){
      digitalWrite(13,LOW);
    }
  }
}

I’ve compiled it but not tested it as I don’t have a modem to hand. You might want to display the contents of gsm_sms on Serial Monitor so you can see what, if anything, is happening.

it's really strange. The led doesn't turn on. Whether with your blended code or with a little change:

void setup(){
  pinMode(13, OUTPUT);
  gsmSerial.begin(9600);
  Serial.begin(9600);
  delay(20000); // give time to log on to network.
  gsmSerial.print("AT+CMGF=1\r"); 
  delay(100);
  gsmSerial.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);
  gsmSerial.println("AT+CMGR");
  delay(100);
  Serial.println("Ready...");
}

Anyway, thanks a lot for all your support.