microAmpere

Lightweight Low Power Arduino Library

We have just release the 1st revision of our low power library for Arduino. This is a simple and easy to use library that has the following features:

  • Supports all sleeping mode of ATmega328P:
    • Idle.
    • ADC reduction mode.
    • Power save.
    • Power down.
    • Standby.
    • Extended standby.
  • Selectable sleep duration:
    • 15 ms, 30 ms, 60 ms, 120 ms, 250 ms, 500 ms, 1 s, 2 s, 4 s, 8 s, and forever (wake up using other resources) through on chip 125 kHz Watchdog timer. Using sleeping forever duration, the Watchdog timer module is not in use and will further reduce the current consumption by approximately 4 µA.
  • Option to shutdown Analog to Digital Converter (ADC) module to further reduce current consumption.
  • Option to disable Brownout Detector (BOD) module to further reduce current consumption by approximately 17 µA. BOD module cannot be disabled through software in idle and ADC noise reduction mode. It can only be disabled through fuse setting in these 2 modes.
  • Option to shutdown Timer 2 module in idle, ADC noise reduction, power save,  and extended standby mode. Timer 2 is used by the core of Arduino for PWM operation.
  • Option to shutdown Timer 0, Timer 1, USART0, TWI, and SPI module in idle mode.

We didn’t add any wake up functionality except using the Watchdog timer module to allow certain amount of sleep duration as we think other wake up resources (interrupt on pins, TWI address match, ADC conversion complete, SPI serial transfer complete, EEPROM ready) are closely bind to the external peripheral or interface it is connected to. For example, an external RTC chip with it’s clock output pin connected to pin 2 of the Arduino board. In this case, the library should not know what this external interrupt signal means to the system (timer or counter for time stamping or other usage). Therefore, we omit them out (at least for now). But, rest assured examples are included (more will be added from time to time) to demonstrate the usage of the library with external peripheral and interface.

Please bear in mind that, most of the Arduino boards (official and also compatible) that is currently available in market (except some brilliant design from JeeLabs and Wiblocks, but there might be more out there that we are not aware of) are not low power by design. Low power design requires both hardware and software implementation. Our Mini Ultra 8 MHz (Arduino compatible) board is designed to be low power and is basically the testing platform for this library. Using the library on any Arduino boards (official or compatible) may and may not yield the best result.

Using our Mini Ultra 8 MHz (we are assembling an army of them right now using our reflow oven controller shield) and revision 1.0 of the library yields the following current consumption measurement result. The board is being powered by a Li-Ion 3.7 V battery running at 8 MHz with 3.3 V. The on board regulator of the Mini Ultra 8 MHz consumes about 1.6 µA of quiescent current.

Mode WDT ADC BOD T2 T1 T0 SPI USART0 TWI Current

Timer 1 & Timer 2 not in use

Timer 2 not clock asynchronously from an external 32.768 kHz crystal  (lower consumption can be further achieved)

Idle On On On On On On On On On 3648.0 µA
Idle Off On On On On On On On On 3643.0 µA
Idle Off Off On On On On On On On *
Idle Off Off On Off On On On On On *
Idle Off Off On Off Off On On On On 3618.0 µA
Idle Off Off On Off Off Off On On On 927.0 µA
Idle Off Off On Off Off Off Off On On 832.0 µA
Idle Off Off On Off Off Off Off Off On 789.0 µA
Idle Off Off On Off Off Off Off Off Off 687.0 µA
ADC Noise Reduction On On On On - - - - - 651.0 µA
ADC Noise Reduction Off On On On - - - - - 646.0 µA
ADC Noise Reduction Off Off On On - - - - - *
ADC Noise Reduction Off Off On Off - - - - - 584.0 µA
Power Down Off Off Off - - - - - - 1.7 µA
Power Down Off Off On - - - - - - 18.6 µA
Power Down Off On On - - - - - - 110.0 µA
Power Down On On On - - - - - - 113.9 µA
Power Save Off Off Off Off - - - - - 1.7 µA
Power Save Off Off Off On - - - - - 416.0 µA
Power Save Off Off On On - - - - - 435.0 µA
Power Save Off On On On - - - - - 527.0 µA
Power Save On On On On - - - - - 531.0 µA
Standby Off Off Off - - - - - - 201.7 µA
Standby Off Off On - - - - - - 218.5 µA
Standby Off On On - - - - - - 309.9 µA
Standby On On On - - - - - - 313.9 µA
Extended Standby Off Off Off Off - - - - - 202.2 µA
Extended Standby Off Off Off On - - - - - 416.0 µA
Extended Standby Off Off On On - - - - - 436.0 µA
Extended Standby Off On On On - - - - - 527.0 µA
Extended Standby On On On On - - - - - 531.0 µA

