What is the purpose of using interrupts to wake up an Arduino from sleep mode?
Interrupts allow the Arduino to wake up immediately when a specific event occurs, saving power by sleeping until needed.
Click to reveal answer
beginner
Which Arduino function is used to put the microcontroller into sleep mode?
The sleep_mode() function from the avr/sleep.h library is used to put the Arduino into sleep mode.
Click to reveal answer
intermediate
How do you attach an interrupt to a pin to wake the Arduino from sleep?
Use attachInterrupt(digitalPinToInterrupt(pin), ISR, mode) where ISR is the interrupt service routine and mode defines the trigger condition (e.g., RISING).
Click to reveal answer
intermediate
What must you do inside the Interrupt Service Routine (ISR) to wake the Arduino from sleep?
The ISR should be short and can set a flag or simply return; the interrupt itself wakes the Arduino from sleep automatically.
Click to reveal answer
advanced
Why is it important to disable ADC and other peripherals before sleeping?
Disabling ADC and unused peripherals reduces power consumption, making sleep mode more effective.
Click to reveal answer
Which library is commonly used to control sleep modes on Arduino?
AWire.h
Bavr/sleep.h
CSPI.h
DEEPROM.h
✗ Incorrect
The avr/sleep.h library provides functions to manage sleep modes on Arduino.
What does attachInterrupt(digitalPinToInterrupt(pin), ISR, RISING) do?
ASets an interrupt on the pin triggered when the signal rises
BPuts the Arduino to sleep
CDisables the interrupt on the pin
DReads the digital value of the pin
✗ Incorrect
It attaches an interrupt to the specified pin that triggers the ISR when the signal changes from LOW to HIGH.
What happens when an interrupt occurs while Arduino is sleeping?
AArduino shuts down
BArduino stays asleep
CArduino resets
DArduino wakes up and runs the ISR
✗ Incorrect
An interrupt wakes the Arduino from sleep and executes the interrupt service routine.
Which of these is NOT a valid interrupt trigger mode?
ASTABLE
BFALLING
CRISING
DCHANGE
✗ Incorrect
STABLE is not a valid interrupt trigger mode; valid modes include RISING, FALLING, and CHANGE.
Why should the ISR be kept short when waking from sleep?
ATo disable interrupts
BTo use more memory
CTo quickly return control and avoid delays
DTo put Arduino back to sleep
✗ Incorrect
Short ISRs ensure the Arduino resumes normal operation quickly without blocking other processes.
Explain how to set up an Arduino to wake up from sleep using an external interrupt.
Think about the steps from preparing sleep to waking up with a button press.
You got /5 concepts.
Describe why using interrupts to wake from sleep is better for power saving than polling.
Compare continuous checking vs waiting quietly.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using an interrupt to wake an Arduino from sleep mode?
easy
A. To allow the Arduino to respond immediately to an external event while saving power
B. To make the Arduino run faster during normal operation
C. To reset the Arduino automatically after a delay
D. To increase the Arduino's memory capacity
Solution
Step 1: Understand sleep mode purpose
Arduino sleep mode reduces power consumption by stopping most activities.
Step 2: Role of interrupts in sleep mode
Interrupts allow the Arduino to wake up immediately when an external event occurs, saving power while staying responsive.
Final Answer:
To allow the Arduino to respond immediately to an external event while saving power -> Option A
Quick Check:
Interrupt wakes Arduino from sleep to save power [OK]
Hint: Interrupts wake Arduino instantly during sleep to save power [OK]
Common Mistakes:
Thinking interrupts speed up normal running
Confusing interrupts with reset functions
Believing interrupts increase memory
2. Which of the following is the correct way to attach an interrupt to pin 2 that triggers on a RISING signal?
easy
A. attachInterrupt(2, ISR, FALLING);
B. attachInterrupt(digitalPinToInterrupt(2), ISR, RISING);
C. attachInterrupt(digitalPinToInterrupt(3), ISR, CHANGE);
D. attachInterrupt(2, ISR, LOW);
Solution
Step 1: Use digitalPinToInterrupt() for pin mapping
Pin 2 must be converted using digitalPinToInterrupt(2) for portability.
Step 2: Set correct trigger mode
RISING triggers interrupt when signal goes from LOW to HIGH.
Final Answer:
attachInterrupt(digitalPinToInterrupt(2), ISR, RISING); -> Option B
Quick Check:
Correct pin and RISING trigger = attachInterrupt(digitalPinToInterrupt(2), ISR, RISING); [OK]
Hint: Always use digitalPinToInterrupt(pin) with correct trigger [OK]
Common Mistakes:
Using pin number directly without digitalPinToInterrupt()
Choosing wrong trigger mode like FALLING or LOW
Attaching interrupt to wrong pin number
3. What will be the output on the serial monitor after running this code if a button connected to pin 2 is pressed once?
A. attachInterrupt() uses pin number directly instead of digitalPinToInterrupt()
B. ISR function should not be empty
C. sleep_mode() should be called inside loop()
D. sleep_enable() must be called after sleep_mode()
Solution
Step 1: Check attachInterrupt() usage
Pin number must be converted with digitalPinToInterrupt(pin) for correct interrupt mapping.
Step 2: Validate other parts
Empty ISR is allowed; sleep_mode() can be in setup; sleep_enable() must be before sleep_mode().
Final Answer:
attachInterrupt() uses pin number directly instead of digitalPinToInterrupt() -> Option A
Quick Check:
Pin mapping requires digitalPinToInterrupt() [OK]
Hint: Always convert pin with digitalPinToInterrupt() in attachInterrupt() [OK]
Common Mistakes:
Not using digitalPinToInterrupt() for pin mapping
Thinking ISR must have code
Misplacing sleep_enable() call
5. You want to put your Arduino to sleep and wake it up only when a button connected to pin 4 is pressed. Which sequence correctly implements this behavior?
hard
A. attachInterrupt(digitalPinToInterrupt(4), wakeISR, LOW); sleep_enable(); sleep_mode();
B. attachInterrupt(4, wakeISR, RISING); sleep_disable(); sleep_mode();
C. attachInterrupt(digitalPinToInterrupt(4), wakeISR, FALLING); sleep_enable(); sleep_mode();
D. attachInterrupt(digitalPinToInterrupt(4), wakeISR, CHANGE); sleep_enable(); sleep_disable();
Solution
Step 1: Attach interrupt correctly
Use digitalPinToInterrupt(4) and FALLING trigger for button press (assuming active LOW button).
Step 2: Enable sleep and enter sleep mode
Call sleep_enable() before sleep_mode() to allow waking on interrupt.
Final Answer:
attachInterrupt(digitalPinToInterrupt(4), wakeISR, FALLING); sleep_enable(); sleep_mode(); -> Option C