Arduino Sleep Modes and How to use them to Save the Power

Published  September 12, 2019   0
Arduino Sleep Modes and How to use them to Save the Power

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 an Arduino sleep mode, which helps developers to design electronic gadgets for optimal power consumption. Sleep mode puts the device in power-saving mode by turning off the unused module. Whether you're building a weather station, IoT sensor, or remote monitoring system, understanding Arduino low power sleep techniques is essential for optimal performance. This comprehensive guide covers Arduino sleep mode programming, Arduino sleep mode power consumption measurements, and practical implementation for Arduino UNO, Nano, and Pro Mini. We'll demonstrate how to implement Arduino sleep and wake up functionality while measuring actual power savings using real-world testing.

Earlier, we explained the Deep-sleep mode in ESP8266 for Power Saving. Today, we will learn about Arduino Sleep Modes and demonstrate power consumption by using an Ammeter. An Arduino Sleep mode is also referred to as Arduino Power Save mode or Arduino Standby Mode

Arduino Weather Station with DHT11 sensor demonstrating sleep mode implementation for power optimization

Arduino Sleep Modes Quick Comparison

Sleep ModePower ConsumptionActive ModulesWake-up SourcesBest Use Case
Idle Mode~15 mASPI, USART, Timers, ADCAll interruptsShort delays with peripheral access
ADC Noise Reduction~10 mAADC, External interruptsADC, External interrupts, TimersPrecision ADC measurements
Power-Down~0.1 μAWatchdog Timer onlyExternal interrupts, WatchdogMaximum power savings
Power-Save~1-2 μATimer2 (async), WatchdogTimer2, External interruptsRTC applications
Standby~1.5 μAExternal oscillatorExternal interruptsFast wake-up needed
Extended Standby~2 μATimer2, External oscillatorTimer2, External interruptsRTC with fast wake-up

Understanding Arduino Sleep Modes

Arduino sleep modes allow the user to stop or turn off the unused modules in the Microcontroller, which significantly reduces the power consumption. 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. Implementing Arduino UNO low power mode is crucial for battery-powered applications.

There are six sleep modes in ATmega328P:

Six Arduino sleep modes in ATmega328P microcontroller showing Idle, ADC Noise Reduction, Power-Down, Power-Save, Standby, and Extended Standby modes

To enter 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 the sleep mode among 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 the sleep mode.

Arduino Sleep Modes Explained in Detail

1. Idle Mode - Arduino Sleep Function Basics

For entering into the Idle Arduino low power sleep, 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, analog comparator to operate. Idle mode basically stops the CLKCPU and CLKFLASH. Arduino can be woken up at any time by using an external or internal interrupt.

Arduino Code for Idle Sleep Mode:

LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);

There is a library for setting various low-power modes for Arduino sleep mode programming. So first download and install the library from the given link, and use the above code to put the Arduino in Idle Sleep Mode. By using the above code, the Arduino will go into a sleep of eight seconds and wake up automatically. As you can see in the code that the idle mode turns off all the timers, SPI, USART, and TWI (2-wire interface).

2. ADC Noise Reduction Mode

To use this sleep mode, write the SM[2,0] bit to ‘001’. The mode stops the CPU but allows the ADC, external interrupt, USART, 2-wire serial interface, Watchdog, and counters to operate. ADC Noise Reduction mode basically stops the CLKCPU, CLKI/O and CLKFLASH. We can wake up the controller from the ADC Noise Reduction mode by the following methods:

  • External Reset
  • Watchdog System Reset
  • Watchdog Interrupt
  • Brown-out Reset
  • 2-wire Serial Interface address match
  • External level interrupt on INT
  • Pin change interrupt
  • Timer/Counter interrupt
  • SPM/EEPROM ready interrupt

3. Power-Down Mode - Maximum Arduino Sleep Mode Power Consumption Reduction

Power-down mode stops all the generated clocks and allows only the operation of asynchronous modules. It can be enabled by writing the SM[2,0] bits to ‘010’. In this Arduino sleep mode power consumption, the external oscillator turns OFF, but the 2-wire serial interface, watchdog and external interrupt continue to operate. It can be disabled by only one of the methods below:

  • External Reset
  • Watchdog System Reset
  • Watchdog Interrupt
  • Brown-out Reset
  • 2-wire Serial Interface address match
  • External level interrupt on INT
  • Pin change interrupt

This implementation demonstrates Arduino sleep and wake up functionality using external interrupts. 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 into a sleep of eight seconds and wake up automatically.

We can also use the power-down mode with an interrupt, where the Arduino will go into sleep but only wakes up when an external or internal interrupt is provided.

