0
0
Arduinoprogramming~10 mins

Reducing power consumption tips in Arduino - 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() {
  // Empty loop
}
Drag options to blanks, or click blank then click option'
ASLEEP_MODE_POWER_DOWN
BSLEEP_MODE_ADC
CSLEEP_MODE_IDLE
DSLEEP_MODE_STANDBY
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a sleep mode that does not reduce power significantly.
2fill in blank
medium

Complete the code to disable the ADC to save power.

Arduino
void setup() {
  ADCSRA [1] 0;
}

void loop() {
  // Main code
}
Drag options to blanks, or click blank then click option'
A|=
B=
C^=
D&=
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR or AND operators which do not clear all bits properly.
3fill in blank
hard

Fix the error in the code to turn off the built-in LED to save power.

Arduino
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, [1]);
}

void loop() {
  // Empty loop
}
Drag options to blanks, or click blank then click option'
AINPUT
BHIGH
CLOW
DOUTPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the pin HIGH which keeps the LED on.
4fill in blank
hard

Fill both blanks to create a dictionary of sensor readings only if the reading is above 100.

Arduino
int readings[] = {120, 90, 150, 80};

void setup() {
  Serial.begin(9600);
  for (int i = 0; i < 4; i++) {
    if (readings[i] [1] 100) {
      Serial.println(readings[i] [2] 2);
    }
  }
}

void loop() {}
Drag options to blanks, or click blank then click option'
A>
B*
C<
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than operator which filters wrong values.
Using addition instead of multiplication.
5fill in blank
hard

Fill all three blanks to create a map of sensor names to values only if the value is positive.

Arduino
String sensors[] = {"temp", "light", "sound"};
int values[] = {25, -5, 10};

void setup() {
  Serial.begin(9600);
  for (int i = 0; i < 3; i++) {
    if (values[i] [3] 0) {
      Serial.print(sensors[i].[1]());
      Serial.print(": ");
      Serial.println(values[i] [2] 1);
    }
  }
}

void loop() {}
Drag options to blanks, or click blank then click option'
AtoUpperCase
B*
C>
DtoLowerCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using toUpperCase instead of toLowerCase.
Using addition instead of multiplication.