Optimizing power consumption (Arduino micro, Adafruit VS1053, sensor, amp)

You're welcome!

thank you

You're welcome. It's good that you had a photo of your actual connection.

I done for today, maybe @EmilyJane can take over

Thanks a lot Jim, I will be trying to find some Sleep mode codes.

I found this article Gammon Forum : Electronics : Microprocessors : Power saving techniques for microprocessors hope it helps me to understand it.

I would measure the current consumed by each board now and determine if disabling one or more when not in use will help. As mentioned, the 9 volt battery doesn't have much capacity to start with so that will continue to be a limiting factor.

Understand, Iam thinking of using 2x 3,7V Li pol batteries, 2900mAh each. Because im limited in space, I hope these batteries will still fit.

I will measure each component tomorrow. Thanks for your help.

So I measured my components:

AMP - 9mA

IR Sensor 58mA

Adafruit VS1053 10mA

Arduino - 84mA

When playing track max 150mA

The Arduino current seems high. Was there anything connected to the Arduino when you made that measurement?

Here is example code that will put your micro to sleep and wake itself up.

/*
  This program uses the Watchdog timer (WDT) to wake the Arduino from sleep.
*/
#include <avr/sleep.h>
#include <avr/wdt.h>

/* WDT timeouts bits WDP[3:0] are bit 5 and bits 2:0 of the WDTCSR
  0x05 = 0.5 seconds
  0x06 = 1
  0x07 = 2
  0x20 = 4
  0x21 = 8 seconds
*/

// I'm using 4 seconds for testing
const byte TIME_OUT = 0x20;

void setup(void)
{
  Serial.begin(115200);

  pinMode(LED_BUILTIN, OUTPUT);     // Set as output
  digitalWrite(LED_BUILTIN, HIGH);  // LED ON

  // Set sleep mode to full power down.
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  // Setup the WDT
  WDTSetup(TIME_OUT);

  Serial.println(F("Setup complete"));
}

void loop(void)
{
  // Your code goes here
  // --->
  /* This is just dummy code for testing
    You can delete everyrhing between the arrows
    and insert your code */

  Serial.println(F("=Awake"));
  Serial.println(F("Working"));
  for (int i = 0; i < 40; i++)
  {
    digitalWrite(LED_BUILTIN, HIGH);  // LED On
    delay(50);
    digitalWrite(LED_BUILTIN, LOW); // LED Off
    delay(50);
  }
  Serial.println(F("Done Working"));

  // end of your code
  //<---

  Serial.println("=Sleeping");
  delay(10); // This makes sure that serial.println has
  // finished before going to sleep
  GoToSleep(); // Call this at the end of loop()
}

//=======================================================
void GoToSleep(void)
{
  WDTCSR |= _BV(WDIF); // Clear the flag
  WDTCSR |= _BV(WDIE); //Enable WDT
  wdt_reset(); // Reset WDT
  // Enable sleep: Puts cpu to sleep and disbles sleep when awoken
  sleep_mode();
  // We are now asleep
  // ZZZZZZZZZZZZZZZZZZZZZZZZZZZ
  // TIMEOUT seconds later we are awake
  WDTCSR &= ~_BV(WDIE); // Disable WDT
}
//=======================================================

//=======================================================
void WDTSetup(byte TIME_OUT)
{
  // Setup the watchdog timer to set an interrupt which wakes the Arduino
  // from sleep every TIME_OUT seconds
  // WDTCSR register Bits: WDIF WDIE WDP3 WDCE WDE WDP2 WDP1 WDP0;
  MCUSR = 0x00; // Clear the MCU Status Reg (including the WDRF)
  cli();  // This next section of code is timing critical, so interrupts are disabled
  // Start the timed Sequence for configuring the WDT
  WDTCSR   =  (1 << WDCE ) | (1 << WDE  );  // Enable configuration change.
  WDTCSR   =  (0 << WDIE) |  (1 << WDIF) |  // Disble Interrupts and clear the flag
              (0 << WDE  ) |  // Disable Watchdog System Reset Mode
              TIME_OUT;    // Set Watchdog Timeout

  wdt_reset(); // Reset WDT
  sei();  // Enable interrupts

}
//=======================================================


// Watchdog timer ISR. Hardware clears the WDIF
ISR(WDT_vect)
{
  //digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));  // Toggle the LED
}

Thanks Jim,

this code is working, do you have an example with IR sensor interupt?
Maybe I can combine the code I have.

To your previous question, that 84mA was for Arduino connected with all components.

Before we go further we need to discuss batteries and how long you want the batteries to last.
If you want to use an interrupt from the IR sensor to wake the Arduino, then the IR sensor needs to be on all the time. 58mA is a lot of current.

Ok, I see. I was measuring the object where I need to put all the components and I think 2x Li-lon 18650 batteries are still acceptable. Of course best choice will be battery size like 9V.

Then just leave everything on all the time

Ok, I think that with my electronics and coding skills is the best way to use the battery with the biggest capacity. And also because I need to finish this object in a week.

Thanks for your help, I learned new things during this process.

Wish you the best

In case you are interested, if you use two 2900mAh batteries, I estimate they will last about 30 hours provided an object is never detected. Of course it will be less hours depending how many times an object is detected.

I think Iam ok with this. One last question, on one forum, guy recommend me to use step down between batteries and arduino and set it from 7,4V to 5V which can prolong the battery use.

What do you think about it?

If you decide to power the micro via the 5V output pin the power source must be well regulated with no voltage spikes and have low ripple. Also, you must never connect anything to the Vin pin or the USB port while you have a power source connected to the 5V pin either on purpose or accidentally

I estimate maybe another 2 hours.
Of course if you shut everything off and only woke up every 2 seconds it could last maybe 145 hours.

A new fuse will fix that :slight_smile:

1 Like

Can I achieve it by modifiyng the code you sent me?
I still have few days to finish it so I can at least try.

In the practice - all the components will be hidden in the top of a hat, the visitor of my exhibition can put the hat on his head, when he/she put it on, random track start playing till the end and then nothing, he/she must put the hat down and put it on again if wants to hear another track.

Tracks are mostly from 15-30seconds and 7 in total.