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!
1 Answer 1
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.
-
Oh that was it, yeah! Draw dropped straight down to 5mA. Thanks! I knew it had to be something stupid I'd forgotten.Santanor– Santanor2022年03月21日 14:33:47 +00:00Commented Mar 21, 2022 at 14:33