0
0
Arduinoprogramming~20 mins

Documentation and pin mapping in Arduino - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pin Mapping Master
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 pin mapping code?

Consider the following Arduino code that maps pins and prints their states. What will be printed on the serial monitor?

Arduino
const int ledPin = 13;
const int buttonPin = 7;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  Serial.begin(9600);
}

void loop() {
  int buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) {
    digitalWrite(ledPin, HIGH);
    Serial.println("LED ON");
  } else {
    digitalWrite(ledPin, LOW);
    Serial.println("LED OFF");
  }
  delay(1000);
}
ALED ON always, no output printed
BLED OFF always, no output printed
CLED ON (if button pressed), LED OFF (if not pressed) every second
DSyntax error due to missing semicolon
Attempts:
2 left
💡 Hint

Remember that INPUT_PULLUP mode means the button reads HIGH when not pressed and LOW when pressed.

🧠 Conceptual
intermediate
1:00remaining
Which Arduino pin is best for PWM output?

Given an Arduino Uno, which pin below is typically used for PWM (Pulse Width Modulation) output?

APin 13
BPin 0
CPin 7
DPin 9
Attempts:
2 left
💡 Hint

Look for pins marked with a tilde (~) on the Arduino board.

🔧 Debug
advanced
2:00remaining
Why does this Arduino code fail to turn on the LED?

Examine the code below. The LED connected to pin 8 never turns on. What is the reason?

Arduino
int ledPin = 8;

void setup() {
  pinMode(ledPin, INPUT);
}

void loop() {
  digitalWrite(ledPin, HIGH);
}
AMissing semicolon after pinMode line
BThe pinMode is set to INPUT, so digitalWrite has no effect
CLED is connected to wrong pin number
DdigitalWrite should be called in setup, not loop
Attempts:
2 left
💡 Hint

Think about the difference between INPUT and OUTPUT pin modes.

📝 Syntax
advanced
1:30remaining
What error does this Arduino code produce?

Look at the code snippet below. What error will the Arduino IDE show when compiling?

Arduino
const int ledPin = 13;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  delay(1000);
}
ASyntax error: missing semicolon after const int ledPin = 13
BType error: ledPin must be declared as volatile
CRuntime error: delay function not defined
DNo error, code compiles and runs correctly
Attempts:
2 left
💡 Hint

Check the end of each statement for proper punctuation.

🚀 Application
expert
2:30remaining
How many pins are configured as OUTPUT after this Arduino setup?

Given the following Arduino setup code, how many pins are set as OUTPUT?

Arduino
const int pins[] = {2, 3, 4, 5, 6};

void setup() {
  for (int i = 0; i < 5; i++) {
    if (pins[i] % 2 == 0) {
      pinMode(pins[i], OUTPUT);
    } else {
      pinMode(pins[i], INPUT);
    }
  }
}

void loop() {}
A3
B0
C5
D2
Attempts:
2 left
💡 Hint

Count how many pins in the array are even numbers.