0
0
Arduinoprogramming~20 mins

Why project structure matters in Arduino - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Arduino Project Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Arduino sketch?

Consider this Arduino code that blinks an LED connected to pin 13. What will be printed on the Serial Monitor?

Arduino
void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  Serial.println("LED ON");
  delay(1000);
  digitalWrite(13, LOW);
  Serial.println("LED OFF");
  delay(1000);
}
ALED OFF\nLED OFF\nLED OFF\nLED OFF\n... (repeats every second)
BLED ON\nLED ON\nLED ON\nLED ON\n... (repeats every second)
CLED ON\nLED OFF\nLED ON\nLED OFF\n... (repeats every second)
DNo output on Serial Monitor
Attempts:
2 left
💡 Hint

Look at the Serial.println calls inside the loop() function.

🧠 Conceptual
intermediate
1:30remaining
Why organize Arduino code into separate files?

Which of the following is the best reason to split Arduino code into multiple files (like separate .ino or .h/.cpp files)?

ATo make the Arduino run faster by loading files separately
BTo reduce the size of the compiled program automatically
CTo prevent the Arduino IDE from compiling the code
DTo make the code easier to read and maintain by grouping related functions
Attempts:
2 left
💡 Hint

Think about how organizing papers in folders helps you find things faster.

🔧 Debug
advanced
2:30remaining
Why does this Arduino sketch fail to compile?

Look at this Arduino sketch split into two files. Why does it fail to compile?

// File: main.ino
#include "led_control.h"

void setup() {
  initLED();
}

void loop() {
  toggleLED();
  delay(500);
}

// File: led_control.h
void initLED();
void toggleLED();

// File: led_control.cpp
#include 

void initLED() {
  pinMode(13, OUTPUT);
}

void toggleLED() {
  static bool state = false;
  state = !state;
  digitalWrite(13, state);
}
AThe pinMode function is called inside loop instead of setup
BThe led_control.cpp file is missing from the project or not compiled
CThe functions initLED and toggleLED are not declared in led_control.h
DThe digitalWrite function requires a delay before toggling
Attempts:
2 left
💡 Hint

Check if all files are included and compiled by the Arduino IDE.

📝 Syntax
advanced
1:30remaining
Which option causes a syntax error in Arduino code?

Which of these code snippets will cause a syntax error when compiling an Arduino sketch?

Avoid setup() { pinMode(13, OUTPUT) } void loop() { digitalWrite(13, HIGH); delay(1000); }
B} ;)0001(yaled ;)HGIH ,31(etirWlatigid { )(pool diov } ;)TUPTUO ,31(edoMnip { )(putes diov
Coid setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); }
Dvoid setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(1000); }
Attempts:
2 left
💡 Hint

Look carefully for missing semicolons.

🚀 Application
expert
3:00remaining
How many functions are in this well-structured Arduino project?

Given this Arduino project with three files, how many unique functions are defined?

// main.ino
#include "sensor.h"
#include "display.h"

void setup() {
  initSensor();
  initDisplay();
}

void loop() {
  int value = readSensor();
  showValue(value);
  delay(1000);
}

// sensor.h
void initSensor();
int readSensor();

// sensor.cpp
#include 
void initSensor() { /* setup sensor pins */ }
int readSensor() { return analogRead(A0); }

// display.h
void initDisplay();
void showValue(int val);

// display.cpp
#include 
void initDisplay() { /* setup display */ }
void showValue(int val) { /* display val */ }
A4
B5
C3
D6
Attempts:
2 left
💡 Hint

Count all unique function definitions across all files.