How can I let Arduino GSM shield respond to specific numbers?

I am working on a project where i send 1 to my GSM Shield to switch on the LED connected to pin 13 and off by sending 0, but i would like to modify the code in order for the GSM Shield to respond only to the number specified. Here is my code, in my case I used an example phone number ... 


// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from

char senderNumber[20];
char adminNumber[20]="+123456789234";

void setup()
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);

  // initialize serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  Serial.println("SMS Messages Receiver");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while (notConnected)
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
      Serial.println("Not connected");

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");

void loop()
  char c;

  sms.remoteNumber(senderNumber, 20);
  sms.remoteNumber(adminNumber, 20);
    // If there are any SMSs available()
  if (sms.available())
    Serial.println("Message received from:");

     // Get remote number
    sms.remoteNumber(senderNumber, 20);

       // Any number besides admin number will not change the state of the pin
    while(adminNumber == senderNumber){
        // Any messages starting with 1 will set pin 13 to HIGH
if (sms.peek() == '1'){
      digitalWrite(13, HIGH);
        // Any messages starting with 0 will set pin 13 to LOW
else if(sms.peek() == '0'){
      digitalWrite(13, LOW);


    // Read message bytes and print them
    while (c = sms.read())
    Serial.println("\nEND OF MESSAGE");

    // Delete message from modem memory
    Serial.println("MESSAGE DELETED");




sort by: active | newest | oldest

What do YOU mean by "respond only to the number specified"

The way its written, it should respond only to an SMS from the "correct" number.

Mechatron147 (author)  steveastrouk1 year ago

That's what I want but its not working. By number specified I mean the number in the array "adminNumber"

So its responding to every number, or not even the right number ?

Mechatron147 (author)  steveastrouk1 year ago

It skips the while loop where i compared the senderNumber to adminNumber... It displays the message content and the senderNumber but the LED doesn't switch on

Your string contains extra characters. Search for the adminnumber as a string within the sendernumber, not an == statement

Mechatron147 (author)  steveastrouk1 year ago

How exactly can I do that? Can you give me a sample code?

Mechatron147 (author) 1 year ago

Sorry I didn't get what you mean. Can you clarify?

There are two IF statements defining what happens when a number is received - change them to what you need.
Sorry but can't make it any clearer.

I wonder if its the OPs code, or if its been, ahem, borrowed.

Mechatron147 (author)  steveastrouk1 year ago

Actually I used the Send SMS example from the IDE and modified it

So why don't you change it, it is just two IF statements...