VOID LOOP() not working

Hey guys, im new to using the arduino board, and iv written some small code for a project in my person time however the SMSrecieve function initialises and receives the first message fine, but it will not loop for some reason it just loops and sends out “sms receiver” to the serial monitor and doesnt actually receive the 2nd or third message unless i restart it. I am assuming its a noobie mistake as its been years since i last programmed and have forgotten Alot! any help would be appreciated

#include <GSM.h>

#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;
boolean notConnected = true;

// char array of the telephone number to send SMS
// change the number 1-212-555-1212 to a number
// you have access to
char remoteNumber[10][20]= {"0411216560", "0411216560", "0411216560", "0411216560", "0411216560", "0411216560", "0411216560", "0411216560", "0411216560", "0411216560"}; // character array for storing phone numbers. currently has a set size need to find more efficient way to input
char senderNumber[20];

// char array of the message
char txtMsg[200]="MESSAGE SEND TO ARDUINO TEST";

void sendSMS(){
 for (int i=0; i < 11; i++) // create a for loop based on the number of phone number entries to loop through the text message and increment counter. MUST FIND MORE EFFICIENT SELF ADJUSTING WAY.
 {
         Serial.print("Message to mobile number: ");
         Serial.println(remoteNumber[i]);

         // sms text
         Serial.println("SENDING");
         Serial.println();
         Serial.println("Message:");
         Serial.println(txtMsg);


      
       
         // send the message
         sms.beginSMS(remoteNumber[i]);
         sms.print(txtMsg);
         sms.endSMS(); 
         Serial.println("\nCOMPLETE!\n");  

        
         }
           }

void SMSsetup(){

 // initialize serial communications
 Serial.begin(9600);

 Serial.println("SMS Messages Sender");

 // connection state
 boolean notConnected = true;

 // Start GSM shield
 // If your SIM has PIN, pass it as a parameter of begin() in quotes
 while(notConnected)
 {
       if(gsmAccess.begin(PINNUMBER)==GSM_READY)
       notConnected = false;
   else
   {
       Serial.println("Not connected");
       delay(1000);
   }
 }
       Serial.println("GSM initialized");


 
}



void SMSrecieve() {
 

 // initialize serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial) {
   ; // wait for serial port to connect. Needed for native USB port only
 }

 Serial.println("SMS Messages Receiver");

 // connection state
 boolean notConnected = true;

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

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



void setup() {
 // put your setup code here, to run once:
 SMSsetup();
 sendSMS();
 // initialize serial communications and wait for port to open:
 SMSrecieve(); 
}

void loop() {



  char c;

 // If there are any SMSs available()
 if (sms.available()) {
   Serial.println("Message received from:");

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

   // An example of message disposal
   // Any messages starting with # should be discarded
   if (sms.peek() == '#') {
     Serial.println("Discarded SMS");
     sms.flush();
   }

   // Read message bytes and print them
   while (c = sms.read()) {
     Serial.print(c);
   }

   Serial.println("\nEND OF MESSAGE");

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

 delay(1000);

}

This is because the send sms is in the set up which is called only once (at each reset)

The loop only checks what you receive

yeah sorry, i asked that wrong. the loop only receives the first message it doesn’t actually receive more than one. The void loop section only loops once, it refuses to loop again. my serial monitor output is “message deleted” and it will not loop back to the start again

How do you know that loop() is 'looping' only once? Add a Serial.println() in the beginning of loop()

void loop()
{
  Serial.println("Entering loop()");

  ...
  ...
}

If that does not display Entering loop() repeatedly you are right.

sterretje:
How do you know that loop() is 'looping' only once? Add a Serial.println() in the beginning of loop()

void loop()

{
  Serial.println("Entering loop()");

...
  ...
}



If that does not display *Entering loop()* repeatedly you are right.

Well. i added the "Entering Loop" and i figured i might as well add a "exiting loop" aswell. Seems as though its entering and exiting without executing anything in the middle.... weird i cant figure it out

What if sms.available() is never true? Since all the code in loop is conditional on that, if that's never true, the code will never execute.

Are you sure the GSM modem is working and connected correctly and communicating with your carrier?

DrAzzy:
What if sms.available() is never true? Since all the code in loop is conditional on that, if that's never true, the code will never execute.

Are you sure the GSM modem is working and connected correctly and communicating with your carrier?

Hmmm, well it sends messages fine, and receives the FIRST message but if i were to send 2-x messages from my phone to the board, it will only receive the first message, and once i reboot the whole thing and run the program again, it will receive the second one. so im assuming its a software issue?

Why do you restart serial and GSM (calling begin again) in SMS receive function. Get rid of that. You already initialized all this in the setup

Also just having some doubts - how is your GSM shield connected?

J-M-L:
Why do you restart serial and GSM (calling begin again) in SMS receive function. Get rid of that. You already initialized all this in the setup

Also just having some doubts - how is your GSM shield connected?

i commented out the whole section and commented out calling the function. it still does the same thing. weird.... my GSM shield is connected to my arduino uno directly ontop no modifications nothing fits straight in. the weird thing about this was that at one stage when i first started running my code it worked and kept looping through the display sms received however it just stopped one day and im unsure if its something iv changed or a hardware issue which i think is unlikely

Time to share how you connected up things. Hand drawing following your actual wires best option

I haven't connected any wires the arduino GSM shield literally plugs straight into my arduino uno, so it's everything standard I haven't made any modifications

What GSM Shield do you have?

I don't particularly like the way you framed the question, but nonetheless, I'd be checking the requirement of the library function for SMS receive.

Do you have to call it repeatedly, or only once?

You say 'initialise' in your comment, but from the symptom, I'm guessing you have to call it every time before testing SMS.available
weird.

lastchancename:
I don't particularly like the way you framed the question, but nonetheless, I'd be checking the requirement of the library function for SMS receive.

Do you have to call it repeatedly, or only once?

You say 'initialise' in your comment, but from the symptom, I'm guessing you have to call it every time before testing SMS.available
weird.

'SMSreceive()' is a user-defined function, used to initialise the port, not a library function. It's shown in the posted code:-

void SMSrecieve()
{
    // initialize serial communications and wait for port to open:
    Serial.begin(9600);
    while (!Serial)
    {
        ; // wait for serial port to connect. Needed for native USB port only
    }
    Serial.println("SMS Messages Receiver");

    // connection state
    boolean notConnected = true;

    // Start GSM connection
    while (notConnected)
    {
        if (gsmAccess.begin(PINNUMBER) == GSM_READY)
        {
            notConnected = false;
        }
        else
        {
            Serial.println("Not connected");
            delay(1000);
        }
    }
    Serial.println("GSM initialized");
    Serial.println("Waiting for messages");
}