Make the Arduino sleep and then wake up

ArduinoSoftware & CodingHardware

In this article, we will, as the title suggests, make the Arduino sleep, and wake it up using an interrupt. Arduino’s microcontroller, ATmega328P has 6 sleep modes, of which 5 are available with the avr/sleep.h library. Each mode has different wake-up modes and different power consumption.

Arduino’s microcontroller, ATmega328P has 6 sleep modes, of which 5 are available with the avr/sleep.h library.

  • Idle mode

  • ADC Noise Reduction

  • Power-down

  • Power-save

  • Standby

  • Extended Standby

Each mode has different wake-up modes and different power consumption.

The Idle mode is easiest to wake up from and the Standby and Power down mode is the most difficult to wake up from (you can only wake up the module from the Standby mode using external interrupts or watchdog timer). The Power down mode is also the most power efficient sleep mode.

The TWI Address match refers to I2C or Wire Address match. The microcontroller can wake up through this way only when it is the I2C slave, and a master sends address corresponding to this microcontroller to wake it up). You are encouraged to go through the datasheet of ATmega328P to read up more about the sleep modes.

Now, you can directly work with the avr/sleep.h library and explore the sleep modes within Arduino. An example is given here.

However, as always happens, someone has taken the effort to create a library. The library is called Low-Power. It can be found on GitHub here.

It is not available in Library Manager of Arduino IDE. The way to install such libraries has been explained here.

Once you have this library installed, go to: File → Examples → Low-Power → Examples → idleWakePeriodic

As you can see, the code is as simple as it gets. You include the "LowPower.h" library, and just have one line in loop (no setup required) −

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

As you can see, we are setting the Arduino in the Low Power Idle mode, disabling ADC, Timers, SPI, UART and TWI, and waking it up using the watchdog timer.

The above statement is for Arduino Uno (ATmega328P). The corresponding statements for other microcontrollers are also provided in the comments in the code.

You can check that the Arduino is actually in sleep by connecting a current sensor (ammeter) in series with the Arduino supply, and observing the drop in current while the Arduino is asleep.

raja
Updated on 31-Jul-2021 13:57:47

Advertisements