Arduino Uno does not enter Idle Mode

Hi guys,

I’m trying to measure the power consumption of my Arduino while being in different sleep modes and compare the measurements with the regular power consumption.
Therefore I used the following code:

#include <avr/sleep.h> 

void setup()
{
  Serial.begin(9600);                         
  pinMode(13,OUTPUT);                         
  digitalWrite(13,HIGH); 
  pinMode(2,INPUT);                           
  digitalWrite(2,HIGH);

 
}

void loop()
{
  Serial.println("5");
  delay(1000);
  Serial.println("4");
  delay(1000); 
  Serial.println("3");
  delay(1000); 
  Serial.println("2");
  delay(1000); 
  Serial.println("1");
  delay(1000);                                
  Serial.println("Zzz");
  delay(1500);
  sleepSetup();                   
}

void sleepSetup()                 
{
  sleep_enable();
  attachInterrupt(0, pinInterupt, LOW); 
  set_sleep_mode(SLEEP_MODE_IDLE);        
  digitalWrite(13,LOW);                       
  sleep_cpu();                               
  Serial.println("Just woke up!");       
  digitalWrite(13,HIGH);                      
}

void pinInterupt()                            
{
  
  sleep_disable();

  detachInterrupt(0);
  
}

The program works perfectly fine for almost every sleep mode.
But in idle mode the Arduino does not fall asleep. It just continues with the code and the serial monitor says “Just works up!”
Why is it?


Please excuse my bad English! :wink:

and the serial monitor says "Just works up!"

Specifically, which line of code causes THAT to happen?

Look at the Idle mode in the datasheet to see what can cause a wake-up. Could it be caused by the Timer0 interrupt that happens roughly every millisecond? Perhaps disabling interrupts could allow your processor to sleep longer. Of course then you wouldn't be able to wake it with Pin 2.

@OP

There are 5 different sleep modes which are:
The 5 different modes are:
SLEEP_MODE_IDLE -the least power savings
SLEEP_MODE_ADC
SLEEP_MODE_PWR_SAVE
SLEEP_MODE_STANDBY
SLEEP_MODE_PWR_DOWN -the most power savings

Your program works well for SAVE, STANDBY, DOWN; but, it does not work for IDLE. Why? I could not yet figure out.

Chip is being woken by the millis() timer interrupt, which is not stopped during Idle sleep mode. It will sleep for some fraction of a millisecond, and then be woken by the interrupt.

DrAzzy:
Chip is being woken by the millis() timer interrupt, which is not stopped during Idle sleep mode. It will sleep for some fraction of a millisecond, and then be woken by the interrupt.

Right point. I have tested the OP’s program with ‘TC0’s interrupt enable bit disabled’. Now, the MCU enters into IDLE state and wakes up when interrupted by INT0. ++++++++++++++++++++++++.

#include <avr/sleep.h>

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  bitClear(TIMSK0, 0);  //TC0's interrupt capability is disabled.


}

void loop()
{
  Serial.println("5");
  delay(1000);
  Serial.println("4");
  delay(1000);
  Serial.println("3");
  delay(1000);
  Serial.println("2");
  delay(1000);
  Serial.println("1");
  delay(1000);
  Serial.println("Zzz");
  delay(1500);
  sleepSetup();
}

void sleepSetup()
{
  sleep_enable();
  attachInterrupt(0, pinInterupt, LOW);
  set_sleep_mode(SLEEP_MODE_IDLE);//SLEEP_MODE_STANDBY);//PWR_SAVE);//PWR_DOWN);//IDLE);
 // SMCR = SMCR & 0b00000001;
  digitalWrite(13, LOW);
  sleep_cpu();
  Serial.println("Just woke up!");
//  bitSet(TIMSK0, 0);
  digitalWrite(13, HIGH);
}

void pinInterupt()
{
  sleep_disable();
  detachInterrupt(0);
}