Go Down

Topic: Arduino drains the battery even with lowPower library (Read 163 times) previous topic - next topic

arad2456

Hey all :) I am trying to power my project from a power bank and used therefore the lowPower library. Everytime I go to sleep however I wake up to see the power bank empty. I don't really know what's the reason so I'll be happy to hear you guys's opinion. I have 1200mAh battery and I am using Arduino Nano. The buttons don't react after the Arduino goes to sleep so I suppose it is kind of sleeping. But if it is so why does my battery gets drained ?


I added the schematics (the schematics shows Uno but I am using Nano. I also forgot to show that busy from the DFPlayer is connected to pin 13), the sketch is down here. I removed the parts which don't involve the wakeUpPin (pin 2) because the sketch is long, like functions to light the leds, to switch the directory from short to long and to change the volume.
Code: [Select]


#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include "LowPower.h"


DFRobotDFPlayerMini myDFPlayer;


const int wakeUpPin = 2;



int buttonStart = 3 ;

int buttonStop = 4 ;


SoftwareSerial mySoftwareSerial(10, 11); // RX, TX 11 Resistor

int busy = 13 ;

boolean sleeping = true ;
boolean countingDown = false ;
boolean fileEnded = false ;

int numberFilesLongFolder  ;
int numberFilesShortFolder  ;


static unsigned long timer ;
static unsigned long busyCount;
int busyCountInterval = 10000 ;
int sleepingCountInterval = 180000 ;
int busyState ;

//start
void playRandom (int folder, int randomNumber) {
  myDFPlayer.playFolder(folder, randomNumber);  //Play file
  green() ;
}


void myDelay(int del) {
  unsigned long myPrevMillis = millis();
  while (millis() - myPrevMillis <= del);
}



void wakeUp()
{
  // Just a handler for the pin interrupt.
}

void setup()
{



  mySoftwareSerial.begin(9600);
  myDFPlayer.begin (mySoftwareSerial) ;


  pinMode(wakeUpPin, INPUT);
  digitalWrite (wakeUpPin, HIGH) ;

  pinMode (busy, INPUT) ;


  busyCount = 0 ;


  secondTimer = 0 ;


}


void loop()
{
  attachInterrupt(0, wakeUp, LOW);

  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);


  detachInterrupt(0);

 
 // wake up & start
  if (!digitalRead (wakeUpPin) && sleeping) {
    myDelay (50) ;
    if (!digitalRead (wakeUpPin) && sleeping) {
      digitalWrite (wakeUpPin, LOW) ;
      sleeping = false ;
      numberFilesLongFolder = myDFPlayer.readFileCountsInFolder(1) ;
    numberFilesShortFolder = myDFPlayer.readFileCountsInFolder(2) ;
      if (playShort) {
        randomNumber = random (1, numberFilesShortFolder ) ;
        playRandom(2, randomNumber) ;
      }
      else {
        randomNumber = random (1, numberFilesLongFolder ) ;
        playRandom(1, randomNumber);  //Play file
      }
      myDelay (500) ;
      fileEnded = false ;
    }


  }




  if (!digitalRead(buttonStart) ) {
    myDelay (50) ;
    if (!digitalRead(buttonStart) ) {
      if (playShort) {
        randomNumber = random (1, numberFilesLongFolder) ;
        playRandom(2, randomNumber) ;
      }


      else {
        randomNumber = random (1, numberFilesShortFolder) ;
        playRandom(1, randomNumber);  //Play file
      }
      fileEnded = false ;
      myDelay (500) ;
    }
  }


  //Pause & continue
  //Pause
  //readState = 513 --> playing
  if (!digitalRead(buttonStop) && !digitalRead (busy) ) {
    myDelay (50) ;
    if (!digitalRead(buttonStop) && !digitalRead (busy) ) {
      myDFPlayer.pause();
      countingDown = false ;
      yellow () ;
      myDelay (500) ;


    }
  }


  //Continue
  //readState = 514 --> stopped


  if (!digitalRead(buttonStop) && digitalRead (busy) ) {
    myDelay (50) ;
    if (!digitalRead(buttonStop) && digitalRead (busy) ) {
      myDFPlayer.start();
      countingDown = false ;
      green () ;
      myDelay (500) ;
    }
  }



  //making the arduino go to sleep when the file ends / stopped for a while


  if (millis () - busyCount >= busyCountInterval ) {
    busyCount = millis () ;
    busyState = digitalRead (busy) ;
  }


  if (busyState) {
    if (countingDown == false ) {
      timer = millis () ;
      countingDown = true ;
    }
  }


  //without this delay the file don't stop after  a file ended
   delay (10) ;




  //go to sleep
  if (busyState && millis () - timer > sleepingCountInterval ) {
    sleeping = true ;
    timer = millis () ;
    countingDown = false ;
    fileEnded = false ;
    digitalWrite (wakeUpPin, HIGH) ;
  }
}



