Receive SMS

Hi guys, can you help me how to code for receiving sms? i have a code for sending sms and it works well but i dont know how to make a code for receiving sms. can you modify my code and add some code for receiving sms? i just want to receive 2 messages the ON or OFF. i am using sim900d and arduino mega 2560. here is my code.

void send_msg(char *number, char *msg)
{
  char at_cmgs_cmd[30] = {'\0'};
  char msg1[160] = {'\0'};
  char ctl_z = 0x1A;

  sprintf(msg1, "%s%c", msg, ctl_z);
  sprintf(at_cmgs_cmd, "AT+CMGS=\"%s\"\r\n",number);
  
  sendGSM(at_cmgs_cmd);
  delay(100);
  delay(100);
  delay(100);
  sendGSM(msg1);
  delay(100);
}

void sendGSM(char *string){
  Serial.write(string);
  delay(90);
}

Thanks in advance! :slight_smile:

I just asked a similar question, what shield are you using?

SIMCOM SIM900D. can you help me with this? or anyone else? :slight_smile:

I just found some sample code, not sure if this will work or not, good luck trying to find a tutorial, I have been searching for a while. http://www.elecrow.com/download/Using_SMS_to_Control_Relay_Hardware_Serial.ino

Thanks! what if i wont use the serial monitor? just when the module receive the text, it will read the message automatically and do the operation with respect to the message it receives?

I am actually trying to do the same thing, but yeah, just take out the functions you aren't using and modify it for what you need it to do. You just need to go through each line and see what it is doing.

Actually check out this: Receive SMS example - Arduino GSM Shield - Arduino Forum