Low Power mode combined waking up


I am using an Arduino Pro Mini for a state of charge battery application but I don't want the device to fully discharge it when not being used for long.

For that, my intention would be to use the "LowPower" library so I can run my code and send it to sleep for 8 seconds in a periodic way. However, I would also like to be able to wake it up by myself using a push-button that also triggers some LED's.

As a basic idea I was thinking in a code like this,

#include "LowPower.h"

// Use pin 2 as wake up pin
const int Button = 12;
int wakeUpPin = digitalPinToInterrupt(Button);

// Used to determine if board woke up from an interrupt
bool interrupt = false;

void wakeUp() 
    // Just a handler for the pin interrupt
    interrupt = true;

void setup()
    pinMode(Button, INPUT);

void loop() 
    attachInterrupt(wakeUpPin, wakeUp, LOW);


    if (interrupt) {
      // Woke up from an interrupt
      interrupt = false;
      digitalWrite(LED1, HIGH);
      digitalWrite(LED2, HIGH);
      digitalWrite(LED3, HIGH);
      digitalWrite(LED4, HIGH);
      digitalWrite(LED5, HIGH);
    } else {
        // Woke up by itself

Could somebody verify this? I would really appreciate some feedback from the experts :smiley:

Thank you!!

It looks plausible. But you are going to have to “verify” this yourself by…

build and test the wiring and code. A good ammeter is essential to see what the current drawn in sleep you are actually accomplishing.

As you may find, there are things that can sabotage the low power-ness of a design.

You are using a library, nevertheless I think this is required reading for all on this subject:

What do you find when you try the code you posted?


Variables shared with interrupt routines must be declared volatile

volatile bool interrupt = false;

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.