- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Make the Arduino sleep and then wake up
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.
ADC Noise Reduction
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.
- Deep sleep in Arduino
- What are the things I have to do every morning when I wake up?
- How to make the program sleep for x milliseconds in C++?
- How to make a C# program sleep for x milliseconds?
- Difference between Wait and Sleep in Java
- Join, Sleep and Abort methods in C# Threading
- Differences between wait() and sleep() method in Java?
- Difference Between sleep() and wait() Method in Java
- sleep() function in PHP
- Add or subtract space between the letters that make up a word with CSS
- Bitwise AND and OR in Arduino
- Logical AND and OR in Arduino
- How to pick up and hung up calls in android?