0
0
Arduinoprogramming~5 mins

LowPower library usage in Arduino

Choose your learning style9 modes available
Introduction

The LowPower library helps your Arduino save battery by putting it to sleep when it is not doing anything important.

When your Arduino project runs on batteries and you want it to last longer.
When your device waits for a button press or sensor event and can sleep in the meantime.
When you want to reduce power use during idle times in your program.
Syntax
Arduino
LowPower.sleep(sleepTime);

// sleepTime can be:
// SLEEP_15MS, SLEEP_30MS, SLEEP_60MS, SLEEP_120MS, SLEEP_250MS, SLEEP_500MS, SLEEP_1S, SLEEP_2S, SLEEP_4S, SLEEP_8S

Include the library with #include <LowPower.h> at the top of your sketch.

Use LowPower.sleep() to put the Arduino into a low power sleep mode for a set time.

Examples
This example puts the Arduino to sleep for 1 second repeatedly.
Arduino
#include <LowPower.h>

void setup() {
  // setup code here
}

void loop() {
  LowPower.sleep(SLEEP_1S); // sleep for 1 second
}
This puts the Arduino into a deeper sleep (power down) for 8 seconds, turning off ADC and brown-out detector to save more power.
Arduino
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
Sample Program

This program blinks the built-in LED on for half a second, then sleeps for 2 seconds to save power before repeating.

Arduino
#include <LowPower.h>

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH); // turn LED on
  delay(500); // wait half a second
  digitalWrite(LED_BUILTIN, LOW); // turn LED off

  // sleep for 2 seconds to save power
  LowPower.sleep(SLEEP_2S);
}
OutputSuccess
Important Notes

Sleep modes stop the CPU but keep some parts running depending on the mode.

Use the deepest sleep mode possible to save the most power.

Interrupts can wake the Arduino from sleep early if needed.

Summary

The LowPower library helps save battery by sleeping the Arduino.

Use LowPower.sleep() or LowPower.powerDown() with different sleep times.

Choose sleep modes based on how much power you want to save and what needs to stay active.