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:
#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
//1minuto
//#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()
{
setupExternals();
Serial.begin(9600);
// connection state
boolean notConnected = true;
// Start GSM shield
while(notConnected)
{
if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("connecting...");
}
void loop()
{
thisMillis = millis();
if(thisMillis - lastMillis > delayMillis)
{
lastMillis = thisMillis;
digitalReads();
readAnemometer();
readHalls();
// params must be url encoded.
sprintf(params,"velocidad=%i&direccion=%i", velocidad,direccion);
Serial.println(params);
if(!postPage(server,port,path,params)) Serial.print(F("Fail "));
else Serial.print(F("Pass "));
totalCount++;
Serial.println(totalCount,DEC);
}
}
byte postPage(char* domainBuffer,int thisPort,char* page,char* thisData)
{
int inChar;
char outBuf[64];
Serial.print(F("connecting..."));
if(client.connect(domainBuffer,thisPort))
{
Serial.println(F("connected"));
analogWrite(ledPin, 255);
// send the header
sprintf(outBuf,"POST %s HTTP/1.1",page);
client.println(outBuf);
sprintf(outBuf,"Host: %s",domainBuffer);
client.println(outBuf);
client.println(F("Connection: close\r\nContent-Type: application/x-www-form-urlencoded"));
sprintf(outBuf,"Content-Length: %u\r\n",strlen(thisData));
client.println(outBuf);
// send the body (variables)
client.print(thisData);
}
else
{
Serial.println(F("failed"));
analogWrite(ledPin, 0);
return 0;
}
int connectLoop = 0;
while(client.connected())
{
while(client.available())
{
inChar = client.read();
Serial.write(inChar);
connectLoop = 0;
}
delay(1);
connectLoop++;
}
Serial.println();
Serial.println(F("disconnecting."));
analogWrite(ledPin, 0);
client.stop();
return 1;
}
void digitalReads(){
statePin1=digitalRead(hallPin1);
statePin2=digitalRead(hallPin2);
statePin3=digitalRead(hallPin3);
statePin4=digitalRead(hallPin4);
statePin5=digitalRead(hallPin5);
statePin6=digitalRead(hallPin6);
statePin7=digitalRead(hallPin7);
statePin8=digitalRead(hallPin8);
}
void readHalls(){
if(statePin1==HIGH)
{
direccion = 1;
}
if(statePin2==HIGH)
{
direccion = 2;
}
if(statePin3==HIGH)
{
direccion = 3;
}
if(statePin4==HIGH)
{
direccion = 4;
}
if(statePin5==HIGH)
{
direccion = 5;
}
if(statePin6==HIGH)
{
direccion = 6;
}
if(statePin7==HIGH)
{
direccion = 7;
}
if(statePin8==HIGH)
{
direccion = 8;
}
if (statePin1 == LOW &&
statePin2 == LOW &&
statePin3 == LOW &&
statePin4 == LOW &&
statePin5 == LOW &&
statePin6 == LOW &&
statePin7 == LOW &&
statePin8 == LOW){
direccion = direccion;
}
return;
}
void setupExternals(){
pinMode(hallPin1,INPUT);
pinMode(hallPin2,INPUT);
pinMode(hallPin3,INPUT);
pinMode(hallPin4,INPUT);
pinMode(hallPin5,INPUT);
pinMode(hallPin6,INPUT);
pinMode(hallPin7,INPUT);
pinMode(hallPin8,INPUT);
pinMode(anemoPin, INPUT);
}
void readAnemometer(){
//Anemometro
//=======
pulseWidth=pulseIn(anemoPin, LOW);
//Formula for period (in microsec) to mph
wSpeed=1000000.0/pulseWidth*2.5;
//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;
return;
}
Thank you in advance¡