Best Way to run months

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:

When your Arduino Pro Mini is idle, you can push it in sleep mode. In sleep mode, it consumes low energy thus saves battery. Get it into active mode & send the value after every hour and then again go back to sleep mode.

Get rid of the mechanical relay and use a transistor to switch the power.

Solar power to recharge the batteries.

Use wifi/bluetooth/RF module to transmit the data instead of a GSM module - if you have to have the data via GSM, can you mount a 2nd arduino outside the water tank, and use it to relay the data?

Do you need the water level hourly, or could you accumulate several hours of data and send it all at once?

Not related to the power consumption, but if you intend for this to run for an extended amount of time it would be a good idea to not use any String variables, those can lead to memory corruption problems on an arduino.

Thomas_Wall:
The code and hardware work's good, but I'm having trouble with the battery life, just work 20 days.

If you are inside a building why not use mains power? Or, for greater reliability use a lead-acid battery that is trickel-charged from the mains.

...R

Thomas_Wall:
Can some one give me some tips to save battery in the project?

As a start dump the Pro Mini, most all of them are unsuited to low power operation, even when you put them to deep sleep, the can use a lot of current, 4 or 5mA maybe.

A bare bones ATMega328, with a low Iq regulator, will consume around 2uA in deep sleep.

I have a PCB for a 2uA deep sleep Pro Mini if you are into DIY SMT.

Have you used your multimeter to measure how much current is actually being drawn by each device? You would particularly need to know what's flowing into the Pro Mini's RAW pin while it's sleeping. I suspect it's pretty high.

It's a simple procedure to remove the power-on LED and the voltage regulator from the Pro Mini. Just put the tip of your soldering iron on them and flick them away. Then you could run the Mini directly from the batteries (to the Vcc pin) without using a regulator at all. It would run fine up to 5.6V. The question though is whether the relay and the sensor will operate at 4.2V. If you do need a regulator, something with a low dropout voltage and low quiescent current would do better than the Mini's built-in regulator, which is neither of those.

I would guess that it's the GSM module that shuts down first as the batteries discharge. That's because as I remember its operating voltage is 3.7V minimum. So you are leaving some significant amount of battery charge "on the table" if you have to stop and recharge at 3.7V. It might improve things to put three batteries on the GSM and one on the Mini, or even put all four together in parallel if the relay and sensor work at 4.2V.

Others have commented on lower-current options for the relay and the GSM module. Whatever you choose for those, it seems your code has lots of delays in it. For example, you turn on the relay for 30 seconds before you do anything else. And all these delays are during the high-current parts of the timeline when everything is on. You might experiment to see if everything could be done much more quickly. Suppose you turn on the sensor first and get your reading, then turn the sensor off and turn on the relay to send the SMS. Just whatever you can do to minimize the high-current times for each device. If those times are reduced to just a few seconds, then it may not matter so much whether a mosfet would be better than a relay. That said, I suspect the biggest influence on battey life is what the Mini draws when it's sleeping.

One thing that makes a difference is to make sure that all of the I/O ports are initialized to one rail or the other. By default, all but D0 and D1 come up in INPUT mode, and floating inputs can use lots of current. Try this at the beginning of setup, then reinitialize the ones you will be using to their desired state:

for (i = 2; i < 20; i++) { // all pins to one rail or the other - power saving
pinMode(i,OUTPUT);
}

It may not be worth it, but it might work to have a real time clock module powered by a separate button battery to wake up the 328P on a pin change once an hour. That would let you use the power-down sleep mode, which turns off all oscillators. I have an 8MHz Mini with the regulator and LED removed, and during power-down sleep waiting for a pin change to wake it up, it draws 0.4µA. That's with all the I/O pins at a rail, as described above, and with WDT, ADC and BOD disabled during sleep. An 18650 will last a long time at 0.4µA.

One more comment about measuring current. If you have a scope, even one of the $20 kit scopes from Banggood, you can insert a 1-ohm resistor into the ground line of whatever you're measuring, and set up the scope probes to show the voltage across that resistor. Because of the math, a 1mV drop is 1mA of current flowing through it. That setup lets you see the spikes that don't show up on a multimeter.

I hope you will report back here as you try different things. Others will want to know what works and what doesn't.

The Pro Mini clones are perfect for ultra low power battery operation, after you remove the voltage regulator and the power LED.

Just swipe the parts off the board using the tip of a hot solder pencil. Best to start with a 3.3V Pro Mini, as that is already set up for 3.3V operation with an 8 MHz crystal.

This will give you the equivalent of a "bare bones" Arduino, as described here.

You can get more out of your batteries if you keep the voltage under what your Arduino needs and use a DC-DC Boost Converter to raise battery V to Arduino voltage.
There are boost converters that will take 0.9V to 5V and give you 5V as long as there's enough current to stay 0.9+V. If you have 4 batteries in series it will drain them down to 0.9V total, less than 250mV each. You get more out that way than 4 batteries draining down to 5V total through a Buck Converter.

You can run Arduino on less power by running a slower clock. The faster it runs the more power it uses regardless of voltage. At 8MHz an AVR can run on 3V.