0

I saw a library called LowPower_LowPowerLab that can set the Arduino in sleep mode. In their example they put the Arduino to sleep using an external button, is there anyway to invert this behavior? I want the Arduino to save battery power by being in sleep mode and then when I need it, hold a button down to keep the Arduino awake and then release the button to put it back to sleep. In their example below I have tried changing the attachInterrupt to HIGH/RISING/FALLING with no change. Also coul

LowPowerLab's Example:

#include "LowPower.h"

// Use pin 2 as wake up pin
const int wakeUpPin = 2;

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

void setup()
{
    // Configure wake up pin as input.
    // This will consumes few uA of current.
    pinMode(wakeUpPin, INPUT);   
}

void loop() 
{
    // Allow wake up pin to trigger interrupt on low.
    attachInterrupt(0, wakeUp, LOW);
    
    // Enter power down state with ADC and BOD module disabled.
    // Wake up when wake up pin is low.
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); 
    
    // Disable external pin interrupt on wake up pin.
    detachInterrupt(0); 
    
    // Do something here
    // Example: Read sensor, data logging, data transmission.
}
1
  • 2
    Looks like you're missing something after "Also coul".
    – VE7JRO
    Nov 19, 2023 at 17:49

1 Answer 1

2

In their example they put the Arduino to sleep using an external button, is there anyway to invert this behavior?

Of course. Put the Arduino to sleep in setup and make the button wake it up.

Some tips here.

Also, I wouldn't use LOW, I would use FALLING. LOW keeps interrupting the processor, so while you hold the button down it keeps entering the interrupt, which would make it unresponsive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.