Problem with Arduino Micro and putting it to sleep

I have an application who is run by batteries, I need to put the Arduino Micro to sleep and wake it up again with an interrupt. I have searched the net and found different approaches to put the Arduino to sleep, but I simply can't get it to work.

When I program the Arduino Micro with the code below, it drops the usb connection to the board and nothing happens, no LED is on and when I pulls pin 2 low nothing happens???

#include <avr/sleep.h>

int wakePin = 2;                 // pin used for waking up           
int led = 13;

void setup()
{
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW); //Lights on when not in sleep

  pinMode(wakePin, INPUT);
  digitalWrite(wakePin, HIGH); //Activate the internal pull up resistor
}

void loop()
{
  delay(5000); //wait 5 sec. before sleep

  SleepNow();
}

void SleepNow()         // here we put the arduino to sleep
{
  sleep_enable();          // enables the sleep bit in the mcucr register
  attachInterrupt(0, WakeUp, LOW); // use interrupt 0 (pin 2) and run function wakeUp when pin 2 gets LOW 

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here

  digitalWrite(led, LOW);
  //sleep_cpu();

  sleep_mode();            // here the device is actually put to sleep!!
 
  // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP

  for(int i = 0; i < 5; i++) //when wake up blink with the onboard led 5 times
  {
    digitalWrite(led, HIGH);
    delay(100);
    digitalWrite(led, LOW);
  }

}

void WakeUp()        // here the interrupt is handled after wakeup
{
  sleep_disable();
  detachInterrupt(0);
}

A sleep mode tutorial with not the same code as yours:
http://www.engblaze.com/hush-little-microprocessor-avr-and-arduino-sleep-mode-basics/

Also you should put your code posted here into code tags so it views without html interpretation.
In the forum post edit window, the # button makes code tags around highlighted text.

Should be in code tags now :slight_smile:

Have tried the code, but that didn't work either :frowning: is there something special about the Micro board???

Kelle

I don't have one but here's the Arduino site specs page. Hey, I didn't know it's got a 32U4! 2.5K SRAM!

One question comes to mind, is your battery if it goes to VI at least 7V?

Did you try sleep mode idle?

Also the Pin Map is not as the UNO but instead the Leonardo.
It may matter if you address port registers, which I don't see.

-Here in the development process I use a power supply, so I just put 7v on the VIN pin.

-I haven't tried the idle mode

-I rely on the Pinout description on the http://arduino.cc/en/Main/ArduinoBoardMicro page, so as far as I understand, interrupt 0 is D2 who is PIN 7 (the left side) on the Micro board.

Everything seems to be ok, but it doesn't work :frowning: The interrupt pin is set to trigger on LOW and the idle setup is, as far as I understand, set up right...

Kelle

It must be something with the Micro board, have just tried with the UNO board and everything works just fine???

Kelle

Also works like a charm with the mini board

Kelle

Try putting a led and resistor on pin 2 and make it light.