{"id":10152,"date":"2020-12-07T22:36:18","date_gmt":"2020-12-07T22:36:18","guid":{"rendered":"https:\/\/wolles-elektronikkiste.de\/sleep-modes-and-power-management"},"modified":"2025-09-17T19:23:37","modified_gmt":"2025-09-17T19:23:37","slug":"sleep-modes-and-power-management","status":"publish","type":"post","link":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management","title":{"rendered":"Sleep Modes and Power Management"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">About this Post<\/h2>\n\n<p>In the <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/using-the-atmega328p-standalone\">last post<\/a> I showed you how to operate the ATmega328P standalone, i.e. outside its Arduino UNO periphery. This saves costs, space and power. If you run a project with such a &#8220;naked&#8221; Atmega328P, an average battery of, say, 2000 mAh is still empty after a few days, even if you don&#8217;t have anything else attached to it. To reduce power consumption, the AVR microcontrollers have various sleep modes. For example, if you build a weather station where a microcontroller on the sensor side only performs one measurement per minute, you can send it to sleep the rest of the time.&nbsp;<\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Stromverbrauch_Boards_MCUs_bare_minimum_5V.png\"><img decoding=\"async\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/12\/Power_consumption_Boards-1024x257.png\" alt=\"Power consumption of some boards and MCUs (bare minimum sketch \/ 5V)\" class=\"wp-image-5389\"\/><\/a><figcaption class=\"wp-element-caption\">Table 1: Power consumption of some boards and MCUs (bare minimum sketch \/ 5V)<\/figcaption><\/figure>\n\n<p>In this article, I am concentrating on the ATmega328P, as it is most common to those who work with the Arduino UNO. For many projects, however, it is oversized. That is why, at the end of the article, I will briefly handle the sleep modes of the less power-hungry ATtinys 85\/45\/25 using the example of the ATtiny85. The ATtinys 85\/45\/25 can also be programmed via the Arduino IDE. I described that <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/programming-attiny85-84-45-44-25-24\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.&nbsp;<\/p>\n\n<h3 class=\"wp-block-heading\">Content<\/h3>\n\n<ul>\n<li><a href=\"#Anker1\">The sleep modes of the ATmega328P<\/a><\/li>\n<li><a href=\"#Anker2\">Activate sleep modes<\/a> (with watchdog as alarm clock)\n<ul>\n<li>directly via the sleep mode control register&nbsp;<\/li>\n<li>Using sleep.h functions<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#Anker3\">Benefits of the sleep modes<\/a> &#8211; a few measurements<\/li>\n<li><a href=\"#Anker4\">Further energy-saving potentials<\/a>\n<ul>\n<li>Save energy with the Power Reduction Register<\/li>\n<li>Switching off the brown-out detector<\/li>\n<li>Lowering the clock frequency&nbsp;<\/li>\n<li>Lowering the operating voltage<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#Anker5\">Other wake-up methods<\/a>\n<ul>\n<li>External interrupt<\/li>\n<li>timer<\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#Anker6\">Sleep Modes of other AVR microcontrollers<\/a><\/li>\n<\/ul>\n\n<h3 class=\"wp-block-heading\">First of all&#8230;.<\/h3>\n\n<h4 class=\"wp-block-heading\">Uploading the Sketches<\/h4>\n\n<p>I will not comment in the article, or very little, on <em>how<\/em> the sketches are uploaded on the ATmega328P or the ATtiny85. I have described this in detail in the above-mentioned articles. It would be beyond the scope to repeat this in detail.&nbsp;<\/p>\n\n<h4 class=\"wp-block-heading\">Pinout of the ATmega328P<\/h4>\n\n<p>For orientation, the pinout scheme of the ATmega328P:<a id=\"Anker1\"><\/a><\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/12\/Pinout-Atmega-328P-vs-Arduino-UNO.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"495\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/12\/Pinout-Atmega-328P-vs-Arduino-UNO-1024x495.png\" alt=\"\" class=\"wp-image-4356\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/12\/Pinout-Atmega-328P-vs-Arduino-UNO-1024x495.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/12\/Pinout-Atmega-328P-vs-Arduino-UNO-300x145.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/12\/Pinout-Atmega-328P-vs-Arduino-UNO-768x371.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/12\/Pinout-Atmega-328P-vs-Arduino-UNO-1320x637.png 1320w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/12\/Pinout-Atmega-328P-vs-Arduino-UNO.png 1495w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Pinout of the ATmega328P<\/figcaption><\/figure>\n\n<h2 class=\"wp-block-heading\">The sleep modes of the ATmega328P<\/h2>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\">\n<figure><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/ATMEGA328P.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5225\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/ATMEGA328P-1024x345.jpg\" alt=\"\" width=\"512\" height=\"173\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/ATMEGA328P-1024x345.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/ATMEGA328P-300x101.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/ATMEGA328P-768x258.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/ATMEGA328P-1536x517.jpg 1536w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/ATMEGA328P-1320x444.jpg 1320w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/ATMEGA328P.jpg 1783w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n<figcaption>I explain the sleep modes using the ATmega328P as example<\/figcaption>\n<\/figure>\n<\/div>\n\n<p>The Atmega328P offers six different sleep modes. Depending on the mode, more or less of its functions are sent to sleep. The remaining power consumption is correspondingly different.<\/p>\n<p>If you send the ATmega328P to sleep, you must of course be able to wake it up again. Each mode has its selection of possible &#8220;wake-up calls&#8221;. In addition, it should be noted that the ATmega328P takes different times to wake up depending on the &#8220;sleep depth&#8221;.&nbsp;<\/p>\n<p>The following table provides an overview of which sleep modes are still activated and how to wake up the ATmega328P again. The good news is that the table is valid for a whole series of ATmegas.&nbsp;<\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_48_88_168_328.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"569\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_48_88_168_328-1024x569.png\" alt=\"\" class=\"wp-image-5376\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_48_88_168_328-1024x569.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_48_88_168_328-300x167.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_48_88_168_328-768x427.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_48_88_168_328-1320x733.png 1320w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_48_88_168_328.png 1379w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Table 2: Sleep modes of ATmega328P (and 48A\/48PA\/88A\/88PA\/168A\/168PA\/328)<\/figcaption><\/figure>\n\n<p>Here is a short description of Sleep Modes. More information can be found in the <a href=\"https:\/\/ww1.microchip.com\/downloads\/en\/DeviceDoc\/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">data sheet<\/a>.<\/p>\n<ul>\n<li><strong>Idle<\/strong>: light sleep. You may need to switch off other components directly via PRR (coming later) so that the ATmega328P does not wake up unintentionally.<\/li>\n<li><strong>ADC Noise Reduction<\/strong>: Even in this mode, many functions remain active. The ADC Noise Reduction Mode, as the name suggests, is also used to reduce noise in analog digital conversions. This allows a higher resolution to be achieved.&nbsp;<\/li>\n<li><strong>Power-down<\/strong>: the most energy-saving deep sleep. Only external interrupts, TWI (Two Wire Interface -&gt;  I2C) or the watchdog interrupt can wake up the ATmega328P.&nbsp;<\/li>\n<li><strong>Power-save<\/strong>: is similar to the power-down mode, but the Timer2 is still awake and could be operated via an external clock.<\/li>\n<li><strong>Stand-by<\/strong>: the system oscillator is still running here. This mode is typically chosen when quick waking is necessary. Only six cycles are needed. It is important to know that an external quartz oscillator needs time in the millisecond range to provide a stable system clock.&nbsp;<\/li>\n<li><strong>Extended Standby<\/strong>: Compared to the stand-by mode, the Timer2 is active. <a id=\"Anker2\"><\/a><\/li>\n<\/ul>\n\n<h2 class=\"wp-block-heading\">Activating sleep modes<\/h2>\n\n<h3 class=\"wp-block-heading\">Control sleep modes via the SMCR<\/h3>\n\n<p>The sleep modes are controlled by corresponding entries in the Sleep Mode Control Register SMCR. The Bits SM0&#8230; SM2 set the mode, the SE bit (sleep enable) starts sleep mode.&nbsp;<\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/SMCR.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"92\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/SMCR-1024x92.png\" alt=\"\" class=\"wp-image-5380\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/SMCR-1024x92.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/SMCR-300x27.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/SMCR-768x69.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/SMCR.png 1182w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The Sleep Mode Control Register SMCR<\/figcaption><\/figure>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Mode_Select.png\"><img loading=\"lazy\" decoding=\"async\" width=\"969\" height=\"427\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Mode_Select.png\" alt=\"Setting sleep modes via the SMCR\" class=\"wp-image-5381\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Mode_Select.png 969w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Mode_Select-300x132.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Mode_Select-768x338.png 768w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/><\/a><figcaption class=\"wp-element-caption\">Table 3: Setting sleep modes via the SMCR<\/figcaption><\/figure>\n\n<h3 class=\"wp-block-heading\">Sleep modes using sleep.h functions<\/h3>\n\n<h4 class=\"wp-block-heading\">The short-notation<\/h4>\n\n<p>Not everyone likes to write into registers with instructions like <code>SMCR |= (1&lt;&lt;SM0);<\/code>. If you include the header file sleep.h, you can use less cryptic functions. How to do this, I show in the following sketch.<\/p>\n<p>To wake up, I use the watchdog timer, which I set to 8 seconds. Details about the watchdog timer can be found <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/watchdog-timer\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. I&#8217;ll discuss other wake-up methods later.<\/p>\n<p>The sketch does the following:<\/p>\n<ul>\n<li>first wdt.h (for the watchdog timer) and sleep.h are included<\/li>\n<li>PD7 is set to OUTPUT <\/li>\n<li>the watchdog is set up<\/li>\n<li>The LED to PD7 starts for 3.5 seconds\n<ul>\n<li>this serves only as an &#8220;I-am-awake-sign&#8221;<\/li>\n<li>I chose 3.5 seconds to allow my sluggish multimeter to measure the power consumption reliably<\/li>\n<\/ul>\n<\/li>\n<li>after another 3.5 seconds, the watchdog timer is reset<\/li>\n<li>the sleep mode is selected with <code>set_sleep_mode(...)<\/code>, in this case power-down<\/li>\n<li><code>sleep_mode()<\/code> starts sleep mode<\/li>\n<li>after 8 seconds, the watchdog wakes up the Atmega328P; the interrupt service routine (ISR) is empty, but it still needs to be included in the sketch<\/li>\n<li>The sketch resumes its work directly after <code>sleep_mode()<\/code><\/li>\n<\/ul>\n<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-group=\"sleep_modes_wd_wakeup.ino\" data-enlighter-title=\"sleep_modes_wd_wakeup.ino\">#include &lt;avr\/wdt.h&gt;\n#include &lt;avr\/sleep.h&gt;\n\nvoid setup(){\n  DDRD = (1&lt;&lt;PD7); \/\/ equals (roughly) pinMode(7, OUTPUT);\n  watchdogSetup();\n}\n\nvoid loop(){\n  PORTD |= (1&lt;&lt;PD7);  \/\/ equals (roughly) digitalWrite(7, HIGH);\n  delay(3500);\n  PORTD &amp;= ~(1&lt;&lt;PD7); \/\/ equals (roughly) digitalWrite(7, LOW);\n  delay(3500);\n  wdt_reset();\n\n  set_sleep_mode(SLEEP_MODE_PWR_DOWN); \/\/ choose power down mode\n\/\/  set_sleep_mode(SLEEP_MODE_PWR_SAVE); \/\/ choose power save mode\n\/\/  set_sleep_mode(SLEEP_MODE_STANDBY); \/\/ choose external standby power mode\n\/\/  set_sleep_mode(SLEEP_MODE_EXT_STANDBY); \/\/ choose external standby power mode\n\/\/  set_sleep_mode(SLEEP_MODE_IDLE); \/\/ did not work like this!\n\/\/  set_sleep_mode(SLEEP_MODE_ADC); \/\/ choose ADC noise reduction mode\n\/\/  sleep_bod_disable();  \/\/ optional brown-out detection switch off  \n\n  sleep_mode(); \/\/ sleep now!\n}\n\nvoid watchdogSetup(void){\n  cli();\n  wdt_reset();\n  WDTCSR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);\n  WDTCSR = (1&lt;&lt;WDIE) | (0&lt;&lt;WDE) | (1&lt;&lt;WDP3) | (1&lt;&lt;WDP0);  \/\/ 8s \/ interrupt, no system reset\n  sei();\n}\n\nISR(WDT_vect){\/\/put in additional code here\n}<\/pre>\n<p>\u00a0<\/p>\n<p>\n\n<p>For other Sleep Modes, simply uncomment the corresponding lines. Try idle mode. You will see that it is not working and the LED flashes with at a frequency of 3.5 s. Idle is a kind of light sleep and from such you wake up easily. We&#8217;ll come to see how you can prevent that.&nbsp;<\/p>\n\n<p>And now try to swap lines 10 and 12. The LED now lights up while the ATmega328P is asleep, as all register contents are preserved during the sleep phase, including the port registers.&nbsp;&nbsp;<\/p>\n\n<h4 class=\"wp-block-heading\">The more detailed spelling<\/h4>\n\n<p>The function <code>sleep_mode();<\/code> corresponds to the sequence of commands:<\/p>\n<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">sleep_enable(); \nsleep_cpu(); \nsleep_disable();<\/pre>\n<p>\n\n<p>By the way, this is defined in sleep.h. You can find the file here: &#8220;Program Files (x86)\\Arduino\\hardware\\tools\\avr\\avr\\include\\avr\\sleep.h&#8221;. Don&#8217;t be sorry to look in. <\/p>\n<p>It is safer if you use the more detailed command sequence and switch off all interrupts before <code>sleep_enable()<\/code> using <code>cli()<\/code>. Before <code>sleep_cpu()<\/code> you activate the interrupts again with <code>sei()<\/code>. Without the intermittent shutdown, interrupts can &#8220;collide&#8221; with unpredictable consequences. This is particularly important when further commands are inserted between <code>sleep_enable()<\/code> and <code>sleep_cpu()<\/code>, and that is exactly what we will do soon. <\/p>\n<p>But for now, the sketch looks like this:<\/p>\n<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-group=\"sleep_modes_wd_wakeup_with_int_disable.ino\" data-enlighter-title=\"sleep_modes_wd_wakeup_with_int_disable.ino\">#include &lt;avr\/wdt.h&gt;\n#include &lt;avr\/sleep.h&gt;\n\nvoid setup(){\n  DDRD = (1&lt;&lt;PD7); \/\/ equals (roughly) pinMode(7, OUTPUT);\n  watchdogSetup();\n}\n\nvoid loop(){\n  PORTD |= (1&lt;&lt;PD7);  \/\/ equals (roughly) digitalWrite(7, HIGH);\n  delay(3500);\n  PORTD &amp;= ~(1&lt;&lt;PD7); \/\/ equals (roughly) digitalWrite(7, LOW);\n  delay(3500);\n  wdt_reset();\n\n    set_sleep_mode(SLEEP_MODE_PWR_DOWN); \/\/ choose power down mode\n\/\/  set_sleep_mode(SLEEP_MODE_PWR_SAVE); \/\/ choose power save mode\n\/\/  set_sleep_mode(SLEEP_MODE_STANDBY); \/\/ choose external standby power mode\n\/\/  set_sleep_mode(SLEEP_MODE_EXT_STANDBY); \/\/ choose external standby power mode\n\/\/  set_sleep_mode(SLEEP_MODE_IDLE); \/\/ did not work!\n\/\/  set_sleep_mode(SLEEP_MODE_ADC); \/\/ choose ADC noise reduction mode\n\n  cli(); \/\/ deactivate interrupts\n  sleep_enable(); \/\/ sets the SE (sleep enable) bit\n  sei(); \/\/ \n  sleep_cpu(); \/\/ sleep now!!\n  sleep_disable(); \/\/ deletes the SE bit\n}\n\nvoid watchdogSetup(void){\n  cli();\n  wdt_reset();\n  WDTCSR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);\n  WDTCSR = (1&lt;&lt;WDIE) | (0&lt;&lt;WDE) | (1&lt;&lt;WDP3) | (1&lt;&lt;WDP0);  \/\/ 8s \/ interrupt, no system reset\n  sei();\n}\n\nISR(WDT_vect){\/\/put in additional code here\n}<\/pre>\n<p>\u00a0<\/p>\n<p>\n\n<p>&#8220;Register fans&#8221; can replace lines 23 to 27 by:<\/p>\n<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">SMCR |= (1&lt;&lt;SM1); \/\/ power down sleep mode\ncli();\nSMCR |= (1&lt;&lt;SE); \/\/ sleep_enable();\nsei();\nasm(\"SLEEP\"); \/\/ sleep_cpu();\nSMCR &amp;= ~(1&lt;&lt;SE); \/\/ sleep_disable();<\/pre>\n<p>\n\n<p>Less easy to read but nice in its brevity.<a id=\"Anker3\"><\/a>&nbsp;<\/p>\n\n<h2 class=\"wp-block-heading\">Benefits of the sleep modes &#8211; some measurements<\/h2>\n\n<p>I uploaded the last sketch on the Arduino UNO, the standalone ATmega328P and the ATtiny85, ran it using different clocks and measured the power consumption in the sleep phase. In some cases I uploaded the sketch using the Arduino IDE (as described in the last post), in the other cases I used Atmel (Microchip) Studio.<\/p>\n<p><strong>These values only apply to the conditions I have selected!<\/strong> Further measures (e.g. switching off the ADC) can achieve even more. <\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Stromverbrauch_Sleep_Modes.png\"><img decoding=\"async\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/12\/Power_consumption_Sleep_Modes-1024x446.png\" alt=\"Power consumption in different sleep modes \" class=\"wp-image-5398\"\/><\/a><figcaption class=\"wp-element-caption\">Table 4: Power consumption in various sleep modes, using the Arduino UNO, ATmega328P and ATtiny85<\/figcaption><\/figure>\n\n<p>Some results were as expected, others not:<\/p>\n<ul>\n<li>The Arduino UNO uses a lot of power because of its peripherals on the board (e.g. the power LED).<\/li>\n<li>The idle mode consumes the most electricity in standalone operation.<\/li>\n<li>Power-down sleep mode consumes the least power.<\/li>\n<li>It makes an amazing difference for power-down mode whether the sketch is uploaded via Arduino IDE or Atmel Studio. This is because the Arduino board package switches on certain functions by default, which must be explicitly switched off for energy-efficient sleep. We&#8217;ll get to that.  <\/li>\n<li>In power-down mode, there is no difference at different clock frequencies since the system clock is switched off.<\/li>\n<li>Using an ATtiny85 saves a lot of power. <a id=\"Anker4\"><\/a><\/li>\n<\/ul>\n\n<h2 class=\"wp-block-heading\">Further energy-saving potentials<\/h2>\n\n<h3 class=\"wp-block-heading\">Saving energy with the Power Reduction Register<\/h3>\n\n<p>Depending on the sleep mode and the desired wake-up method, you can reduce power consumption even further by manually shutting off some components. This is controlled by the Power Reduction Register PRR:<\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/PRR.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"81\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/PRR-1024x81.png\" alt=\"\" class=\"wp-image-5405\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/PRR-1024x81.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/PRR-300x24.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/PRR-768x61.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/PRR.png 1167w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The Power Reduction Register PRR<\/figcaption><\/figure>\n\n<p>Bits that are set switch off the corresponding component:<\/p>\n<ul>\n<li><strong>PRTWI<\/strong>: switches off the Two Wire Interface (I2C). After waking up, it must be reinitialized.<\/li>\n<li><strong>PRTIM2:<\/strong> turns off Timer2 in synchronous mode.<\/li>\n<li><strong>PRTIM0\/PRTIM1<\/strong>: these bits control Timer0 and Timer1. \n<ul>\n<li>The Timers0\/1\/2 continue their work after waking up without any further action<\/li>\n<\/ul>\n<\/li>\n<li><strong>PRSPI<\/strong>: turns off the SPI interface. SPI must be reinitialized after waking up.<\/li>\n<li><strong>PRUSART0<\/strong>: turns off the serial port, i.e. RX\/TX (<strong>U<\/strong>niversal <strong>S<\/strong>ynchronous and <strong>A<\/strong>synchronous serial <strong>R<\/strong>eceiver and <strong>T<\/strong>ransmitter). The USART interface must be reinitialized after waking up. <\/li>\n<li><strong>PRADC<\/strong>: switches off the ADC<br><ul>\n<li>To switch off the ADC, you must first deactivate it (line 18)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>You don&#8217;t have to use binary operations to set the bits of your choice (although that&#8217;s not really hard). For this purpose, there are functions defined in the header file power.h. In the following sketch you will find the (self-explanatory) functions in lines 28 to 35.<\/p>\n<p>To avoid fluctuating pin states during sleep, it is best to set the pins to OUTPUT\/LOW (line 6-11).<\/p>\n<\/p>\n<div class=\"scroll-paragraph\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"further_power_savings.ino\" data-enlighter-title=\"further_power_savings.ino\">#include &lt;avr\/wdt.h&gt;\n#include &lt;avr\/sleep.h&gt;\n#include &lt;avr\/power.h&gt;\n\nvoid setup(){\n  DDRB = 0;\n  DDRC = 0;\n  DDRD = 0;\n  PORTB = 0;\n  PORTC = 0;\n  PORTD = 0;\n\n  watchdogSetup();\n}\n\nvoid loop(){\n  delay(5000);\n  ADCSRA = 0; \/\/ disable ADC\n  set_sleep_mode(SLEEP_MODE_PWR_DOWN); \/\/ choose power down mode\n\/\/  set_sleep_mode(SLEEP_MODE_PWR_SAVE); \/\/ choose power save mode\n\/\/  set_sleep_mode(SLEEP_MODE_STANDBY); \/\/ choose external standby power mode\n\/\/  set_sleep_mode(SLEEP_MODE_EXT_STANDBY); \/\/ choose external standby power mode\n\/\/  set_sleep_mode(SLEEP_MODE_IDLE); \/\/ did not work!\n\/\/  set_sleep_mode(SLEEP_MODE_ADC); \/\/ choose ADC noise reduction mode\n\n  cli(); \/\/ deactivate interrupts\n\n\/\/  power_usart0_disable();\n\/\/  power_spi_disable();\n\/\/  power_timer0_disable();\n\/\/  power_timer1_disable();\n\/\/  power_timer2_disable();\n\/\/  power_twi_disable();\n\/\/  power_adc_disable();\n\/\/  power_all_disable (); \/\/ short summary of the former six lines\n  \n  sleep_enable(); \/\/ sets the SE (sleep enable) bit\n  sleep_bod_disable(); \/\/ disable brown-out detector\n  \n \n  sei(); \/\/ \n  sleep_cpu(); \/\/ sleep now!! \/\/ no wake up option selected\n  \n  sleep_disable();\n  power_all_enable();\n}\n\nvoid watchdogSetup(void){\n  cli();\n  wdt_reset();\n  WDTCSR |= (1&lt;&lt;WDCE) | (1&lt;&lt;WDE);\n  WDTCSR = (1&lt;&lt;WDIE) | (0&lt;&lt;WDE) | (1&lt;&lt;WDP3) | (1&lt;&lt;WDP0);  \/\/ 8s \/ interrupt, no system reset\n  sei();\n}\n\nISR(WDT_vect){\/\/put in additional code here\n}<\/pre>\n<p>\u00a0<\/p>\n<\/div>\n<p>\n\n<p>With this sketch I was able to reduce the current consumption at 5 V supply voltage to <strong>6.3 \u00b5A<\/strong>. If I also switched off the watchdog, it went down to <strong>0.28 \u00b5A<\/strong>. However, the ATmega328 then no longer wakes up at all. Alternatively, I tried a pin change interrupt as a wake-up method. This resulted in a current consumption of <strong>0.71 \u00b5A<\/strong> &#8211; not too bad either.   <\/p>\n<p>As you can see, I have not used any of the options provided by the Power Reduction Register in this sketch. This was not necessary because the components were either not activated or were switched off in power-down mode anyway. The main additional saving compared to the previous sketch was switching off the ADC using <code>ADCSRA = 0<\/code>.  <\/p>\n<p>If you are not sure what was activated in wake mode or not, it is better to switch off more than too little. However, you should not switch off anything that you need to wake up and you should not forget to switch the components back on again. <\/p>\n\n<h3 class=\"wp-block-heading\">Turning off the Brown-Out Detector (BOD)<\/h3>\n\n<h4 class=\"wp-block-heading\">What is a BOD?<\/h4>\n\n<p>In case of a sudden, complete power failure, one speaks of a blackout. I think everyone knows this expression. A brown-out, on the other hand, is when the supply voltage of the microcontroller slips below a minimum level. Typically, this happens when the battery running your project drains. A microcontroller that gets too little voltage does completely unpredictable things. The microcontroller itself does not necessarily take any damage. But if the devices it controls do strange things, that might become critical. That&#8217;s why most microcontrollers have a Brown-Out Detector (BOD). This compares the operating voltage with a fixed trigger level. If this level is exceeded, a reset is triggered to protect the system. However, for some applications, a brownout may be unproblematic.&nbsp;<\/p>\n\n<h4 class=\"wp-block-heading\">How do I turn off the BOD?<\/h4>\n\n<p>With the picoPower variants of the AVR microcontrollers, the Brown-Out detector can be switched off. You can recognize the picoPower models by the &#8220;P&#8221; in the name, e.g. the ATmega328<strong>P<\/strong>. The MCU Control Register MCUCR controlls the BOD:<\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/MCUCR.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"79\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/MCUCR-1024x79.png\" alt=\"\" class=\"wp-image-5418\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/MCUCR-1024x79.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/MCUCR-300x23.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/MCUCR-768x59.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/MCUCR.png 1186w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The Microcontroller Control Register MCUCR<\/figcaption><\/figure>\n\n<p>The following bits are relevant:<\/p>\n<ul>\n<li>BODS: BOD Sleep<\/li>\n<li>BODSE: BOD Sleep Enable<\/li>\n<\/ul>\n<p>Both bits must be set in a certain sequence to turn off the BOD. It is easier using the function <code>sleep_bod_disable()<\/code> which is defined in sleep.h. In the last sketch (idle_mode_enable.ino) I had already inserted the function in line 33, but not yet explained and commented out.&nbsp;<\/p>\n<p>Alternatively, if you use programs like <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/atmel-studio-7-an-introduction\" target=\"_blank\" rel=\"noopener noreferrer\">Atmel Studio,<\/a> you can also control the BOD via the corresponding fuse bits (BODLEVEL). Settings 4.3 V, 2.7 V, 1.8 V, or &#8220;disabled&#8221; are available.&nbsp;<\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/bodlevel_fuses.png\"><img loading=\"lazy\" decoding=\"async\" width=\"744\" height=\"310\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/bodlevel_fuses.png\" alt=\"BOD setting via the fuses \" class=\"wp-image-5422\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/bodlevel_fuses.png 744w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/bodlevel_fuses-300x125.png 300w\" sizes=\"auto, (max-width: 744px) 100vw, 744px\" \/><\/a><figcaption class=\"wp-element-caption\">BOD setting via the fuses<\/figcaption><\/figure>\n\n<p>According to my measurements, turning off the BOD in the Sleep Mode Power-down saves another 8 \u00b5A of power. Doesn&#8217;t sound much, but in a year it&#8217;s about 70 mAh.<\/p>\n\n<h3 class=\"wp-block-heading\">Lowering the clock frequency<\/h3>\n\n<p>In continuous awake mode, lowering the clock frequency results in a considerable saving (see Table 1). However, you have seen that the power consumption of the microcontroller is frequency-independent, at least in power-down mode. If you send the microcontroller to sleep and only wake it up briefly from time to time to do a few things, it may be better to select a high clock frequency. The reason for this is that things are done faster at high clock speeds. The speed overcompensates for the higher power consumption. If you use delays, things are different again. There is an interesting discussion about this topic on <a href=\"https:\/\/www.mikrocontroller.net\/topic\/412817\" target=\"_blank\" rel=\"noopener noreferrer\">mikrocontroller.net<\/a>.&nbsp;<\/p>\n\n<h3 class=\"wp-block-heading\">Lowering the operating voltage<\/h3>\n\n<p>A microcontroller acts like a capacitor or &#8211; more exact &#8211; like many small capacitors and their charge depends on the operating voltage. This is called parasitic capacities. In addition, there are leakage currents, e.g. from conductor track to another.<\/p>\n<p>In power-down mode, I could reduce the power consumption of the ATmega328P from 0.15 mA (programmed via Arduino IDE) to 0.12 mA when I reduced the voltage from 5 to 3.3 volts. More information and comparative values can be found <a href=\"https:\/\/www.mikrocontroller.net\/articles\/Leistungsaufnahme_von_Mikrocontrollern\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. <a id=\"Anker5\"><\/a><\/p>\n\n<h2 class=\"wp-block-heading\">Other wake-up methods<\/h2>\n\n<p>In previous examples, the watchdog was our alarm clock for the ATmega328P. I would now like to mention two other methods.&nbsp;<\/p>\n\n<h3 class=\"wp-block-heading\">Waking up via external interrupt<\/h3>\n\n<h4 class=\"wp-block-heading\">Using Arduino functions<\/h4>\n\n<p>In the following sketch, the ATmega328P is awakened by external interrupts. For this purpose, I have attached a pushbutton to INT0 (PD2, Pin4 = Arduino Pin 2), which generates a HIGH signal when pressed. Each time the button is pressed, the ATmega328P wakes up, the LED lights up for 1 second, then the ATmega328P settles down again. <\/p>\n<p>With the Arduino functions, the interrupt can be easily set up. It is advisable to deactivate the interrupt after waking up so that it is not triggered several times, for example due to bouncing of the pushbutton. I have used the short <code>sleep_mode()<\/code> function here to draw attention to the relevant things. <\/p>\n<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-group=\"wake_up_on_external_interrupt_arduino.ino\" data-enlighter-title=\"wake_up_on_external_interrupt_arduino.ino\">#include &lt;avr\/sleep.h&gt;\n\nvoid setup(){\n  DDRD = (1&lt;&lt;PD7); \n}\n\nvoid loop(){\n  PORTD |= (1&lt;&lt;PD7); \n  delay(1000);\n  PORTD &amp;= ~(1&lt;&lt;PD7); \n  attachInterrupt(digitalPinToInterrupt(2), intRoutine, RISING);\n  \n  set_sleep_mode(SLEEP_MODE_PWR_DOWN); \/\/ choose power down mode\n  sleep_mode(); \/\/ sleep now!\n}\n\nvoid intRoutine(){ \n  detachInterrupt(2); \/\/ external interrupt disable (INT0)\n}<\/pre>\n<p>\u00a0<\/p>\n<p>\n\n<h4 class=\"wp-block-heading\">Programming in C<\/h4>\n\n<p>You can also write directly into the relevant registers, which is not really difficult. In the EICRA Register (External Interrupt Control Register A), you set the conditions for the interrupt.<\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EICRA.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"77\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EICRA-1024x77.png\" alt=\"\" class=\"wp-image-5424\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EICRA-1024x77.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EICRA-300x23.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EICRA-768x58.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EICRA.png 1184w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The External Interrupt Control Register A EICRA<\/figcaption><\/figure>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/INT0_Select.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"219\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/INT0_Select-1024x219.png\" alt=\"\" class=\"wp-image-5426\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/INT0_Select-1024x219.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/INT0_Select-300x64.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/INT0_Select-768x164.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/INT0_Select.png 1033w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Setting the interrupt for INT0<\/figcaption><\/figure>\n\n<p>In the EIMSK (External Interrupt Mask Register) the interrupt is activated:<\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EIMSK.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"85\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EIMSK-1024x85.png\" alt=\"\" class=\"wp-image-5425\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EIMSK-1024x85.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EIMSK-300x25.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EIMSK-768x64.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/EIMSK.png 1184w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The External Interrupt Mask Register EIMSK<\/figcaption><\/figure>\n\n<p>Here&#8217;s what the sketch looks like: <\/p>\n<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-group=\"wake_up_on_external_interrupt_in_C.ino\" data-enlighter-title=\"wake_up_on_external_interrupt_in_C.ino\">#include &lt;avr\/sleep.h&gt;\n\nvoid setup(){\n  DDRD = (1&lt;&lt;PD7); \n  EICRA |= (1&lt;&lt;ISC01)|(1&lt;&lt;ISC00); \/\/ interrupt on rising edge of INT0\n}\n\nvoid loop(){\n  PORTD |= (1&lt;&lt;PD7); \n  delay(1000);\n  PORTD &amp;= ~(1&lt;&lt;PD7); \n  EIMSK |= (1&lt;&lt;INT0); \/\/ external interrupt enable on INT0\n  \n  set_sleep_mode(SLEEP_MODE_PWR_DOWN); \/\/ choose power down mode\n  sleep_mode(); \/\/ sleep now!\n}\n\n\/\/ INT0 interrupt service routine\nISR(INT0_vect){ \n  EIMSK &amp;= ~(1&lt;&lt;INT0); \/\/ external interrupt disable (INT0)\n}<\/pre>\n<p>\u00a0<\/p>\n<p>\n\n<h3 class=\"wp-block-heading\">Wake up by Timer2<\/h3>\n\n<p>If you want to wake up the ATmega328P using a timer, you can do this with Timer2 in all sleep modes, except in power-down mode. Anyone who has read my posts about the 8-bit <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/timer-and-pwm-part-1-8-bit-timer0-2\" target=\"_blank\" rel=\"noopener noreferrer\">Timer0 and Timer2<\/a> and the 16-bit <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/timer-and-pwm-part-2-16-bit-timer1\" target=\"_blank\" rel=\"noopener noreferrer\">Timer1<\/a> knows that the Timer2 overflows in a relatively short time, even when using the maximum prescaler. I do not go into the details of the timer programming here again. <\/p>\n<p>In the following example sketch, the Timer2 is set with the maximum prescaler. At a clock speed of 16 MHz, 16 mio\/1024\/256 = ~61 interrupts are triggered per second. To obtain an eight seconds rest phase, I added a counter that is incremented every time the MCU wakes up. Only after the 500th wake up the LED lights up. This equates to 500 \/ 61 = 8.2 seconds pause. One would think that waking up frequently leads to considerable surplus of power consumption. Surprisingly, I even found slightly less power consumption in the sleep phase compared to permanent sleep method using the watchdog timer (2.92 mA vs. 2.97 mA).<\/p>\n<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-group=\"wake_up_on_timer2_interrupt.ino\" data-enlighter-title=\"wake_up_on_timer2_interrupt.ino\">#include &lt;avr\/sleep.h&gt;\n#include &lt;avr\/power.h&gt;\nint counter = 0;\n\nvoid setup(){\n  DDRD = (1&lt;&lt;PD7); \n  TCCR2A = 0x00; \/\/ Wave Form Generation Mode 0: Normal Mode, OC2A disconnected\n  TCCR2B = (1&lt;&lt;CS22)|(1&lt;&lt;CS21)|(1&lt;&lt;CS20); \/\/ prescaler = 1024\n  TIMSK2 = (1&lt;&lt;TOIE2);\n}\n\nvoid loop(){\n  if(counter==500){\n    TIMSK2 &amp;= ~(1&lt;&lt;TOIE2);\n    PORTD |= (1&lt;&lt;PD7); \n    delay(1000);\n    PORTD &amp;= ~(1&lt;&lt;PD7); \n    counter = 0;\n  }\n  TIMSK2 = (1&lt;&lt;TOIE2); \/\/ interrupt when TCNT2 is overflowed\n  TCNT2 = 0;\n  set_sleep_mode(SLEEP_MODE_PWR_SAVE); \/\/ choose power down mode\n  \/\/power_timer2_disable(); \/\/ if you uncomment the MCU will sleep forever \n  sleep_mode(); \/\/ sleep now!\n  counter++;\n}\n\n\/\/ TIMER2 interrupt service routine\nISR(TIMER2_OVF_vect){ \n}<\/pre>\n<p>\u00a0<\/p>\n<p>\n\n<p>Try and uncomment line 23. The ATmega328P then falls into a &#8220;sleeping beauty sleep&#8221; &#8211; but without a prince kissing it awake. Only a reset awakes it again.<a id=\"Anker6\"><\/a>&nbsp;<\/p>\n\n<h2 class=\"wp-block-heading\">Apply sleep modes to other AVR MCUs<\/h2>\n\n<p>As mentioned at the beginning, the ATmega328P is not necessarily the first choice for an energy-saving project. With the knowledge acquired here, however, it should not be a problem for you to send other AVRs to sleep. Look at the data sheet and search for &#8220;sleep mode&#8221;. For example, the sleep mode table for the ATtiny85 \/ 45 \/ 25 looks like:<\/p>\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_ATtiny_25_45_85.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"428\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_ATtiny_25_45_85-1024x428.png\" alt=\"\" class=\"wp-image-5430\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_ATtiny_25_45_85-1024x428.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_ATtiny_25_45_85-300x125.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_ATtiny_25_45_85-768x321.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Sleep_Modes_and_Wake_up_Sources_ATtiny_25_45_85.png 1238w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Sleep modes for ATtiny85, ATtiny45, ATtiny25<\/figcaption><\/figure>\n\n<p>There are three sleep modes available, which can be activated via the corresponding functions from sleep.h. Awakening via the timer is not possible. However, if you write to the registers directly, you have to be aware that they have different names or that e.g. the watchdog timer has different prescalers.&nbsp;<\/p>\n\n<h2 class=\"wp-block-heading\">Acknowledgement<\/h2>\n\n<p>This time I used a lot of pictures of <a href=\"https:\/\/pixabay.com\/de\/\" target=\"_blank\" rel=\"noopener noreferrer\">Pixabay.<\/a> In detail, I would like to thank the hard-working photographers:<\/p>\n<ul>\n<li><a href=\"https:\/\/pixabay.com\/de\/users\/christinak93-13970472\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=4616370\">christinak93<\/a> for the monkey<\/li>\n<li><a href=\"https:\/\/pixabay.com\/de\/users\/takanashi66-14239\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=74154\" target=\"_blank\" rel=\"noopener noreferrer\">takanashi66<\/a> for the flamingos<\/li>\n<li><a href=\"https:\/\/pixabay.com\/de\/users\/Salmar-1781233\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2237209%22&gt;Salmar&lt;\/a&gt;%20auf%20&lt;a%20href=%22https:\/\/pixabay.com\/de\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2237209\" target=\"_blank\" rel=\"noopener noreferrer\">Salmar<\/a> for the bats<\/li>\n<li><a href=\"https:\/\/pixabay.com\/de\/users\/yyoz-143067\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=254060\" target=\"_blank\" rel=\"noopener noreferrer\">Yves Yoseph<\/a> for the tired biker<\/li>\n<li><a href=\"https:\/\/pixabay.com\/de\/users\/PhilipBarrington-1255904\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1249511\" target=\"_blank\" rel=\"noopener noreferrer\">Philip Barrington<\/a> for the koala <\/li>\n<li><a href=\"https:\/\/pixabay.com\/de\/users\/skeeze-272447\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=890642\" target=\"_blank\" rel=\"noopener noreferrer\">skeeze<\/a> for the seal<\/li>\n<li><a href=\"https:\/\/pixabay.com\/de\/users\/_freakwave_-12222786\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=4253125%22&gt;_freakwave_&lt;\/a&gt;%20auf%20&lt;a%20href=%22https:\/\/pixabay.com\/de\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=4253125\" target=\"_blank\" rel=\"noopener noreferrer\">_freakwave_<\/a> for the cats<\/li>\n<li><a href=\"https:\/\/pixabay.com\/de\/users\/Alexas_Fotos-686414\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1320855\" target=\"_blank\" rel=\"noopener noreferrer\">Alexas_Fotos<\/a> for the pig<\/li>\n<li><a href=\"https:\/\/pixabay.com\/de\/users\/mermyhh-48700\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2886622\" target=\"_blank\" rel=\"noopener noreferrer\">Sabine Lange<\/a> for the baby<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>By using sleep modes and power management, valuable battery power can be saved on projects. I&#8217;ll show you how to control these features.<\/p>\n","protected":false},"author":1,"featured_media":8413,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[543],"tags":[556,1061,707,1088,1086,1081,1093,1094,1084,1091,1080,1082,1090],"class_list":["post-10152","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-boards-and-microcontrollers","tag-arduino-en-2","tag-atmega328p-en","tag-attiny85-en","tag-bod-en-2","tag-brown-out-en-2","tag-power-management-en","tag-power-down-en-2","tag-power-save-en","tag-power-h-en","tag-prr-en","tag-sleep-modes-en","tag-sleep-h-en","tag-smcr-en-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Sleep Modes and Power Management &#8226; Wolles Elektronikkiste<\/title>\n<meta name=\"description\" content=\"By using sleep modes and power management, valuable battery power can be saved on projects. I&#039;ll show you how to control these features.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Sleep Modes and Power Management &#8226; Wolles Elektronikkiste\" \/>\n<meta property=\"og:description\" content=\"By using sleep modes and power management, valuable battery power can be saved on projects. I&#039;ll show you how to control these features.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management\" \/>\n<meta property=\"og:site_name\" content=\"Wolles Elektronikkiste\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-07T22:36:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-17T19:23:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Beitragsbild-1-1024x1024.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Wolfgang Ewald\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Wolfgang Ewald\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management\"},\"author\":{\"name\":\"Wolfgang Ewald\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"headline\":\"Sleep Modes and Power Management\",\"datePublished\":\"2020-12-07T22:36:18+00:00\",\"dateModified\":\"2025-09-17T19:23:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management\"},\"wordCount\":2855,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"image\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Beitragsbild-1.jpg\",\"keywords\":[\"Arduino\",\"ATmega328P\",\"ATtiny85\",\"BOD\",\"brown-out\",\"power management\",\"power-down\",\"power-save\",\"power.h\",\"PRR\",\"sleep modes\",\"sleep.h\",\"SMCR\"],\"articleSection\":[\"Boards and Microcontrollers\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management\",\"name\":\"Sleep Modes and Power Management &#8226; Wolles Elektronikkiste\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Beitragsbild-1.jpg\",\"datePublished\":\"2020-12-07T22:36:18+00:00\",\"dateModified\":\"2025-09-17T19:23:37+00:00\",\"description\":\"By using sleep modes and power management, valuable battery power can be saved on projects. I'll show you how to control these features.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management#primaryimage\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Beitragsbild-1.jpg\",\"contentUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2020\\\/02\\\/Beitragsbild-1.jpg\",\"width\":1800,\"height\":1800},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/sleep-modes-and-power-management#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Startseite\",\"item\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Sleep Modes and Power Management\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#website\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\",\"name\":\"Wolles Elektronikkiste\",\"description\":\"Die wunderbare Welt der Elektronik\",\"publisher\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\",\"name\":\"Wolfgang Ewald\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"contentUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"width\":512,\"height\":512,\"caption\":\"Wolfgang Ewald\"},\"logo\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Sleep Modes and Power Management &#8226; Wolles Elektronikkiste","description":"By using sleep modes and power management, valuable battery power can be saved on projects. I'll show you how to control these features.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management","og_locale":"en_US","og_type":"article","og_title":"Sleep Modes and Power Management &#8226; Wolles Elektronikkiste","og_description":"By using sleep modes and power management, valuable battery power can be saved on projects. I'll show you how to control these features.","og_url":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management","og_site_name":"Wolles Elektronikkiste","article_published_time":"2020-12-07T22:36:18+00:00","article_modified_time":"2025-09-17T19:23:37+00:00","og_image":[{"width":1024,"height":1024,"url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Beitragsbild-1-1024x1024.jpg","type":"image\/jpeg"}],"author":"Wolfgang Ewald","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Wolfgang Ewald","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management#article","isPartOf":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management"},"author":{"name":"Wolfgang Ewald","@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"headline":"Sleep Modes and Power Management","datePublished":"2020-12-07T22:36:18+00:00","dateModified":"2025-09-17T19:23:37+00:00","mainEntityOfPage":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management"},"wordCount":2855,"commentCount":2,"publisher":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"image":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management#primaryimage"},"thumbnailUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Beitragsbild-1.jpg","keywords":["Arduino","ATmega328P","ATtiny85","BOD","brown-out","power management","power-down","power-save","power.h","PRR","sleep modes","sleep.h","SMCR"],"articleSection":["Boards and Microcontrollers"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management#respond"]}]},{"@type":"WebPage","@id":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management","url":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management","name":"Sleep Modes and Power Management &#8226; Wolles Elektronikkiste","isPartOf":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#website"},"primaryImageOfPage":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management#primaryimage"},"image":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management#primaryimage"},"thumbnailUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Beitragsbild-1.jpg","datePublished":"2020-12-07T22:36:18+00:00","dateModified":"2025-09-17T19:23:37+00:00","description":"By using sleep modes and power management, valuable battery power can be saved on projects. I'll show you how to control these features.","breadcrumb":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management#primaryimage","url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Beitragsbild-1.jpg","contentUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/02\/Beitragsbild-1.jpg","width":1800,"height":1800},{"@type":"BreadcrumbList","@id":"https:\/\/wolles-elektronikkiste.de\/en\/sleep-modes-and-power-management#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Startseite","item":"https:\/\/wolles-elektronikkiste.de\/en"},{"@type":"ListItem","position":2,"name":"Sleep Modes and Power Management"}]},{"@type":"WebSite","@id":"https:\/\/wolles-elektronikkiste.de\/en#website","url":"https:\/\/wolles-elektronikkiste.de\/en","name":"Wolles Elektronikkiste","description":"Die wunderbare Welt der Elektronik","publisher":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wolles-elektronikkiste.de\/en?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46","name":"Wolfgang Ewald","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","contentUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","width":512,"height":512,"caption":"Wolfgang Ewald"},"logo":{"@id":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png"}}]}},"_links":{"self":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts\/10152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/comments?post=10152"}],"version-history":[{"count":6,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts\/10152\/revisions"}],"predecessor-version":[{"id":24889,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts\/10152\/revisions\/24889"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/media\/8413"}],"wp:attachment":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/media?parent=10152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/categories?post=10152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/tags?post=10152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}