Arduino Code for Power-Down Interrupt Mode:

void loop()
{
    // Allow wake up pin to trigger interrupt on low.
    attachInterrupt(0, wakeUp, LOW);
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
    // Disable external pin interrupt on wake up pin.
    detachInterrupt(0);
    // Do something here
}

4. Power-Save Mode

To enter into the power-save mode, we need to write the SM[2,0] pin to ‘011’. This sleep mode is similar to the power-down mode, only with one exception, i.e. if the timer/counter is enabled, it will remain in running state even at the time of sleep. The device can be woken up by using the timer overflow. Arduino Nano sleep mode power consumption in Power-Save mode ranges from 1-2 μA, slightly higher than Power-Down due to the active timer.

If you are not using the time/counter, it is recommended to use Power-down mode instead of Power-Save mode.

5. Standby Mode

The standby mode is identical to the Power-Down mode; the only difference between them is that the external oscillator keeps running in this mode. For enabling this mode, write the SM[2,0] pin to ‘110’.

6. Extended Standby Mode

This mode is similar to the power-save mode, only with one exception that the oscillator is kept running. The device will enter the Extended Standby mode when we write the SM[2,0] pin to ‘111’. The device will take six clock cycles to wake up from the extended standby mode.

Below are the requirements for this project, after connecting the circuit as per the circuit diagram. Upload the sleep mode code into Arduino using Arduino IDE. Arduino will enter the idle sleep mode. Then check the current consumption on the USB ammeter. Otherwise, you can also use a clamp meter for the same.

Components Required

  • Arduino UNO
  • DHT11 Temperature and Humidity Sensor
  • USB Ammeter
  • Breadboard
  • Connecting Wires

To learn more about using DHT11 with Arduino, follow the link. Here we are using a USB Ammeter to measure the voltage consumed by Arduino in sleep mode. We'll use a USB Ammeter to measure actual Arduino sleep mode power consumption in our weather station project.

USB Ammeter Specifications

A USB ammeter is essential for measuring real-world Arduino UNO low power mode performance.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.05ohm resistor in-line with the power pin through which it measures the value of 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 three seconds.

USB Ammeter digital display showing voltage and current measurement for Arduino power consumption testing

Specification:

  • Operating voltage range: 3.5V to 7V
  • Maximum current rating: 3A
  • Compact size, easy to carry
  • No external supply needed

Application:

  • Testing USB devices
  • Checking load levels
  • Debugging battery chargers
  • Factories, electronics products and personal use

Circuit Diagram and Connections

Complete circuit diagram showing Arduino UNO connected to DHT11 sensor and USB ammeter for sleep mode power consumption testing

ComponentArduino PinNotes
DHT11 VCC5VPower supply
DHT11 GNDGNDGround connection
DHT11 DataDigital Pin 2Data communication
USB AmmeterUSB PortBetween Arduino and computer

In the above setup to demonstrate Arduino Deep sleep modes, the Arduino is plugged into the USB ammeter. Then the USB ammeter is plugged into the USB port of the laptop. The data pin of the DHT11 sensor is attached to the D2 pin of the Arduino.

Arduino Sleep Mode Programming - Complete Code

The complete code for the project with a video is given at the end. This Arduino sleep mode programming example demonstrates a complete weather station with optimised power consumption:

Before implementing the Arduino sleep function in your project, install the required libraries:

The code starts by including the library for the DHT11 sensor and the LowPower library. For downloading the Low Power library, follow the link. Then we have defined the Arduino PIN to which the data pin of the DHT11 is connected and created a DHT object. 

#include <dht.h>
#include <LowPower.h>
#define dataPin 2
dht DHT;

This section includes the necessary libraries for Arduino deep sleep mode implementation and DHT11 sensor communication. 

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 the sleep mode. So, we have set the pin as output, and digital write low.

void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN,OUTPUT);
  digitalWrite(LED_BUILTIN,LOW);
}

 

In the void loop function, we are making the built-in LED HIGH and reading the temperature and humidity data from the sensor. Here, DHT.read11(); command is reading the data from the sensor. Once the data is calculated, we can check the values by saving them into any variable. Here, we have taken two float-type variables, ‘t’ and ‘h’. Hence, the temperature and humidity data are printed serially on the serial monitor.