In idle mode, the IO clock is available for general IO modules usage. Therefore, you need to pull any unused pins low in output mode to reduce the overall current consumption.

In power save mode, Timer 2 can be clocked asynchronously from an external 32.768 kHz crystal to achieve very low current consumption. However, this will require the removal of the external 8 MHz resonator (or crystal in other board variants) to facilitate the low frequency crystal. This will require the ATmega328 to run on its internal 8 MHz on chip RC oscillator in normal operation. But, this will affect time critical modules such as millis, PWM and higher baud rate USART communication as the accuracy of the on chip RC oscillator is limited and is affected pretty much by the operating voltage and temperature. We have some prototype work on running a 32.768 kHz crystal asynchronously which can be seen here.

Here’s a sample code snapshot on how to use the library.

#include "LowPower.h"

void setup()
{
    // No setup is required for this library
}

void loop()
{
    // Sleep for 8 s with ADC module and BOD module off
    LowPower.powerDown(SLEEP_8S, ADC_CONTROL_OFF, BOD_OFF);
    // Do something here
    // Example: read sensor, log data, transmit data
}

The library is available on our GitHub repository. Comments and opinions are greatly appreciated! We hope you find this library useful for your application. Take care and happy tinkering.

119 replies
    • Administrator
      Administrator says:

      Hi Mike,
      You can actually use another microcontroller to measure a voltage drop across a very small resistor placed at the input of the board. But it basically has to be a differential measurement ADC. Then, you can calculate the current and push into a PC or something similar. We use 2 meter in our case, one to measure the current and 1 to monitor the input voltage.

      Reply
  1. Frederic
    Frederic says:

    Hello,
    I would like to put the Arduino to sleep with the command
    LowPower.powerDown(SLEEP_8S, ADC_CONTROL_OFF, BOD_OFF);

    However, I found out that since I have a sensor (TSL230) using an interrupt
    the Arduino doesn’t go to sleep.
    Is there a way to bypass the interrupt for sleeping?

    Thanks for this useful library.

    Reply
    • Administrator
      Administrator says:

      Frederic,
      If I understand the TSL230 correctly, you wanted to use the TSL230 OUT pin to wake the Arduino? In that case instead of using SLEEP_8S as the argument, use SLEEP_FOREVER instead and configure the attachInterrupt on either pin 2 or 3 to wake the Arduino up.

      Reply
      • Frederic
        Frederic says:

        In fact I am using the interrupt for reading frequency of the sensor. I would like to put the Arduino to sleep only with the timer SLEEP_8S; but when an interrupt occurs from the sensor (many time each second depending on lighting condition)the Arduino wakes-up (I tried both pin 2 and 3).
        Is there a way to power down the Arduino only with timer 2 despite the interrupt being used?

        Reply
        • Administrator
          Administrator says:

          The interrupt will definitely wake the Arduino up if the interrupt occurs within that 8s. But, you can go back to sleep after that interrupt happens in this case. If you can use a pin to indicate the sleep & awake sequence, you’ll probably be able to see the sleep & wake up sequence few times within a period of time. Timer 2 can be clocked asynchronously if driven by a low speed crystal attached to the oscillator pins in power save mode. But, that is totally a different thing. In power down mode, all clock to timer are disabled except the WDT.

          Reply
  2. Jory
    Jory says:

    Can someone draft a sample code that would put the device to sleep with a timer running for 15 minutes on low power but could also be woken up by an interrupt on pin 2 high (ie, external power is attached). why doesn’t the below work?

    // **** INCLUDES *****
    #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_900S, ADC_OFF, BOD_OFF);

    // Disable external pin interrupt on wake up pin.
    detachInterrupt(0);

    // Do something here
    // Example: Read sensor, data logging, data transmission.
    }

    Reply
    • Administrator
      Administrator says:

      Jory,
      The maximum period you can insert is SLEEP_8S using the watchdog timer.
      If you need to do something after 15 minutes periodically, you can use SLEEP_4S and wake up 225 times before executing the task you have in hand. The awake time to increment a counter (and check whether it is the 225′s time) will take pretty little time to execute.

      Reply
  3. Jory
    Jory says:

    Makes sense. If I need to use the 2 interrupts and the timer for the 4S what is the best option for saving power?

    Also, do I need to detach the interrupts afterwards while I execute other functions during normal use? If so, (due to volitility) what is my best option for always being able to utilize the interrupts at any time?

    Thanks

    Reply
  4. Jory
    Jory says:

    I’m getting an error using the library that BODS was not declared in the scope even though the h and cpp files are in the sketch folder.

    Here is the code that I’m using in my sketch:
    //int i is for loop decrement to have a 15 minute sleep (many 8 second sleeps) and if there is an interrupt then instead of decrementing the loop I want it to end the sleep cycling.

    void wakeUp() //place to send the interrupts
    {
    int i=0;
    }

    void sleep()
    {
    // Allow wake up pins to trigger interrupt on change.
    attachInterrupt(0, wakeUp, CHANGE); //Interrupt on pin 2 for any change in power plug
    attachInterrupt(1, wakeUp, CHANGE); //Interrupt on pin 3 for any change in solar power

    // Enter power down state with ADC and BOD module disabled.
    // Wake up when wake up interrupts are triggered.
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

    detachInterrupt(0);
    detachInterrupt(1);
    }

    Reply
    • Kdub
      Kdub says:

      I am getting this same error when trying to use the library, it is in the correct location but it seems like a variable isn’t declared or something in the .cpp file. Also is this compatible with a mega2560?

      Reply
      • Administrator
        Administrator says:

        If you are trying to compile them to work for either 32U4 or Mega2560, the library is yet to support both of that chip. But, we will support them in the future. We need some low power board to test them.

        Reply
  5. Dan
    Dan says:

    Does the UNO fully support this library? I tried it with (as I recall) success with a Duemilanove and saw a significant reduction in power consumption. Now I’m using an UNO but never using less than about 20 mA with LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);. Nothing more than a bare Arduino and code that switches back and forth between power off 8s and delay(8000). I seem to recall better results with the 2009. Any thoughts, or am I missing something major? Thanks.

    Reply
    • Administrator
      Administrator says:

      It shouldn’t be any different actually. The only different I can from the Uno point of view is the bootloader (upload speed, Optiboot smaller boot size). But, I didn’t actually try on an bare Uno yet. Some guys tested it to work with the Pro Mini with Optiboot bootloader and it works fine. Maybe you can a look at the fuses as a start?

      Reply
    • Administrator
      Administrator says:

      Ron,

      Haven’t check it’s compatibility on other processor other than ATMega328P. Currently looking for Mega2560 & Mega32U4 boards that I can convert into low power boards and expand the library supported devices.

      Reply
  6. Peter
    Peter says:

    Hello,

    using your library are causing Errors.

    ///MyCode///

    #include “LowPower.h”

    void setup()
    {
    // No setup is required for this library
    }

    void loop()
    {
    // Sleep for 8 s with ADC module and BOD module off
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    // Do something here
    // Example: read sensor, log data, transmit data
    }

    ///MyCode///

    Errors:

    LowPower.cpp: In member function ‘void LowPowerClass::powerDown(period_t, adc_t, bod_t)’:
    LowPower.cpp:298: error: ‘BODS’ was not declared in this scope
    LowPower.cpp:298: error: ‘BODSE’ was not declared in this scope
    LowPower.cpp: In member function ‘void LowPowerClass::powerSave(period_t, adc_t, bod_t, timer2_t)’:
    LowPower.cpp:379: error: ‘BODS’ was not declared in this scope
    LowPower.cpp:379: error: ‘BODSE’ was not declared in this scope
    LowPower.cpp: In member function ‘void LowPowerClass::powerStandby(period_t, adc_t, bod_t)’:
    LowPower.cpp:439: error: ‘BODS’ was not declared in this scope
    LowPower.cpp:439: error: ‘BODSE’ was not declared in this scope
    LowPower.cpp: In member function ‘void LowPowerClass::powerExtStandby(period_t, adc_t, bod_t, timer2_t)’:
    LowPower.cpp:512: error: ‘BODS’ was not declared in this scope
    LowPower.cpp:512: error: ‘BODSE’ was not declared in this scope

    Where is the problem?

    Reply
    • Administrator
      Administrator says:

      Hi Peter,

      I believe your are trying to compile for Mega2560 or a Mega32U4?
      Both of the chip’s BOD cannot be controlled through software. So, they lacked of the BODS register & BODSE control bit. I’m currently working to support that 2 MCU. You need a fast workaround, drop us a mail from the website.

      Reply
  7. Qint
    Qint says:

    I’am using Arduino 0023 and Arduino FIO board. I always getting this error

    powerDownWakePeriodic.cpp:2:22: error: LowPower.h: No such file or directory
    powerDownWakePeriodic.cpp: In function ‘void loop()’:
    powerDownWakePeriodic:11: error: ‘LowPower’ was not declared in this scope
    powerDownWakePeriodic:11: error: ‘SLEEP_8S’ was not declared in this scope
    powerDownWakePeriodic:11: error: ‘ADC_OFF’ was not declared in this scope
    powerDownWakePeriodic:11: error: ‘BOD_OFF’ was not declared in this scope

    The library is already put in Arduino libraries folder

    Thanks

    Reply
    • Administrator
      Administrator says:

      Did you rename the downloaded library (removing characters appended by GitHub) accordingly to “LowPower”?
      If the example is accessible from the IDE, the library should be there as well.

      Reply
  8. Sebastian
    Sebastian says:

    Hi,

    I try to use your library with a atmega168. After some errors I realised, that the BODS is not supported by that chip.

    Is there a way to use your library anyway?

    Regards

    Sebastian

    Reply
    • Administrator
      Administrator says:

      Hi Sebastian,

      Yes, the BODS register is only available on Pico Power devices. If need help for that, drop us a mail. We have a subsequent beta version.

      Reply
  9. Toby Borland
    Toby Borland says:

    I’ve been successfully using the LowPower library on an Arduino Duemilanove with an ATMega328P. Having switched to the low power Olimexino-32U4, based around Leonardo architecture, the 32U4 will not support software BODS control (see above). Do you have a workaround/beta?

    Reply
      • Christian
        Christian says:

        i’m currently working with an arduino leonardo and xbee and i’m trying to put the system to sleep. is it possible that you could also send me the beta/workaround, please. i didn’t find an update of the library on github yet.

        Thanks in advance!
        Christian

        Reply
      • Toby Borland
        Toby Borland says:

        Heck, sorry.. I missed this, I just commented out the BODS stuff and it worked fine. The Leonardo boards were switched out for Xino boards in the end. Thanks, T

        Reply
  10. Anders J
    Anders J says:

    May I also request support for the Atmega2560, or any beta code that you have developed for it so far? I would find great use for it! Can also report back on whether or not it works with the Mega.
    Thanks!
    Anders

    Reply
    • Administrator
      Administrator says:

      I haven’t actually try it out or look at the registers of Attiny45. There could be quite a number of peripheral not on the Attiny series. Expect some compilation error due to that.

      Reply
  11. mark
    mark says:

    Hi,

    I would like to apply this to an open source GPS tracker (http://dsscircuits.com/geogram-one.html)

    Could someone help me out with this.

    The shipped sketch is using the millis timer to send the GPS and GSM module to sleep (not the MCU) but it consumes too much power for what I would like to use it for (Long term tracking, say 6+ months, with a 6000mAh battery).

    If I could get the Arduino chip to sleep also, that would make this device so much better!

    Thanks

    Reply
    • Administrator
      Administrator says:

      You need another wake-up source other than millis(). Depending on your required timing accuracy, the built-in watch-dog timer (although will drift a little across temperature) could be enough. Other than that, an external RTC can also be used to wake the processor up.

      Reply
      • mark
        mark says:

        ok, thanks. Is there any way to “sync” with the GPS time to keep the timer drift to a minimum?

        If I understand correctly, the watchdog timer sleeps the device after it has completed one loop of the code for upto 8 seconds, then completes another loop, sleeps for 8 seconds and so on. Is that correct?

        Reply
  12. Colby
    Colby says:

    Hey,

    I’m playing with the ATMega32u4. Could I get a copy of the beta library that supports it?

    I’ve tested with the Uno and the ATMega328P and it works great!

    Reply
  13. Pauli Hickox
    Pauli Hickox says:

    Hi,

    Thanks for the nice product (Mini Ultra+) and the low-power library. Being new to sleep modes and energy optimization with MCUs, I could not figure out how to make the software RTC (RTClib in my case) to work with the sleep mode, is it just impossible or do I always need a hardware RTC (like DS1307)?

    My example code is like that:

    #include
    #include “RTClib.h” // https://github.com/adafruit/RTClib
    #include // https://github.com/rocketscream/Low-Power

    RTC_Millis RTC;

    void setup(void){

    Serial.begin(115200);
    Wire.begin();

    // following line sets the RTC to the date & time this sketch was compiled
    RTC.begin(DateTime(__DATE__, __TIME__));

    }

    void loop(){

    // Sleep for x s with ADC module and BOD module off
    // other options, see LowPower.cpp, e.g. 15 ms to FOREVER
    LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); // ADC_CONTROL_OFF -> ADC_OFF

    // Get the time using the “software RTC”
    DateTime now = RTC.now();

    // Print on the Serial Monitor / Console the time (debugging)
    Serial.print(now.year(), DEC);
    Serial.print(‘/’);
    Serial.print(now.month(), DEC);
    Serial.print(‘/’);
    Serial.print(now.day(), DEC);
    Serial.print(‘ ‘);
    Serial.print(now.hour(), DEC);
    Serial.print(‘:’);
    Serial.print(now.minute(), DEC);
    Serial.print(‘:’);
    Serial.print(now.second(), DEC);
    Serial.println();

    // Integer that could be saved to the EEPROM
    // Could be then converted to human-readable format when reading
    // in the data in Python, Matlab, Java, whatever
    Serial.print(” seconds since 1970: “);
    Serial.println(now.unixtime());

    delay(10);
    }

    And the output on Serial Monitor like that (the time increment in “real-world time” is now 1 second)

    2013/4/18 12:52:25
    seconds since 1970: 1366289545
    2013/4/18 12:52:25
    seconds since 1970: 1366289545
    2013/4/18 12:52:25
    seconds since 1970: 1366289545
    2013/4/18 12:52:25
    seconds since 1970: 1366289545

    Thanks,
    P

    Reply
    • Administrator
      Administrator says:

      The millis() requires the IO clock to drive the Timer 0. During sleep, it is not available.
      Another more accurate way of doing this is using an external 32.768 kHz crystal (but the processor has to run off the internal 8 MHz) to drive Timer 2 asynchronously during power save mode. Simpler method, would be using the external RTC like what you mentioned above.

      Reply
  14. Joakim
    Joakim says:

    Hi, nice library and it works perfect.

    I have a question – is it possbile to wake up the arduiono by for example a key press?

    Or does that has to happen when the sleep of 8 seconds is done?

    Joakim

    Reply
    • Administrator
      Administrator says:

      You could attach external interrupt (key press) and then power down (SLEEP_FOREVER). It will wake up upon the key press.

      Reply
      • Joakim
        Joakim says:

        Ah ok – but I do want my arduino to check some status from time to time and then go to sleep to save my batteries. But if the user pushes a button I would like the arduino to do some stuff and then get back to sleep and start checking when it wakes from the sleep period. This is not possible is it?

        Joakim

        Reply
        • Administrator
          Administrator says:

          You can do that. By pushing it to power down mode with the sleep interval you desire. At the same time, attach the external interrupt.
          In this case, your board could wake up on either of the source. To check the wake up source, use a semaphore flag in your external interrupt handler function and check it upon waking up.

          Reply
  15. ARJunior
    ARJunior says:

    Very great library !
    Works perfectly with ATmega328P.
    Don’t know if I can use it with Attiny85 chip…will try it later…

    Thank you ;)

    Reply
  16. Brendan
    Brendan says:

    Hi, I also am working with the Mega2560 (the ADK version) and would love to try out and beta test the code. I will be using this in a battery powered remote install and could really use some help taking down the power a bit. Thanks!

    Reply
    • Administrator
      Administrator says:

      Hi Brendan,

      The latest version on GitHub has support for Mega2560.
      But, if you are using the official Mega2560 or ADK, I think the current consumption won’t be very low due to the design.

      Reply
      • Brendan
        Brendan says:

        Hi, thanks so much for your quick reply. You’re right of course, the megas use a lot of power, so I ended up purchasing one of your minis and am overall very happy with it. However, I have a question about the low power function that might be more general.

        I am using an LED screen with the controller, and when the atmega is sleeping, screen “dims” but does not completely blank (sort of a ghosting effect of the most recent screen). The screen is powered via a separate 5v supply that is enabled by the microcontroller (and is thus off) and I’m using the full .powerDown with interrupt.

        I’m guessing (hoping?) that this is because the pins on the atmega are floating a bit and providing just enough current to power the screen ( which is why I’m at 40µA instead of the few without the LED). Any ideas on how to solve this? Should I set all the pins as input and change them back upon waking? I’m ripping my hair out on this one.

        Reply
        • Administrator
          Administrator says:

          Hi Brendan,

          You could usually set the pins to output low but it also depends on the pins on the other having a pull-up or not. You definitely don’t want to provide a low resistance path for the current to flow. The extra tens of uA could be one of the pins.

          Other way would be using a transistor or MOSFET to completely cut-off the supply to your LCD.

          Reply
  17. muhkuh
    muhkuh says:

    So I am able to do the following:

    run measurement and check some stuff
    sleep some time
    rune some other stuff
    sleep some time

    start from top again.

    ? I guess so.

    Reply
  18. muhkuh
    muhkuh says:

    If I try:

    #include “LowPower.h”

    void setup()
    {
    Serial.begin(9600);
    }

    void loop()
    {
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);

    Serial.println(“Ill go to sleep now for 8 seconds”);
    //delay(100);
    }

    it won’t work unless i uncomment the delay part… because it does to sleep again before the Serial.print has completed … how to solve this?

    Reply
    • Administrator
      Administrator says:

      You could use Serial.flush() after the Serial.println() instead of the delay().
      That will ensure all characters are transmitted before going into power down mode.

      Reply
      • muhkuh
        muhkuh says:

        Thanks for this helpful answer!

        Too bad this was just an example to point on my problem in common.

        Is there a way to make sure all tasks have been completed before entering sleep modes?

        For example when I’m sending commands to an IC via SPI ?

        Reply
        • Administrator
          Administrator says:

          The SPI.transfer() function returns when it’s completed unlike the Serial.print() function.
          You have to ensure to all tasks are done before sleep.

          Reply
  19. Hugo Z.
    Hugo Z. says:

    Hi, I’m very new with the arduino, I work in a remote control based on nrf24l01 chip and I want to save batteries.
    I have 10 inputs (Switchs) and I want to use the powerDownWakeExternalInterrupt example

    I don’t know how to add more that one wake up pins (i need 10) on that example.
    some one can help me.

    I know maybe this it’s very simple but this are my firs experiment on electronics.
    Thanks.

    Reply
  20. Hugo
    Hugo says:

    Ok, thanks.
    I try with PinChangeInt Library without success.
    It’s compatible LowPower Library with PinChangeInt Library?

    Reply
  21. pndtkd
    pndtkd says:

    Hi, i use this function to put my ATMEGA328 in idle mode:
    LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF,
    SPI_OFF, USART0_ON, TWI_OFF);
    But if i receive a serial command (Serial.read()) i want wake up my micro controller.
    it is correct?

    finally which are the differences between idle mode and power down mode?

    Thanks.

    Reply
    • Administrator
      Administrator says:

      Once you have enter into idle mode with the SLEEP_8S and USART0_ON parameters, you would either wake up due to the 8 s watchdog timeout or a character is received on the USART0. Once, you wake up, you should use Serial.read() to check whether there’s a valid character.

      The main differences is obviously the amount of power consumed.
      Check page 39 (Section 9.1) of the ATMega328P datasheet to see the differences.

      Reply
  22. Lensdigital
    Lensdigital says:

    Can someone help me to modify library to include support for ATMega644p and ATMEga1284p (they pretty much identical other than memory size)? According to Datshet they have only 2 timers and 2 USARTS.

    Reply
  23. Anjian Wu
    Anjian Wu says:

    In the example code of:
    #include “LowPower.h”

    void setup()
    {
    // No setup is required for this library
    }

    void loop()
    {
    // Sleep for 8 s with ADC module and BOD module off
    LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF);
    // Do something here
    // Example: read sensor, log data, transmit data
    }

    Does the function LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF) just sleep for 250 MS and THEN everything that was powered down becomes available again to use? (e.g. ADC, etc.) until it hits LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF);
    again?

    Thanks!

    Reply
  24. Glyn
    Glyn says:

    Seems to be a problem on the UNO, I have two..
    After uploading the powerDownWakePreiodic example to both the results are :-
    1. Proper smdedition board gives approx 24mA
    2. Non smd clone board gives approx 16mA

    I was hoping for a more substantial saving was I optimistic?

    Reply
  25. Peter K
    Peter K says:

    Thank you a lot for Low Power library and I was wondering if you a table or estimates of power savings possible using your Mini Ultra 8 MHz Plus which I am currently testing here and when measuring with a HP 34401A multimeter I cannot get average current lower than around ~8.7 mA (compared to ~12.8 mA with no sleep mode)

    Am I doing something wrong, or is there just a different overhead from the Plus board?

    This is my LowPower sample sketch


    #include "LowPower.h"

    int sensorPin = A0; // select the input pin
    int sensorValue = 0; // variable to store the value coming from the sensor

    void setup()
    {
    // No setup is required for this library
    }

    void loop()
    {
    // Enter power down state for 8 s with ADC and BOD module disabled
    // LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);

    // Do something here
    // Example: Read sensor, data logging, data transmission.
    sensorValue = analogRead(sensorPin);
    }

    And for without, I just commented the LowPower line

    Best wishes,
    Peter

    Reply
    • Administrator
      Administrator says:

      Hi Peter,

      I just tested the code, it should be around 40 uA when sleep using 4 s. The wake up duration to read the sensor is very tiny.
      If I changed the sleep duration to 8 s, I can see the current goes down to 36 uA. This probably due to the meter’s response time.
      I’m using a Li-Ion to power the battery in this setup.

      If you are powering from the VEXT instead of the battery, then it should be few mA during sleep.

      Reply
  26. Mike
    Mike says:

    Excellent library! I’m have a 328P connected to a lipo through an LDO and it wakes on pushbutton to light an led. I’d like to have the light on forever until the same button is pressed again where it goes back to sleep. Do I need to set up the interrupt pin again in a while loop that waits for the button press and has the led lit?

    Reply
  27. Mike
    Mike says:

    This may not be the best place to ask since I’ve modified the code but if you can help with my problem that toggles the LED from always on to deep sleep it would be great. I might be close. Right now the LED occasionally stays on but it takes quite a few presses. The deep sleep part works great.

    #include “LowPower.h”

    // Use pin 2 as wake up pin
    const int wakeUpPin = 2;
    int led = 13;
    volatile int state = LOW;

    void setup()
    {
    // Configure wake up pin as input.
    pinMode(wakeUpPin, INPUT);
    //digitalWrite(2, HIGH);
    pinMode(led, OUTPUT);
    }

    void loop()
    {
    // Allow wake up pin to trigger interrupt on high.
    attachInterrupt(0, toggle, HIGH); //note the High on my design

    // Enter power down state with ADC and BOD module disabled.
    // Wake up when wake up pin is high.
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

    // Disable external pin interrupt on wake up pin removed for it to work
    // detachInterrupt(0);

    }

    void toggle()
    {
    if(state == LOW)
    {
    state = HIGH;
    }
    else
    {
    state = LOW;
    }
    digitalWrite(led, state);

    }

    Reply
    • Administrator
      Administrator says:

      Mike,

      The reason, the LED occasionally stay on is because the processor is running way much faster than your finger is letting the button go.
      So, the loop runs few times and by luck the LED turns on or off. Best is to set a semaphore flag in the “toggle” function and check this semaphore flag once you are awake and perform proper button debounce procedure to allow the button to be pressed correctly and let go before sleeping again.

      Reply
  28. Rors
    Rors says:

    Hi all,

    I’m pretty new to all this, attempting to use a GSM shield, which draws a bit of power, on a Arduino Uno board.

    My problem is that even at compile stage, with the most simple code examples, I get the error: ‘LowPower’ was not declared in this scope.

    I have installed the library, added through the IDE under sketch.

    Can anyone shed light on this please? Many thanks, Rors

    Reply
  29. Rors
    Rors says:

    Ignore the above, please:

    After totally reinstalling the library files, it seems to be working, except its saying:

    ‘ADC_CONTROL_OFF’ was not declared in this scope

    Any suggestions, please?

    Thanks, Rors

    Reply
  30. Jerry
    Jerry says:

    Hi.
    First Thank you for the library, it’s great!

    I wanted to know, I’m using arduino mega 2560 and arduino pro micro 5v/16mhz. Are they supprorted?
    Also, I need the mega to wake up once every couple of minutes, do some stuff and go back to sleep. I don’t have an intterupt on pin 2.
    I thought of doing something like this:

    for(int i=0; i<15; i++)
    {
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    }

    Is this possible?

    It does comiple with the arduino mega selected.

    Thank you

    Reply
    • Administrator
      Administrator says:

      Hi Jerry,

      That should work but not sure how much you would gain by running them on a Mega2560 & Pro Micro as both of them consumes quite a lot of current even during sleep due to the supporting circuitry on the board itself.

      Reply
  31. insanable
    insanable says:

    Hey, I’m also looking for the low power library for the arduino Leonardo, could you also send me the workaround too?

    Thanks

    Reply
  32. 0miker0
    0miker0 says:

    If anyone has code where you push to wake from sleep to turn on a LED and then press the button again to turn off the led and go back to sleep it would be great. This would be a great idea for a single momentary power button.

    Reply
  33. Alireza
    Alireza says:

    Hey my board is Arduino Leonardo and I have bluetooth module connected to it. I’m trying to send data via bluetooth to my laptop. I have installed your library however, anytime that I upload a sketch (even you own example), after uploading, Windows gives me an error saying “The device (Leonardo) has malfunctioned and cannot be recognized”. Do I do anything wrong here? Here is my simple test code:

    #include

    void setup() {
    Serial1.begin(9600);
    }
    void loop(){
    LowPower.powerDown(SLEEP_500MS, ADC_OFF, BOD_OFF);
    Serial1.println(“hullo”);
    }

    Reply
    • Administrator
      Administrator says:

      Hi Alireza,

      Before a USB slave device goes to sleep, it needs to inform the host (PC) that it is going to sleep. I’m not sure how to do that yet through Arduino but several guys that used the library on 32U4 based boards ditches the USB interface from the application. In order to load new sketches, try to read the suggestion on this forum discussion.

      Reply
      • Alireza
        Alireza says:

        Thank you for your reply. I tried the library on the Uno and it works just fine. However as I said I’m using the Leonardo. I put a 5 second delay in the setup and it solved the problem of Leonardo going unrecognized. But the problem now is that I cannot get the serial communication over Bluetooth or USB cable work anymore.

        Reply
      • Alireza
        Alireza says:

        Well I got the serial communication working and everything is fine now. BUT since the microprocessor goes on and off, the current drawn from my 9V battery goes from ~12mA to ~50mA with the Bluetooth module connected and this current fluctuation itself causes the battery to drain quickly. This actually defeats the purpose of having a LOWPOWER library for my application. Do you have any recommendation regarding this by any chance?

        Reply
        • Administrator
          Administrator says:

          Did you shut off the Bluetooth module? The current fluctuation indicates it is on. Just check whether it can be turned off through software or pin control and in worst case cutting off the power to it through a transistor or MOSFET.

          Reply
  34. hzdbyte
    hzdbyte says:

    I have an issue with this library and Arduino Micro (ATMega32U4).
    When I call “LowPower.idle” arduino doesn’t wait for the specified amount of time and continues to execute the code immediately.

    The test code is

    void loop()
    {
    // ATmega32U4
    LowPower.idle(SLEEP_8S, ADC_OFF, TIMER4_OFF, TIMER3_OFF, TIMER1_OFF,
    TIMER0_OFF, SPI_OFF, USART1_OFF, TWI_OFF, USB_OFF);
    Serial.println(“LOOP”);
    }

    What’s wrong?

    Reply

