exit status 1 'set_sleep_mode' was not declared in this scope

Hi, I would be grateful for some assistance.

I copied the main element of the code below from the “learning/sleep” example on the Arduino.cc siteI have removed the timer element from the code. Unfortunately, this has not compiled past the point indicated above. I have just started using an Arduino UNO R3 and am hoping to use a sleep function on a project and want to make it work with “blink” and an interupt in Pin 2 as a learning exercise.

The error message in the subject line above appears.

The avr/sleep.h file does not appear in the IDE sketch standard library…do I need to download this? Or is the problem one associated with the code?

#include <avr/sleep.h>

/* Sleep Demo Serial
 * -----------------
 * Example code to demonstrate the sleep functions in an Arduino.
 * use a resistor between RX and pin2. By default RX is pulled up to 5V
 * therefore, we can use a sequence of Serial data forcing RX to 0, what
 * will make pin2 go LOW activating INT0 external interrupt, bringing
 * the MCU back to life
 * NOTE: when coming back from POWER-DOWN mode, it takes a bit
 *       until the system is functional at 100%!! (typically <1sec)
 * Copyright (C) 2006 MacSimski 2006-12-30 
 * Copyright (C) 2007 D. Cuartielles 2007-07-08 - Mexico DF
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  GNU General Public License for more details.
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.

int wakePin = 2;                 // pin used for waking up
int sleepStatus = 0;             // variable to store a request for sleep

void wakeUpNow()        // here the interrupt is handled after wakeup
  // execute code here after wake-up before returning to the loop() function
  // timers and code using timers (serial.print and more...) will not work here.
  // we don't really need to execute any special functions here, since we
  // just want the thing to wake up

void setup()
  pinMode(wakePin, INPUT);

void sleepNow()         // here we put the arduino to sleep
    /* Now is the time to set the sleep mode. In the Atmega8 datasheet
     * http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
     * there is a list of sleep modes which explains which clocks and 
     * wake up sources are available in which sleep mode.
     * In the avr/sleep.h file, the call names of these sleep modes are to be found:
     * The 5 different modes are:
     *     SLEEP_MODE_IDLE         -the least power savings 
     *     SLEEP_MODE_ADC
     *     SLEEP_MODE_PWR_DOWN     -the most power savings
     * For now, we want as much power savings as possible, so we 
     * choose the according 
     * sleep mode: SLEEP_MODE_PWR_DOWN
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here

    sleep_enable();          // enables the sleep bit in the mcucr register
                             // so sleep is possible. just a safety pin 

    /* Now it is time to enable an interrupt. We do it here so an 
     * accidentally pushed interrupt button doesn't interrupt 
     * our running program. if you want to be able to run 
     * interrupt code besides the sleep function, place it in 
     * setup() for example.
     * In the function call attachInterrupt(A, B, C)
     * A   can be either 0 or 1 for interrupts on pin 2 or 3.   
     * B   Name of a function you want to execute at interrupt for A.
     * C   Trigger mode of the interrupt pin. can be:
     *             LOW        a low level triggers
     *             CHANGE     a change in level triggers
     *             RISING     a rising edge of a level triggers
     *             FALLING    a falling edge of a level triggers
     * In all but the IDLE sleep modes only LOW can be used.

    attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
                                       // wakeUpNow when pin 2 gets LOW 

    sleep_mode();            // here the device is actually put to sleep!!

    sleep_disable();         // first thing after waking from sleep:
                             // disable sleep...
    detachInterrupt(0);      // disables interrupt 0 on pin 2 so the 
                             // wakeUpNow code will not be executed 
                             // during normal running time.


void loop()
{ delay(500);
 digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second 


   // check if it should go to sleep 
      sleepNow();     // sleep function called here

Is the code above your modification, or is it the basis which you used ?

I found one problem in it that 'wakepin' sometimes appears as 'wakePin' and C/C++ is case sensitive.

Hi ,Thanks of ryour help.
I have copied the code from the Learning/sleep on the Arduino website. I think i have just taken out code associated with timer inputs. But the error message relates to set sleep mode not being included in scope...I am wondering whether avr/sleep.h is actually being included from the start?

All I can say is that when I correct the error whereby “wakepin” appears instead of “wakePin” it compiles OK without the “exit status 1 ‘set_sleep_mode’ was not declared in this scope” error you referred to.

If the library avr/sleep.h is missing, you’d get a missing library error.
Scroll through the window where the message appears to see if there are any other errors.

Hi, thanks again for your reply. I have tried starting afresh with a simplified version and it compiled ok. I think that it may not have liked the cut and paste part with the #include when I copied the code in originally. Lesson learned. Thanks for sorting the wakePin error.
Thanks for your help.