void loop() {
  Serial.println("Get Data From DHT11");
  delay(1000);
  digitalWrite(LED_BUILTIN,HIGH);
  int readData = DHT.read11(dataPin); // DHT11
  float t = DHT.temperature;
  float h = DHT.humidity;
  Serial.print("Temperature = ");
  Serial.print(t);
  Serial.print(" C | ");
  Serial.print("Humidity = ");
  Serial.print(h);
  Serial.println(" % ");
  delay(2000);

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 code below 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 the sleep after 8 seconds and prints “Arduino:- Hey, I just woke up”.

  Serial.println("Arduino:- I am going for a Nap");
  delay(1000);
  digitalWrite(LED_BUILTIN,LOW);
  LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF,
                 SPI_OFF, USART0_OFF, TWI_OFF);
  Serial.println("Arduino:- Hey I just Woke up");
  Serial.println("");
  delay(2000);
}

Technical Summary and GitHub Repository 

This section presents a concise technical overview of the system’s design, implementation framework, and key electronic components, accompanied by the GitHub repository link for source code access and version control.

Code and Schematics Download Zip

Arduino Sleep Mode Power Consumption - Real-World Measurements

Operating ModeCurrent DrawPower (at 5V)Battery Life (2000mAh)
Active (No Sleep)~50 mA250 mW~40 hours
Idle Mode~15 mA75 mW~133 hours
Power-Down Mode~0.1 μA0.0005 mW~2.3 years
Weather Station (40% Duty)~25 mA avg125 mW~80 hours

So by using this code, Arduino will only wake up for 24 seconds in a minute and will remain in sleep mode for the rest of the 36 seconds, which significantly reduces the power consumed by the Arduino weather station. Arduino Nano sleep mode power consumption characteristics are similar to Arduino UNO, as both use the ATmega328P microcontroller. For battery-powered projects, Arduino Pro Mini offers the best Arduino low power sleep performance, consuming as little as 0.036 μA in Power-Down mode when the power LED is removed.

Arduino weather station running continuously without sleep mode showing higher power consumption on USB ammeter display

 

Arduino weather station with sleep mode enabled showing reduced power consumption measurements on USB ammeter

Our Arduino weather station shows noteworthy power-saving gains by implementing the Arduino sleep function wisely:

  • No Sleep > ~50 mA continuous draw = 40 hours with a 2000mAh battery
  • Idle Sleep (40% duty cycle) > ~25 mA average = 80 hours of battery life
  • Performance Improvement = 100% battery life improvement, doing little more than adding a few lines of code
     

If you used the Arduino deep sleep mode with Power-Down instead of Idle, you could save even more, and potentially run utilities for weeks or months, depending on your sampling rate!

Choosing the Right Sleep Mode

Application TypeRecommended ModeReason
Weather Station (periodic readings)Idle or Power-DownBalance between power savings and quick wake
Motion DetectorPower-Down with interruptMaximum savings with instant wake on trigger
Data Logger with RTCPower-SaveMaintains Timer2 for timekeeping
Precision ADC MeasurementsADC Noise ReductionReduces electrical noise during conversion
Communication GatewayIdleKeeps USART active for incoming data

Frequently Asked Questions on Arduino Deep Sleep Mode

⇥ 1. Is Arduino able to wake from sleep mode involuntarily? 
Yes, Arduino can wake up involuntarily with the use of: watchdog timer (periodic wake-up), external interrupts (pin change or level trigger), timer overflow, or hardware reset. Automatic wake after 8 seconds of use, LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF) or SLEEP_FOREVER and wake with interrupt.

⇥ 2. Which Arduino sleep mode saves the most power? 
The feature used to save the most power is Power-Down mode, which draws only 0.1 μA because all clocks are disabled except the watchdog timer. For applications that require timers, the Power-Save mode will save interestingly close to the same amount of power at 1-2 μA while Timer2 is still active for real-time clock applications.

⇥ 3. Does the Arduino Nano consume less power than the UNO? 
When comparing the UNO to the nano (in active mode), the Nano consumes slightly less in active mode due to the size and compact design; ~40 mA versus ~50 mA. Any action will use the same microcontroller, the ATmega328P chip, which includes the same sleep modes. The Arduino Pro Mini has the least consumption if you remove the power LED.

⇥ 4. Can I use serial communication during Arduino sleep mode?
Serial communication via USART is only active during Idle mode. The Power-Down and Power-Save modes turn off the USART for maximum power saving. If serial communication is needed during low-power operation, use the Idle mode or reinitialise serial communication after wake-up from deeper modes of sleep.

⇥ 5. What is the method to wake up Arduino from deep sleep using a button? 
You need to wire a button to Arduino pin 2 or 3 (INT0/INT1) with a pull-up resistor. If you want the button to wake up the Arduino as you set up before sleep, you would use attachInterrupt(0, wakeUp, LOW) for ECU sleep mode. The interrupt function is executed immediately, which means that when you leave sleep mode, the Arduino will run normally.

