I didn’t like that much that solution so I started to look into other ways of doing it without using an extra pin and without risk of losing data in the serial interface. Because as I understood it using SLEEP_MODE_PWR_DOWN requires to send first a burst of data to the serial interface in order to wake up the arduino. And it takes a while for the Arduino to become fully functional so that means that you will lose/miss data in the serial interface. That was something that didn’t fit my project.
In order to be able to sleep but without missing serial data I used POWER_MODE_IDLE, a power saving mode that leaves the USART on and then using the functions defined in power.h (you have to use arduino-12 to get power.h) I disabled all other modules that I don’t need to cut down the power consumption. When any data is received in the USART the Arduino will be brought back to normal power mode (USART uses interrupts and any interrupt makes the ATmega168 to exit the power saving mode).
<span class='line'>/* Sleep Demo Serial
</span><span class='line'> * -----------------
</span><span class='line'> * Example code to demonstrate the sleep functions in a Arduino. Arduino will wake up
</span><span class='line'> * when new data is received in the serial port USART
</span><span class='line'> * Based on Sleep Demo Serial from http://www.arduino.cc/playground/Learning/ArduinoSleepCode
</span><span class='line'> *
</span><span class='line'> * Copyright (C) 2006 MacSimski 2006-12-30
</span><span class='line'> * Copyright (C) 2007 D. Cuartielles 2007-07-08 - Mexico DF
</span><span class='line'> *
</span><span class='line'> * With modifications from Ruben Laguna 2008-10-15
</span><span class='line'> *
</span><span class='line'> * This program is free software: you can redistribute it and/or modify
</span><span class='line'> * it under the terms of the GNU General Public License as published by
</span><span class='line'> * the Free Software Foundation, either version 3 of the License, or
</span><span class='line'> * (at your option) any later version.
</span><span class='line'> *
</span><span class='line'> * This program is distributed in the hope that it will be useful,
</span><span class='line'> * but WITHOUT ANY WARRANTY; without even the implied warranty of
</span><span class='line'> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
</span><span class='line'> * GNU General Public License for more details.
</span><span class='line'> *
</span><span class='line'> * You should have received a copy of the GNU General Public License
</span><span class='line'> * along with this program. If not, see <http://www.gnu.org/licenses/>.
</span><span class='line'> *
</span><span class='line'> */
</span><span class='line'>
</span><span class='line'>#include <avr/power.h>
</span><span class='line'>#include <avr/sleep.h>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'>int sleepStatus = 0; // variable to store a request for sleep
</span><span class='line'>int count = 0; // counter
</span><span class='line'>
</span><span class='line'>
</span><span class='line'>void setup()
</span><span class='line'>{
</span><span class='line'>
</span><span class='line'> Serial.begin(9600);
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>void sleepNow()
</span><span class='line'>{
</span><span class='line'> /* Now is the time to set the sleep mode. In the Atmega8 datasheet
</span><span class='line'> * http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
</span><span class='line'> * there is a list of sleep modes which explains which clocks and
</span><span class='line'> * wake up sources are available in which sleep modus.
</span><span class='line'> *
</span><span class='line'> * In the avr/sleep.h file, the call names of these sleep modus are to be found:
</span><span class='line'> *
</span><span class='line'> * The 5 different modes are:
</span><span class='line'> * SLEEP_MODE_IDLE -the least power savings
</span><span class='line'> * SLEEP_MODE_ADC
</span><span class='line'> * SLEEP_MODE_PWR_SAVE
</span><span class='line'> * SLEEP_MODE_STANDBY
</span><span class='line'> * SLEEP_MODE_PWR_DOWN -the most power savings
</span><span class='line'> *
</span><span class='line'> * the power reduction management <avr/power.h> is described in
</span><span class='line'> * http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
</span><span class='line'> */
</span><span class='line'>
</span><span class='line'> set_sleep_mode(SLEEP_MODE_IDLE); // sleep mode is set here
</span><span class='line'>
</span><span class='line'> sleep_enable(); // enables the sleep bit in the mcucr register
</span><span class='line'> // so sleep is possible. just a safety pin
</span><span class='line'>
</span><span class='line'> power_adc_disable();
</span><span class='line'> power_spi_disable();
</span><span class='line'> power_timer0_disable();
</span><span class='line'> power_timer1_disable();
</span><span class='line'> power_timer2_disable();
</span><span class='line'> power_twi_disable();
</span><span class='line'>
</span><span class='line'>
</span><span class='line'> sleep_mode(); // here the device is actually put to sleep!!
</span><span class='line'>
</span><span class='line'> // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
</span><span class='line'> sleep_disable(); // first thing after waking from sleep:
</span><span class='line'> // disable sleep...
</span><span class='line'>
</span><span class='line'> power_all_enable();
</span><span class='line'>
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>
</span><span class='line'>void loop()
</span><span class='line'>{
</span><span class='line'> // display information about the counter
</span><span class='line'> Serial.print("Awake for ");
</span><span class='line'> Serial.print(count);
</span><span class='line'> Serial.println("sec");
</span><span class='line'> count++;
</span><span class='line'> delay(1000); // waits for a second
</span><span class='line'>
</span><span class='line'> // compute the serial input
</span><span class='line'> if (Serial.available()) {
</span><span class='line'> int val = Serial.read();
</span><span class='line'> if (val == 'S') {
</span><span class='line'> Serial.println("Serial: Entering Sleep mode");
</span><span class='line'> delay(100); // this delay is needed, the sleep
</span><span class='line'> //function will provoke a Serial error otherwise!!
</span><span class='line'> count = 0;
</span><span class='line'> sleepNow(); // sleep function called here
</span><span class='line'> }
</span><span class='line'> if (val == 'A') {
</span><span class='line'> Serial.println("Hola Caracola"); // classic dummy message
</span><span class='line'> }
</span><span class='line'> }
</span><span class='line'>
</span><span class='line'> // check if it should go asleep because of time
</span><span class='line'> if (count >= 10) {
</span><span class='line'> Serial.println("Timer: Entering Sleep mode");
</span><span class='line'> delay(100); // this delay is needed, the sleep
</span><span class='line'> //function will provoke a Serial error otherwise!!
</span><span class='line'> count = 0;
</span><span class='line'> sleepNow(); // sleep function called here
</span><span class='line'> }
</span><span class='line'>}</span>