Libelium is offering new technical support channels, to contact with de Technical Support team to solve any issue our doubt please contact with your sales agent or visit our contact site

Post a new topicPost a reply Page 1 of 1   [ 2 posts ]
Author Message
 Post subject: GPS/GPRS Shield- Sending SMS only works once
PostPosted: Mon Sep 18, 2017 8:58 am 

Joined: Mon Sep 18, 2017 8:48 am
Posts: 1
I have the following problem:
I use the 3G/GPRS shield on an Arduino Uno and the
example with sending an SMS works just fine.
However, when I want to send multiple SMS, only the
first one gets sent, every further sending command
will return an error. Has anybody any idea as to why this
could happen?
Below is the code, but it is only a sligthly modified
version of the example.
Any help would be appreciated.

int8_t answer;
int onModulePin= 2;
char aux_str[30];

//Change here your data
const char pin[]="****";
const char phone_number[]="MYNUMBER";
const char sms_text[]="Anytext"; 

void setup(){

  pinMode(onModulePin, OUTPUT);



void loop(){


void sendsms(){

  //sets the PIN code
  sprintf(aux_str, "AT+CPIN=%s", pin);
  sendATcommand(aux_str, "OK", 2000);


  Serial.println("Connecting to the network...");

  while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) ||
    sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );

  Serial.print("Setting SMS mode...");
  sendATcommand("AT+CMGF=1", "OK", 1000);    // sets the SMS mode to text
  Serial.println("Sending SMS");

  sprintf(aux_str,"AT+CMGS=\"%s\"", phone_number);
  answer = sendATcommand(aux_str, ">", 2000);    // send the SMS number
  if (answer == 1)
    answer = sendATcommand("", "OK", 20000);
    if (answer == 1)
      Serial.print("Sent ");   
      Serial.print("error ");
    Serial.print("error ");
    Serial.println(answer, DEC);


void power_on(){

  uint8_t answer=0;

  // checks if the module is started
  answer = sendATcommand("AT", "OK", 2000);
  if (answer == 0)
    // power on pulse

    // waits for an answer from the module
    while(answer == 0){     // Send AT every two seconds and wait for the answer
      answer = sendATcommand("AT", "OK", 2000);   


int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){

  uint8_t x=0,  answer=0;
  char response[100];
  unsigned long previous;

  memset(response, '\0', 100);    // Initialice the string


  while( Serial.available() > 0);    // Clean the input buffer

  Serial.println(ATcommand);    // Send the AT command

    x = 0;
  previous = millis();

  // this loop waits for the answer
    // if there are data in the UART input buffer, reads it and checks for the answer
    if(Serial.available() != 0){   
      response[x] =;
      // check if the desired answer is in the response of the module
      if (strstr(response, expected_answer) != NULL)   
        answer = 1;
    // Waits for the answer with time out
  while((answer == 0) && ((millis() - previous) < timeout));   

  return answer;

 Post subject: Re: GPS/GPRS Shield- Sending SMS only works once
PostPosted: Tue Sep 19, 2017 7:13 am 

Joined: Mon Sep 28, 2009 12:06 pm
Posts: 11366
Hi NNo,

If you use the version of the example, have you got the same problem?

Can you show us the Serial monitor output when you run this example?



Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 2 posts ]

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of

© Libelium Comunicaciones Distribuidas S.L. | Terms of use.