0
0
Arduinoprogramming~10 mins

Arduino sleep modes - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to put the Arduino into sleep mode.

Arduino
#include <avr/sleep.h>

void setup() {
  Serial.begin(9600);
  set_sleep_mode([1]);
  sleep_enable();
  sleep_cpu();
}

void loop() {
  // Nothing here
}
Drag options to blanks, or click blank then click option'
ASLEEP_MODE_IDLE
BSLEEP_MODE_PWR_DOWN
CSLEEP_MODE_ADC
DSLEEP_MODE_STANDBY
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a lighter sleep mode that doesn't save much power.
2fill in blank
medium

Complete the code to disable sleep mode after waking up.

Arduino
void wakeUp() {
  sleep_disable();
  Serial.println("Woke up!");
}

void setup() {
  attachInterrupt(digitalPinToInterrupt(2), wakeUp, [1]);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_cpu();
}

void loop() {
  // Sleep until interrupt
}
Drag options to blanks, or click blank then click option'
ALOW
BCHANGE
CRISING
DFALLING
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOW, which triggers continuously while the pin is held low.
3fill in blank
hard

Fix the error in the code to correctly enter sleep mode.

Arduino
#include <avr/sleep.h>

void setup() {
  Serial.begin(9600);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  [1]();
  sleep_cpu();
}

void loop() {
  // Sleep here
}
Drag options to blanks, or click blank then click option'
Asleep_enable
Bsleep_mode
Csleep_disable
Dsleep_set
Attempts:
3 left
💡 Hint
Common Mistakes
Calling sleep_disable() instead of sleep_enable().
4fill in blank
hard

Fill both blanks to create a dictionary of sleep modes and their descriptions.

Arduino
const char* sleepModes[] = {"[1]", "[2]"};

void setup() {
  Serial.begin(9600);
  Serial.println(sleepModes[0]);
  Serial.println(sleepModes[1]);
}

void loop() {}
Drag options to blanks, or click blank then click option'
ASLEEP_MODE_IDLE
BSLEEP_MODE_PWR_SAVE
CIdle mode
DPower save mode
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing mode names with descriptions incorrectly.
5fill in blank
hard

Fill all three blanks to create a function that sets sleep mode and enters sleep.

Arduino
void enterSleepMode([1] mode) {
  set_sleep_mode([2]);
  [3]();
  sleep_cpu();
}

void setup() {
  Serial.begin(9600);
  enterSleepMode(SLEEP_MODE_PWR_DOWN);
}

void loop() {}
Drag options to blanks, or click blank then click option'
Auint8_t
Bmode
Csleep_enable
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter type or forgetting to enable sleep.