- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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.
- Related Articles
- Non-24-Hour Sleep-Wake Disorder
- Study of Consciousness Sleep-Wake Schedules
- Deep sleep in Arduino
- What are the things I have to do every morning when I wake up?
- All About Sleep Cycles and the Stages of Sleep
- How to make the program sleep for x milliseconds in C++?
- Can Icing Your Chest Ease a Panic Attack and Make You Sleep Better?
- How to make a C# program sleep for x milliseconds?
- What colours make up white light?
- Difference Between Sleep and Hibernation
- The Wonder Called Sleep
- What is the scientific name of particles which make up matter?
- Difference between Wait and Sleep in Java
- Insufficient Sleep Syndrome