⇥ 6. What is the difference between Arduino sleep and delay? 
If you use the Arduino's delay() during long wait times, the CPU is still powered ON and consuming full power-like 50 mA. When you put Arduino in sleep mode, it actively reduces current consumption by powering down the CPU and peripherals as low as 0.1μA. For battery-powered projects, sleep mode should always be used in times of long wait, instead of delay.

⇥ 7. Can sensors drain the battery when the Arduino is sleeping? 
Yes, when the Arduino is in sleep mode, all the sensors that can be discovered are powered and consuming. For the most efficient battery life, your simple sensors should be powered down if you are entering Arduino sleep mode as well. You can achieve this with a transistor or a MOSFET, turning your sensors ON just for measurements, but sleep and turning on sensors provides the best overall system efficiency.

Conclusion

Using Arduino sleep modes is an important consideration for battery-powered projects and can help reduce power consumption by 99.9%. Knowing that Arduino sleep mode programming, which mode is best for your project, can increase battery life from hours to months and in some cases, years.

The weather station demonstrates a practical example of Arduino deep sleep mode that increases runtime to another level with little code changes. Whether you are building IoT sensors, remote monitors, or data loggers, knowing how to use Arduino low power sleep modes is going to take your autonomous long-term projects to a whole new level. 

Get started using the different modes of sleep, measure the power consumption of your Arduino sleep mode, and make your own projects better.

Therefore, if we use the Arduino in sleep mode, we can approximately double the device's runtime.

Innovative Low-Power Solutions for IoT Using LoRa and ESP32 Power

This project and article explore power-saving techniques in microcontrollers using LoRa communication and ESP32 applications, highlighting methods to minimise energy usage. It demonstrates practical implementations of deep sleep and efficient data transmission for low-power IoT systems.

ESP32 Active Mode and Deep Sleep Mode Power Consumption Comparison

ESP32 Active Mode and Deep Sleep Mode Power Consumption Comparison

In this project, we will check the current consumption of widely popular Wi-Fi and Bluetooth enabled microcontroller unit ESP32 in normal working mode and deep sleep mode.

LoRa with Raspberry Pi – Peer to Peer Communication with Arduino

LoRa with Raspberry Pi – Peer to Peer Communication with Arduino

So, in this tutorial we will learn how to use a LoRa module SX1278 with Raspberry pi to communicate with another SX1278 connected to a microcontroller like Arduino.

 Minimizing Power Consumption in Microcontrollers

Minimizing Power Consumption in Microcontrollers

In today’s article, we will be exploring some of these techniques and how they can be used to minimize power consumption in microcontrollers.

Complete Project Code

Arduino Weather Station with Sleep Mode
#include <dht.h>
#include <LowPower.h>
#define dataPin 2
dht DHT; 
void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN,OUTPUT);
  digitalWrite(LED_BUILTIN,LOW);
}
void loop() {
  Serial.println("Get Data From DHT11");
  delay(1000);
  digitalWrite(LED_BUILTIN,HIGH);
  int readData = DHT.read11(dataPin); // DHT11
  float t = DHT.temperature; 
  float h = DHT.humidity; 
 
  Serial.print("Temperature = ");
  Serial.print(t);
  Serial.print(" C | ");
  Serial.print("Humidity = ");
  Serial.print(h);
  Serial.println(" % ");
  delay(2000);
  Serial.println("Arduino:- I am going for a Nap");
  delay(200);
  digitalWrite(LED_BUILTIN,LOW);
  LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, 
                 SPI_OFF, USART0_OFF, TWI_OFF);
  Serial.println("Arduino:- Hey I just Woke up");
  Serial.println("");
  delay(2000);
}
 
Arduino Weather Station without Sleep Mode
#include <dht.h>
#define dataPin 2
dht DHT; 
void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN,OUTPUT);
  digitalWrite(LED_BUILTIN,LOW);
}
void loop() {
  digitalWrite(LED_BUILTIN,HIGH);
  int readData = DHT.read11(dataPin); // DHT11
  float t = DHT.temperature; 
  float h = DHT.humidity; 
 
  Serial.print("Temperature = ");
  Serial.print(t);
  Serial.print(" C | ");
  Serial.print("Humidity = ");
  Serial.print(h);
  Serial.println(" % ");
  delay(2000);
}
Video

Have any question related to this Article?

Add New Comment

Login to Comment Sign in with Google Log in with Facebook Sign in with GitHub