Waking Up Your Arduino: Sleep Mode And Power Saving Tips

how to wake up arduino from sleep

Arduino is a popular microcontroller used by makers and professionals alike for its versatility and ease of use. One of its standout features is the ability to put it into sleep mode, which is especially beneficial for battery-powered projects. Arduino's microcontroller, ATmega328P, offers six sleep modes, five of which can be accessed with the avr/sleep.h library. This allows users to significantly reduce power consumption, making their projects more responsive and battery-friendly. The various wake-up methods available for each low-power mode provide users with the flexibility to design efficient and user-friendly applications. This article will explore the different ways to wake up an Arduino from sleep mode, including the use of interrupts, timers, and external influences, providing a comprehensive guide to harnessing the power of Arduino's sleep modes.

How to Wake Up Arduino from Sleep

Characteristics Values
Number of Sleep Modes 6
Power Consumption 14 mA (without sleep mode), 7 mA (with sleep mode)
Current Consumption with Low Power Mode 7 mA
Current Consumption of MCU with Arduino Uno 30-40 mA (awake), 19 mA (asleep)
Current Consumption of MCU with Arduino Pro Mini 25 mA (awake), 0.57 mA (asleep)
Wake-Up Methods Timer function, External wake-up event
Wake-Up Sources Interrupt, Watchdog timer
Low-Power Library LowPower.h

shunsleep

Using an interrupt

To wake up an Arduino from sleep mode, you can use an external interrupt. This involves setting up an external circuit and configuring the Arduino to respond to a specific interrupt signal.

Firstly, you need to determine the source of the interrupt. This could be a physical button, a sensor, or another external device that can trigger an interrupt. For example, you might use an IR sensor as an interrupt to wake up the Arduino from deep sleep power mode.

Next, you need to configure the Arduino board and the external circuit accordingly. This includes setting the correct pin modes, enabling the serial port, and attaching the interrupt service routine to the desired pin. For instance, you can use pin 2 (INT0) as an input for the interrupt.

It is important to note that the timing of the interrupt is crucial. If the Arduino receives an interrupt command before entering sleep mode, it may not receive any subsequent interrupt commands to wake up. Therefore, the interrupt should be triggered after the Arduino has entered sleep mode.

Additionally, you can use the "LowPower" library to configure the wake-up options and quickly put the Arduino to sleep. This library provides functions to enable sleep mode and attach interrupts for wake-up events.

By following these steps and properly configuring the external interrupt, you can effectively wake up an Arduino from sleep mode and utilize the benefits of power-saving features in your projects.

shunsleep

Low-power mode

The ATmega328P microcontroller, used on boards like the Arduino Uno, is quite power-hungry, drawing a minimum current of 15mA. To extend the battery life of your Arduino, you can put it in a low-power mode.

One way to do this is by reducing the number of integrated circuits (ICs) needed, as every IC requires power to function. For instance, the SparkFun RedBoard and Arduino Uno both have a USB bridge IC that can be replaced with a 5V Pro Mini, reducing the supply current from 15mA to 4mA.

Another method is to lower the voltage supplied to the Arduino. Reducing the voltage from 5V to 3.3V can decrease the current from ~4mA to ~1mA. However, lowering the voltage too much without reducing the clock speed can cause the microcontroller to behave erratically. Clock speed does not affect sleep current because the clock is disabled during power-down.

You can also use the LowPower.h library to set the Arduino in Low Power Idle mode and disable certain features like ADC, Timers, SPI, UART, and TWI. Here's an example of the code you can use:

C++

#include

Void setup() {

// Any setup code here

}

Void loop() {

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

}

This code will put the Arduino Uno (ATmega328P) into a low-power idle state for 8 seconds, during which the specified features will be disabled. You can adjust the duration and the features you want to disable based on your requirements.

shunsleep

Watchdog timer

The Watchdog Timer (WDT) is a feature on Arduino boards that can be used to wake the microcontroller from sleep. It is one of the standard internal timers of an Arduino, but it is unique in that it has its own separate internal 128kHz oscillator, allowing it to function in the lowest power mode: SLEEP_MODE_PWR_DOWN. This makes it ideal for applications where maximum sleep time and/or minimum sleep power consumption are required.

