Go Down

Topic: Connecting problems with Arduino GSM Shield (Read 14290 times) previous topic - next topic


Apr 13, 2014, 04:35 pm Last Edit: Apr 15, 2014, 07:40 pm by martinhagreen Reason: 1
Hi all, I´m working on a standalone project with an Arduino Mega 2560 attached to a GSM Shield.
I´m powering it with an swtiching power supply, getting output 12V and 1 amp (I read that It was enough with 1 amp)
I have attached 8 Hall sensors, 1 Led and 1 reed switch.
I´m using it to post the sensors data into a database to show them in a web visualization.

My problem is that sometimes, 3 days later or 2 (this time is variable) since I connect the device, it stops sending data; and the only solution is unplug and plug the power supply again to reset it.
This device is going to be installed on a roof on a corporate building and I can´t go up there to re-plug it, maybe it´s possible to turn off the device once a day (p. example) by code or by hardware (with a Relay?) to avoid this?  Maybe is getting this 2 Amp peak value and because of it its stopping?

Power requirements

It is recommended that the board be powered with an external power supply that can provide between 700mA and 1000mA. Powering an Arduino and the GSM shield from a USB connection is not recommended, as USB cannot provide the required current for when the modem is in heavy use.

The modem can pull up to 2A of current at peak usage, which can occur during data transmission. This current is provided through the large orange capacitor on the board's surface..

The code is the following, the server areas are empty because it´s our client private server:

Code: [Select]

#include <GSM.h>

#define PINNUMBER ""
// APN data
#define GPRS_APN       "bluevia.movistar.es" // replace your GPRS APN
#define GPRS_LOGIN     " "    // replace with your GPRS login
#define GPRS_PASSWORD  " " // replace with your GPRS password

GSMClient client;
GPRS gprs;
GSM gsmAccess;

// URL, path & port
char server[] = "";
char path[] = " ";
int port = 80; // 80 for HTTP

int totalCount = 0;

//Weather variables
long pulseWidth;
float wSpeed;
char params[32];
int velocidad;
int direccion;

int statePin1, statePin2, statePin3, statePin4, statePin5, statePin6, statePin7, statePin8;
//int prevStatePin = 0;

#define delayMillis 60000
//#define delayMillis 60000

unsigned long thisMillis = 0;
unsigned long lastMillis = 0;

int hallPin1 = 12;
int hallPin2 = 11;
int hallPin3 = 9;
int hallPin4 = 8;
int hallPin5 = A0;
int hallPin6 = 6;
int hallPin7 = 5;
int hallPin8 = 4;
int anemoPin = 13;

int ledPin = A5;

void setup()

 // connection state
 boolean notConnected = true;
 // Start GSM shield
   if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
        notConnected = false;
     Serial.println("Not connected");


void loop()
 thisMillis = millis();

 if(thisMillis - lastMillis > delayMillis)
   lastMillis = thisMillis;
   // params must be url encoded.
   sprintf(params,"velocidad=%i&direccion=%i", velocidad,direccion);
   if(!postPage(server,port,path,params)) Serial.print(F("Fail "));
   else Serial.print(F("Pass "));

byte postPage(char* domainBuffer,int thisPort,char* page,char* thisData)
 int inChar;
 char outBuf[64];


   analogWrite(ledPin, 255);
   // send the header
   sprintf(outBuf,"POST %s HTTP/1.1",page);
   sprintf(outBuf,"Host: %s",domainBuffer);
   client.println(F("Connection: close\r\nContent-Type: application/x-www-form-urlencoded"));
   sprintf(outBuf,"Content-Length: %u\r\n",strlen(thisData));

   // send the body (variables)
   analogWrite(ledPin, 0);
   return 0;

 int connectLoop = 0;

     inChar = client.read();
     connectLoop = 0;


 analogWrite(ledPin, 0);
 return 1;

