Make arduino save power

Hi,

I have a project with a pretty simple code like this:

servo.attach(2);
servo.writeMicroseconds(800);
//The delay below is just so that the servo has enough time to move to the desired position.
delay(1000);
servo.detach();

//Wait ~24h.
delay(24*60*60*1000);

servo.attach(2);
servo.writeMicroseconds(1200);
//The delay below is just so that the servo has enough time to move to the desired position.
delay(1000);
servo.detach();

//Wait ~24h.
delay(24*60*60*1000);

servo.attach(2);
servo.writeMicroseconds(1600);
//The delay below is just so that the servo has enough time to move to the desired position.
delay(1000);
servo.detach();

//Wait ~24h.
delay(24*60*60*1000);

....

You can see 99,999% of the time Arduino is doing nothing (long delays between each servo move). So I am wondering: is there some code I can execute before each long delay so Arduino can save power without using wake interrupts?

I am aware of the "avr/sleep.h" library but when I use the code below, arduino stops completely the execution (of course, it's waiting to be woken up). I tried changing "SLEEP_MODE_PWR_DOWN" to "SLEEP_MODE_IDLE" and this way arduino does not stop execution BUT I cant see any current drop using my multmeter.

sleep_enable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_cpu();

So, what you would recommend me doing? Thanks in advance.

EDIT:

I am using arduino Pro Mini 5v.

Which Arduino board do you use ?

@Koepel I am using Pro Mini, but I can change to Nano if you think would be better.

Perhaps adding a real-time clock to the project.
Paul

I would like to keep the hardware the same. Isnt there any code to save battery?

See this excellent tutorial on power saving: https://www.gammon.com.au/power

To be most effective with the Pro Mini, people remove the power LED, and sometimes the voltage regulator (for battery operation).

@jremington Thanks, I had already read that link, it's great! However it messes with registers and is a lot advanced. I was wondering if there is a known library that provides the "delay with power saving" or something similar... I really think that arduino should already have it built in in the language since any delay does absolutely nothing, just waits... every time a delay is called, Arduino could check if there is any interrupt attached or any code to watchdog attached, otherwise it should disable everything untill the delay has passed since the user explicitly didnt set any interrupt or watchdog that could cause problem disabling.

Sure, there are a couple of popular power saving libraries, and they have been around for years. But none that I have seen are sophisticated enough to let you to use all the techniques discussed in Gammon's tutorial.

There is nothing like "delay while power saving", as the MCU clock must be turned off. You have to put it to sleep, with some sort of interrupt to wake the MCU. Most people use the watchdog timer to effect a short wakeup period. Google "Arduino watchdog wakeup" for some examples.

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