If you guys have any idea I will appreciate your help very much. Thank you all in advance :)

** I am trying to make a new Fritzing picture of the sketch but the program makes couple of problems for me, it will come soon, sorry


srnet

Check the Arduino Nano scheamtic.  There are components that wont go to sleep, the serial to USB adapte,  and there are components that draw a fair bit of current too when idle such as the regulator.

Then you appear to have added componets that also will likley not go to sleep, the player.

If you want to know why the battery goes flat, measure the actual current the entire setup uses when the processor is 'asleep'.
No PMs please, they dont get answered.

arad2456

If you want to know why the battery goes flat, measure the actual current the entire setup uses when the processor is 'asleep'.
Why I haven't thought about it myself  :smiley-roll-blue:  So the DFPlayer takes 3mA, I can't measure the Nano because my battery is a power bank with a USB entry but the things you mentioned probably take a big chunk from the Battery. I bough a pro mini and will connect the DFPlayer via a transistor and all should be good then. Thanks :)

srnet

Do some sums.

A 1200mAhr power bank uses an up converter, so assuming an average battery volt in the 3.9V range and a converter efficiency of 85%, at the 5V output you have the equivalent of;

3.9/5 * 0.85 * 1200mah = 800mAhr (approx)

I dont know how long you sleep, but if its 12hours the 3mA of the DFplayer will only use 36mAhr from an available 800mAhr. 

There are devices for measuring current through the USB port, but its easy enough to cut apart a £1 USB extender lead to break the power wire and put a multimeter in circuit.
No PMs please, they dont get answered.

arad2456

I don't need to know the exact numbers, I know that the battery gets drained and that's enough for the moment. I wasn't sure about myself and thought that the code might be somehow wrong but after what you said I am pretty sure that it's simply because the Arduino doesn't go to sleep. I will try it with the pro mini that arrives tomorrow and if it would still not work then I'll start searching every little point in the circuit to see what eats my battery.

ShermanP

Are you sure the battery is drained, and not just shut down?  Most powerbanks need a minimum current draw to stay on.  If you're going to sleep, you may fall below that.

arad2456

I suppose I have that minimum current because as I realized now the DFPlayer doesn't really go to sleep. You mean that the powerbank go to sleep ? but when I try to wake up the arduino nothing happens. I didn't try to disconnect and then connect again the power bank (if that's what needs to be done), I just assumed it's empty. I will try that again tonight.

ShermanP

Yes, the powerbank will go to sleep when the current draw falls below a certain level.  Remember that powerbanks are designed to charge another battery, such as your phone, not to power electronics projects.  So when the "charging" current drops to a low level, the powerbank assumes the phone's battery is now charged, and shuts down so as to extend its own battery life.  The shutoff current level varies from one manufacturer to another.


Grumpy_Mike

Pin 2 is not connected to anything.

The switches will not work correctly because the software should be enabling the internal pull up resistors.

arad2456

ShermanP ok, thank you for the info, it makes sense, good to know :)

Grumpy_Mike I am sorry, I am afraid my knowledge is not high enough for me to truly understand what you mean. The pin was connected and worked, it played the files after I pressed on the button which is connected to it. But I suppose you meant something else...  can you explain it to me again please ?

Grumpy_Mike

#10
Oct 20, 2020, 10:13 am Last Edit: Oct 20, 2020, 10:16 am by Grumpy_Mike
In your Fritzing physical layout diagram pin 2 of the Arduino goes to a track on the Solderless bread board, that nothing else is connected to. So pin 2 is not connected to anything. If you say it works then you have made a mistake in making that drawing, we can only go off what you tell and show us, and we have to assume what that is is true. It might just be that you lied in that drawing.

How you should use inputs is explained here http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

arad2456

#11
Oct 20, 2020, 06:23 pm Last Edit: Oct 20, 2020, 06:24 pm by arad2456
Ohhh, now I understand what you meant. I made a mistake in the Fritzing picture (with all the buttons apperently), I connected them to one track to the left. they are all connected correctly in real life

Go Up