Hy guys, I'm working in a Sensor + GSM + Pro mini 3.3V project, the idea is to install inside of a water box in the top of the building and receive the distance of the water one time per hour.
The code and hardware work's good, but I'm having trouble with the battery life, just work 20 days.
I'm using originals 4 x 2.200mAh battery like you can see in the sketch.
Can some one give me some tips to save battery in the project?
That is the code:
#include <LowPower.h>
// MODEM
#include <SoftwareSerial.h> //is necesary for the library!!
SoftwareSerial sim(9,8); //to declare the library TX GSM RX GSM
char* text;
char* number;
//ULTRASONIC
#include <Ultrasonic.h> // Ultrasom
Ultrasonic ultrasonic(3,2); //TR EC
// Create string
String infos;
char infos2[100];
void setup() {
pinMode(10, OUTPUT); //rele+
pinMode(4, OUTPUT); //ultrason
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
// COLOCAR A PROGRAMAÇÃO AQUI
digitalWrite(10, LOW); // turn relay on
delay(30000); // Wait
digitalWrite(4, HIGH); // turn ultrason on
delay(5000); // Wait
// Configura string infos
infos="";
infos+="006,";
infos+=(ultrasonic.distanceRead());
Serial.println(infos);
snprintf( infos2, sizeof(infos2)-1, "%s", infos.c_str() );
Serial.begin(115200);
sim.begin(115200);
sim.println("AT");
delay(100);
while(sim.available())
{
Serial.write(sim.read());
}
sim.println("AT+CGATT?");
delay(1500);
while(sim.available())
{
Serial.write(sim.read());
}
sim.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(1500);
while(sim.available())
{
Serial.write(sim.read());
}
sim.println("AT+SAPBR=3,1,\"APN\",\"generica.claro.com.br\"");
delay(1500);
while(sim.available())
{
Serial.write(sim.read());
}
sim.println("AT+SAPBR=1,1");
delay(1500);
while(sim.available())
{
Serial.write(sim.read());
}
sim.println("AT+HTTPINIT");
delay(1500);
while(sim.available())
{
Serial.write(sim.read());
}
sim.print("AT+HTTPPARA=\"URL\",\"api.thingspeak.com/update?api_key=YCCK8SYRJXRW81ZE&field1=");
sim.println(infos2);
delay(1500);
while(sim.available())
{
Serial.write(sim.read());
}
sim.println("AT+HTTPACTION=0");
delay(5000);
while(sim.available())
{
Serial.write(sim.read());
}
sim.println("AT+HTTPTERM");
delay(1000);
while(sim.available())
{
Serial.write(sim.read());
}
digitalWrite(10, HIGH); // turn off relay
digitalWrite(4, LOW); // turn ultrason off
// until here
unsigned int sleepCounter;
for (sleepCounter = 440; sleepCounter > 0; sleepCounter--) //One hour interval
{
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
}
And the sketch: