Arduino Power Consumption and Sleep Mode Features
Power consumption is a critical issue for a device running continuously for a long time
without being turned off. So, to overcome this problem almost every controller comes with a
Sleep Mode, which helps developers to design electronic gadgets. Sleep mode puts the device
in power-saving mode optimal power consumption by turning off the unused modules. An
Arduino Sleep mode is also referred to as Arduino Power Save Mode or Arduino Standby
Mode. Arduino UNO, Arduino Nano, and Pro-mini come with ATmega328P and it has a
Brown-Out Detector (BOD), which monitors the supply voltage at the time of Sleep Mode.
Sleep modes enable the application to shut down unused modules in the MCU, thereby saving
power. The AVR provides various sleep modes allowing the user to tailor power consumption
to the application’s requirements. There are six sleep modes in ATmega328P:
SMCR – Sleep Mode Control Register
The Sleep Mode Control Register (SMCR) contains control bits for power management. The
function of these bits (SM2:0) is shown in the next slide. For entering any of the sleep modes,
we need to enable the sleep bit in the Sleep Mode Control Register (SMCR.SE). Then, the
Sleep Mode Select bits select any 1 of the sleep modes among 6 different sleep modes, viz.
Idle, ADC Noise Reduction, Power-Down, Power-Save, Standby, and External Standby. An
internal or external Arduino interrupt or a Reset can wake up the Arduino from sleep mode.
Idle Sleep Mode:
For entering into the Idle sleep mode, write the SM[2,0] bits of the controller ‘000’. This
mode stops the CPU but allows the SPI, 2-wire serial interface, USART, Watchdog,
counters, and analog comparator to operate. Idle mode basically stops the CLKCPU and
CLKFLASH. Arduino can be woken up at any time by using the external or internal
interrupts. Arduino Code for Idle Sleep Mode:
LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF,
SPI_OFF, USART0_OFF, TWI_OFF);
Standard Low Power Example:
This is the simplest way of implementing the Low Power mode. It will use the LED as an
indicator to tell if the device is in an active state or sleep state. The device will be in a
sleep state for 5 seconds.
#include "ArduinoLowPower.h"
void setup() {
pinMode(LED_BUILTIN, OUTPUT); }
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
LowPower.sleep(5000);
}
Here we can also change the line of the code to perform the Deep Sleep mode of the
device.
//LowPower.sleep(5000);
LowPower.deepSleep(5000);
Low Power-Power Down Mode Example:
In this sketch, the Arduino blinks an LED for 2 s and is then powered down for 2 s, and
during that time the ADC and Brown-Out Detect (BOD) are disabled. When powered
down, the Arduino's current drops from several mA to less than a mA! We can use a USB
ammeter to measure the current. From there, we can compute the power using the formula
P = VI, where V is the supply voltage of 5 V.
#include "LowPower.h"
void setup() {
pinMode(8, OUTPUT);
}
void loop() {
digitalWrite(8, HIGH);
delay(2000);
digitalWrite(8, LOW);
LowPower.powerDown(SLEEP_2S, ADC_OFF, BOD_OFF);
}
Let’s load this sketch onto our Arduino, which is running with a 5 V supply at 16 MHz.
To see how little current is needed in sleep mode, we are using an Arduino ATmega328P
board to minimize the current. In this setup, to demonstrate Arduino Power Save or Deep
Sleep Modes, the Arduino is plugged into the USB ammeter. Then the USB ammeter is
plugged into the USB port of the laptop. USB ammeter is a plug-and-play device used to
measure the voltage and current from any USB port. The dongle plugs in between the
USB power supply (computer USB port) and the USB device (Arduino). This device has
a 0.05 resistor in-line with the power pin through which it measures the value of the
current drawn. The device comes with four seven-segment displays, which instantly
display the values of current and voltage consumed by the attached device. These values
flip in an interval of every 3 seconds.
USB Ammeter Connection of Arduino with the USB and Laptop
Arduino Code for Power-Down Periodic Mode:
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
The code is used to turn on the power-down mode. By using the above code, the Arduino
will go to sleep for eight seconds and wake up automatically. We can also use the power-
down mode with an interrupt, where the Arduino will go to sleep but only wakes up when
an external or internal interrupt is provided.
Arduino Code for Power-Down Interrupt Mode:
void loop() {
// Allow the wake-up pin to trigger an interrupt on low.
attachInterrupt(2, wakeUp, LOW);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
// Disable external pin interrupt on the wake-up pin.
detachInterrupt(2);
// Do something here
}
In the void setup function, we have initiated the serial communication by using
Serial.begin(9600), here the 9600 is the baud rate. We are using Arduino’s built-in LED
as an indicator for Sleep Mode. So, we have set the pin as OUTPUT and sent a LOW
signal to this pin using the digitalWrite() command.
Before enabling the sleep mode, we are printing “Arduino:- I am going for a Nap” and
making the built-in LED LOW. After that, Arduino sleep mode is enabled by using the
command mentioned below in the code. The following code enables the idle periodic
sleep mode of the Arduino and gives a sleep of eight seconds. It turns the ADC, Timers,
SPI, USART, and 2-wire interface into the OFF condition. Then, it automatically wakes
up Arduino from sleep after 4 seconds and prints “Arduino:- Hey I just Woke up”.
So, by using this code Arduino will only wake up for 36 seconds (6 s×6 times of the loop)
in a minute and will remain in sleep mode for the rest of the 24 (= 60 – 36 = 4 s×6 times
of the loop) seconds, which significantly reduces the power consumed by the Arduino-
based LED ON-OFF system. Therefore, if we use Arduino with Sleep Mode, we can
increase the device runtime.
#include <LowPower.h>
#define LED_RED 8
void setup() {
Serial.begin(9600);
pinMode(LED_RED, OUTPUT);
// SMCR = 0b00001101;
}
void loop() {
digitalWrite(LED_RED, HIGH);
delay(2000);
Serial.println(“Arduino:- I am going for a Nap”);
digitalWrite(LED_RED,LOW);
LowPower.idle(SLEEP_4S, ADC_OFF, TIMER2_OFF, TIMER1_OFF,
TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);
Serial.println(“Arduino:- Hey I just Woke up”);
delay(4000);
}