void digitalReads(){



void readHalls(){
     direccion = 1;

     direccion = 2;
     direccion = 3;
     direccion = 4;
     direccion = 5;
     direccion = 6;
     direccion = 7;
     direccion = 8;
   if (statePin1 == LOW &&
     statePin2 == LOW &&
     statePin3 == LOW &&
     statePin4 == LOW &&
     statePin5 == LOW &&
     statePin6 == LOW &&
     statePin7 == LOW &&
     statePin8 == LOW){
        direccion = direccion;



void setupExternals(){

 pinMode(anemoPin, INPUT);


void readAnemometer(){
   pulseWidth=pulseIn(anemoPin, LOW);
   //Formula for period (in microsec) to mph
   //convert from mp/h to km/h
   float kmH = wSpeed * 1.609;  
   kmH = constrain(kmH, 1, 200);
   if(kmH == 200){
     kmH = 1.0;
   velocidad = kmH * 100;


Thank you in advance¡


Have you had luck with getting serial debug stream from failure ?


No, when I had it plugged to the computer and stopped sending data, I get from serial console only this:

Fail xxx


Apr 14, 2014, 10:36 am Last Edit: Apr 14, 2014, 10:42 am by markusdnd Reason: 1
It seems like a problem I have worked on for past few weeks.

enable the debug mode from the library and try to get debug output when it fails.
GSM gsmAccess(true);

I am of course guessing that you are using the default gsm library for the module.

Edit> of course you are using the standard library. never hurts to ask thou.


Ofc, Im using the official library, my sketch is based on the GSMwebClient Example

Per example, i went out the weekend, and I noticed than the devide was properly sending data since Wednesday. It might be working for 2 days and disconnect, or 1 month, I couldnt know in advance.

I think the best way to avoid problems is programming a reset of the whole system every XX days, to play it safe.
Maybe I will ned another Arduino board with a relay to interrupt the power supply?  I never used a relay and I don´t know how to start.

How I can enable the debug mode from the library?

Thank you¡


Replace GSM gsmAccess; with GSM gsmAccess(true);

then you will see the data that will be sent to and recieved from gsm module.

What I saw was that at one point (when the hang happens) there is AT command sent but nothing is recieved from module. I guess that the library stays waiting for the reply but nothing happens. for whatever reason

I do not have proper solution yet, but I would love to find out if the symptoms of the problem are the same.

Also I have had 32h of working flawlessly. then it just hangs. no extra info from terminal no nothing.

It seems to me that the library is unable to handle the missing answer from the module. Thou i am not 100 % sure of that.
Also using signal analyzer does not help since I have not figured out the way to log for days in a row.


Apr 14, 2014, 11:37 am Last Edit: Apr 15, 2014, 07:38 pm by martinhagreen Reason: 1
Ok,  I had my device working more than 32h, but I should try what you are advicing; when it Hangs, i Will post the result

For now, is working, it´s normal to get this extrange/weird encoding?

Starting  Client.
0 9>AT%13%%13%%10%OK%13%%10%
9 40>AT+CGREG?%13%%13%%10%+CGREG: 0,1%13%%10%%13%%10%OK%13%%10%
40 57>AT+IFC=1,1%13%%13%%10%OK%13%%10%
57 75>%19%%17%AT+CMGF=1%13%%13%%10%OK%13%%10%
75 91>AT+CLIP=1%13%%13%%10%OK%13%%10%
91 102>ATE0%13%%13%%10%OK%13%%10%
102 108>%13%%10%OK%13%%10%
108 114>%13%%10%OK%13%%10%
114 120>%13%%10%OK%13%%10%
120 126>%13%%10%OK%13%%10%
126 4>%13%%10%OK%13%%10%
4 10>%13%%10%OK%13%%10%
10 16>%13%%10%OK%13%%10%
16 22>%13%%10%OK%13%%10%
22 28>%13%%10%OK%13%%10%
28 34>%13%%10%OK%13%%10%
34 40>%13%%10%OK%13%%10%

34 51>%13%%10%OK%13%%10%%13%%10%CONNECT%13%%10%
POST /xxxx/xxx.php HTTP/1.1%13%%10%Host: xxx.com.es%13%%10%Connection: close%13%%10%Content-Type: application/x-www-form-urlencoded%13%%10%Content-Length: 25%13%%10%%13%%10%velocidad=200&direccion=3
51 47>HTTP/1.1 200 OK%13%%10%Date: Mon, 14 Apr 2014 09:44:45 GMT%13%%10%Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13 OpenSSL/0.9.8g PHP/5.2.11
HTTP/1.1 200 OK
Date: Mon, 14 Apr 2014 09:44:45 GMT
Server: Apache/2.2.13 (Unix) mod_ssl/2.2.13
20 1> OpenSSL/0.9.8g PHP/5.2.11 with Suhosin-Patch%13%%10%Content-Type: text/html%13%%10%Connection: close%13%%10%%13%%10%OKPOST%13%%10%CLOSED%13%%10%
OpenSSL/0.9.8g PHP/5.2.11 with Suhosin-Patch
Content-Type: text/html
Connection: close




Yes this is absolutely normal.

another person with the same problem: http://forum.arduino.cc/index.php?topic=233137.new;topicseen#new

It seems to be rather large problem.

PS the % are added by the library so you can find where are the line endings etc.



Seems that the problem has some kind of solution. I will be testing it soon.


Woah¡ Thank you for the reply, do you think it will work?
I changed the power supply to a 12V & 2amp one, and enabled the output from the library to see the message when it hangs but it is working properly... (I should not complaining about this, but I want to see the error log!)


First: sorry for my bad english  8)

Pay attention of this expression:
Code: [Select]
if(thisMillis - lastMillis > delayMillis)

The Millis() function returns to 0 after 50 days due to the Unsigned LONG type that reaches the maximum value. (Read HERE)

so after this reset, this expression in no longer valid, because "lastMillis" will be bigger then "thisMillis" until the 50th day...


First: sorry for my bad english  8)

Pay attention of this expression:
Code: [Select]
if(thisMillis - lastMillis > delayMillis)

The Millis() function returns to 0 after 50 days due to the Unsigned LONG type that reaches the maximum value. (Read HERE)

so after this reset, this expression in no longer valid, because "lastMillis" will be bigger then "thisMillis" until the 50th day...

Because thisMillis & lastMillis are defined as unsigned, the math will keep working after the rollover of 50 days.


Here is a great solution from Pipeline PCB's(pipelinepcb.net). A customized version of the Super Link Shield, which we got for our final year project. It has GSM+bluetooth+wifi units, independent controlled by on board AVR's, and simple arduino commands through software serials are there to communicate, thanks to the customized libraries.

Reference : http://www.pipelinepcb.net/projects.html


hello all......am working on gsm shiled to sent sms. could some one fix the issue asap......

when I load the example "testemodem" shows me this:

Starting modem test...ERROR, no modem answer.
Checking IMEI...Modem's IMEI: 0
Resetting modem...Modem is functoning properly

when I load the example "gsmscannetworks"  or other shows me this:
"GSM networks scanner"
and do not go to the next step

when I load the example "pinmanagement" shows me this:
Change PIN example

PIN & PUK locked. Use PIN2/PUK2 in a mobile phone.

Go Up