0
0
Arduinoprogramming~10 mins

Wake-up from sleep with interrupt in Arduino - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Wake-up from sleep with interrupt
Start program
Setup interrupt
Enter sleep mode
Interrupt occurs?
NoStay asleep
Yes
Wake up
Run interrupt code
Return to main loop or sleep
The program sets up an interrupt, then goes to sleep. When the interrupt triggers, it wakes up and runs the interrupt code.
Execution Sample
Arduino
#include <avr/sleep.h>

void wakeUp() {
  sleep_disable();
  // Interrupt code
}

void setup() {
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), wakeUp, FALLING);
}

void loop() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_mode();
}
This code puts the Arduino to sleep and wakes it up when pin 2 detects a falling edge interrupt.
Execution Table
StepActionInterrupt Pin StateSleep StateInterrupt TriggeredOutput/Effect
1Setup pin 2 as input with pull-upHIGHAwakeNoPin 2 ready for interrupt
2Attach interrupt on pin 2 falling edgeHIGHAwakeNoInterrupt configured
3Enter sleep modeHIGHSleepingNoArduino sleeps, waiting
4Pin 2 goes LOW (button pressed)LOWSleepingYesInterrupt triggers wakeUp()
5WakeUp function runsLOWAwakeYesArduino wakes and runs code
6Return to loop or sleep againHIGHAwake or SleepingNoCycle repeats
7Pin 2 stays HIGH, no interruptHIGHSleepingNoArduino remains asleep
💡 Execution stops sleeping only when interrupt triggers (pin 2 falling edge detected)
Variable Tracker
VariableStartAfter Step 3After Step 4After Step 5Final
Interrupt Pin StateHIGHHIGHLOWLOWHIGH
Sleep StateAwakeSleepingSleepingAwakeAwake or Sleeping
Interrupt TriggeredNoNoYesYesNo
Key Moments - 3 Insights
Why does the Arduino stay asleep even if the pin state changes?
The Arduino only wakes up when the interrupt condition (falling edge) occurs, not just any pin change. See execution_table row 7 where pin is HIGH and no interrupt triggers.
What happens inside the wakeUp() function?
The wakeUp() function runs immediately when the interrupt triggers, waking the Arduino from sleep. This is shown in execution_table row 5.
Why do we use INPUT_PULLUP for the pin mode?
INPUT_PULLUP keeps the pin HIGH by default, so pressing a button pulls it LOW, creating a falling edge to trigger the interrupt. This setup is in execution_table row 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the Sleep State at Step 4 when the interrupt triggers?
AAwake
BUnknown
CSleeping
DReset
💡 Hint
Check the Sleep State column at Step 4 in the execution_table.
At which step does the Arduino wake up from sleep?
AStep 5
BStep 3
CStep 4
DStep 7
💡 Hint
Look for the step where the wakeUp() function runs and Sleep State changes to Awake.
If the pin never goes LOW, what happens to the Arduino?
AIt stays awake
BIt stays asleep indefinitely
CIt wakes up periodically
DIt resets
💡 Hint
See execution_table row 7 where pin stays HIGH and no interrupt triggers.
Concept Snapshot
Setup interrupt on a pin with attachInterrupt(pin, ISR, mode)
Use INPUT_PULLUP to keep pin HIGH by default
Call sleep_mode() to enter sleep
Arduino wakes when interrupt triggers (e.g., falling edge)
ISR runs immediately on wake-up
After ISR, program continues or sleeps again
Full Transcript
This example shows how an Arduino can go to sleep and wake up using an interrupt. First, the program sets pin 2 as input with a pull-up resistor. Then it attaches an interrupt to pin 2 that triggers on a falling edge (when the pin goes from HIGH to LOW). The Arduino then enters sleep mode. When the pin 2 detects a falling edge, the interrupt triggers the wakeUp() function, waking the Arduino. After running the interrupt code, the Arduino can continue running or go back to sleep. The key is that the Arduino stays asleep until the interrupt triggers, saving power.