Trackbacks & Pingbacks

  1. […] techniques, combined with a library such as RocketScream’s library for low power devices or EnerLib should also enable some performance gains. OpenHomeAutomation has an interesting post […]

  2. […] time the device should be asleep in SLEEP_MODE_POWER_DOWN. You can base your sleep routines off the Rocketscreem Low Power Library. According to that link you should be able to get it down to 1.7uA with ADC, BOD and WDT off and in […]

  3. […] use the Arduino LowPower library from Rocket Scream, which can be downloaded from […]

  4. [...] found this one on RocketScream which looks really promising, and really easy to use. I worked on top of their [...]

  5. [...] is a link to the Arduino sketch: CountingPeople.zip And don't forget to install these libraries: lowPower Adafruit_GFX Adafruit_LEDBackpack This was a fun weekend project. The only problem is that I [...]

  6. [...] is freely available under GPLv3 license on github. The code itself is pretty simple: it uses the Arduino LowPower library by RocketScream to keep the arduino sleeping for most of the time. It only wakes on an event on [...]

  7. [...] low. Turns out the BOD uses quite a bit of power when turned on (something like 0.25mA). The BOD doesn’t seem to use so much power but it’s a good tradeoff for the protection it gives. Turning off the ADCs will yield much [...]

  8. [...] Low Power Library – Βιβλιοθήκη για εντολές Sleep Mode για Arduino [...]

  9. [...] Scream has developed a lightweight low power library that supports all AVR power down modes.  Each mode has an associated library method that lets you [...]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *


7 + five =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>