user84366: I'm working on a battery powered Arduino Nano project. I really need it to save power for hours on end, so I turned to Arduino LowPower Library and avr/sleep.h to do the job.
However, whatever I do, it doesn't look like the board isn't going to sleep. I have a sample sketch that tries to put the board to sleep and then toggles a relay when it wakes up, but it always toggles the relay instantly after booting, so that means it hasn't gone to sleep.
I also measured the current going into the board, and it's drawing 14mA consistently. I would expect to see a much lower draw whilst it's asleep.
Here are the two pieces of code that I've tried, one with LowPower and the other one with avr/sleep.h
void setup(){
    pinMode(relayPin, OUTPUT);
}

void loop(){ 
    // This call doesn't seem to do anything
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    toggleRelay(); //This gets executed continuously, with no indication of sleep time
}

Here's the other one with LowPower
void setup(){
        pinMode(relayPin, OUTPUT);
    }
    
    void loop(){ 
        // This call doesn't seem to do anything
        LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

        //This gets executed continuously, with no indication of sleep time. 
        //I would expect it to see it toggle only every 8s
        toggleRelay(); 
    }

I'm probably doing something stupid, but I can't figure out what... Any help?
Thanks a lot!

user7508: I don't know about the LowPower library. However, four your
avr-libc-based test, you forgot to actually put the device in sleep
mode with sleep_mode():
void loop() {
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // select a deep sleep mode
    sleep_mode();   // now go to sleep
    toggleRelay();  // executed at wake up
}

Beware that, if you haven't enabled a wakeup source that is active in
the mode you selected, the microcontroller may sleep until it is
power-cycled or receives an external reset.

84366: <p>I'm working on a battery powered Arduino Nano project. I really need it to save power for hours on end, so I turned to <a href="https://github.com/arduino-libraries/ArduinoLowPower" rel="nofollow noreferrer">Arduino LowPower Library</a> and <a href="https://www.nongnu.org/avr-libc/user-manual/group__avr__sleep.html" rel="nofollow noreferrer">avr/sleep.h</a> to do the job.</p>
<p>However, whatever I do, it doesn't look like the board isn't going to sleep. I have a sample sketch that tries to put the board to sleep and then toggles a relay when it wakes up, but it always toggles the relay instantly after booting, so that means it hasn't gone to sleep.</p>
<p>I also measured the current going into the board, and it's drawing 14mA consistently. I would expect to see a much lower draw whilst it's asleep.</p>
<p>Here are the two pieces of code that I've tried, one with LowPower and the other one with avr/sleep.h</p>
<pre><code>void setup(){
    pinMode(relayPin, OUTPUT);
}

void loop(){ 
    // This call doesn't seem to do anything
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    toggleRelay(); //This gets executed continuously, with no indication of sleep time
}
</code></pre>
<p>Here's the other one with LowPower</p>
<pre><code>void setup(){
        pinMode(relayPin, OUTPUT);
    }
    
    void loop(){ 
        // This call doesn't seem to do anything
        LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

        //This gets executed continuously, with no indication of sleep time. 
        //I would expect it to see it toggle only every 8s
        toggleRelay(); 
    }
</code></pre>
<p>I'm probably doing something stupid, but I can't figure out what... Any help?
Thanks a lot!</p>
 7508: <p>I don't know about the LowPower library. However, four your
avr-libc-based test, you forgot to actually put the device in sleep
mode with <code>sleep_mode()</code>:</p>
<pre class="lang-cpp prettyprint-override"><code>void loop() {
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // select a deep sleep mode
    sleep_mode();   // now go to sleep
    toggleRelay();  // executed at wake up
}
</code></pre>
<p>Beware that, if you haven't enabled a wakeup source that is active in
the mode you selected, the microcontroller may sleep until it is
power-cycled or receives an external reset.</p>