The WDT can be set to a specific timeout period, such as 8 seconds, after which it will trigger an interrupt and wake up the Arduino. This interrupt can be used to execute a specific task or to put the Arduino back to sleep until a certain condition is met. For example, the Arduino could be programmed to wake up every 8 seconds to read sensor data and then go back to sleep until the next interval.

It's important to note that the WDT and sleep mode are pretty much mutually exclusive. If the Arduino is set to sleep while the WDT is running, it will reset after the timeout period. To prevent this, the WDT can be disabled right before sleeping and enabled again after waking up. Alternatively, the WDT can be set to trigger an interrupt, which will wake up the Arduino without resetting it.

The WDT can also be combined with other wake-up sources, such as external interrupts or real-time clocks, to create more complex wake-up conditions. For example, an Arduino could be programmed to wake up periodically using the WDT and also wake up on-demand when a button is pressed or a certain event occurs.

In summary, the Watchdog Timer is a versatile tool for managing the sleep and wake-up behaviour of Arduino boards. By utilizing the WDT, developers can create power-efficient applications that wake up periodically, on-demand, or in response to specific events.

shunsleep

Timer function

There are several ways to wake up an Arduino from sleep mode, including the use of a timer function. This is a valuable way to plan the wake-up event in your project.

To use the timer function, you must first put the Arduino into sleep mode. This can be done by enabling the sleep bit in the Sleep Mode Control Register (SMCR.SE). Then, the sleep mode select bits are used to select the desired sleep mode. The available modes include Idle, ADC noise reduction, Power-Down, Power-Save, Standby, and External Standby. Once the Arduino is in sleep mode, you can use the timer function to wake it up at a predefined time.

In the Power-Save mode, the timer/counter is enabled and will remain in a running state even during sleep. The device can be woken up by using a timer overflow. If you are not using the timer/counter, it is recommended to use Power-Down mode instead. In this mode, all generated clocks are stopped, except for the asynchronous modules. The Timer/Counter2 will continue running, and the Arduino can be woken up by an internal interrupt, such as a timer overflow.

The ESP32, for example, can be put into deep sleep mode using the esp_deep_sleep_start() function. You can specify the sleep time in microseconds, and the ESP32 will wake up after the predefined amount of time. This feature is useful for projects that require time stamping or daily tasks while maintaining low power consumption.

Overall, the timer function provides a synchronous wake-up event, allowing you to plan when the Arduino wakes up before putting it to sleep. This makes it a valuable tool for creating power-efficient and responsive projects.

shunsleep

External influence

Arduino's microcontroller, ATmega328P, has six sleep modes, five of which are available with the avr/sleep.h library. The different modes have different wake-up mechanisms and power consumption.

One way to wake up an Arduino from sleep is through an external wake-up event. This is an asynchronous event, meaning that the timing of the event is unpredictable. When the event occurs, you can program the Arduino to perform a specific task and then return to sleep. To do this, you can use an external RTC (Real-Time Clock) module. Many RTC chips have an "Alarm" function that can be used to wake up the Arduino. Set the alarm and wire the pin from the RTC to one of the interrupt pins (INT0 or INT1) on the Arduino. Then, put the ATMega into the desired sleep mode. When the RTC reaches the set time, it sends a signal to the interrupt pin, waking up the Arduino, which then executes the predefined tasks.

Another method is to use the "LowPower.h" library and set up an external pin as the wake-up pin. In the code, you can define a function to be executed when the wake-up pin is triggered. This can be done by using the attachInterrupt() function. By configuring the wake-up pin as an input and enabling the interrupt on a low signal, you can wake up the Arduino when the specified condition is met.

Additionally, you can use the internal watchdog timer to wake up the Arduino periodically. This method allows you to wake the Arduino, read the RTC, and then perform tasks or return to sleep. However, it is important to note that some sources mention that the watchdog timer may not be accurate.

Sleep Death: Can You Wake Up After?

You may want to see also

Frequently asked questions

You can use the sleep modes to put the Arduino into low power modes, where only essential MCU blocks will be active. There are six different sleep modes, and you can use the "LowPower" library to configure the wake-up options accordingly.

There are several ways to wake up an Arduino, including using an external influence, such as a nudge, or an internal timer interrupt. You can also use the watchdog timer, although some research suggests it is inaccurate.

Arduino's sleep modes can help to save on current consumption, allowing for smaller batteries or longer battery life. This can also make your product smaller and save on costs.

Written by
Reviewed by
Share this post
Print
Did this article help you?

Leave a comment