Challenge - 5 Problems
Arduino Sketch Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat happens when you upload this sketch?
Consider this Arduino sketch. What will the LED connected to pin 13 do after uploading and running this code?
Arduino
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}Attempts:
2 left
💡 Hint
Look at the loop function and the delay times.
✗ Incorrect
The loop turns the LED on, waits 1 second, turns it off, waits 1 second, then repeats. This causes blinking every second.
❓ Predict Output
intermediateWhat is the output on the Serial Monitor?
What will be printed on the Serial Monitor when this sketch is uploaded and run?
Arduino
void setup() {
Serial.begin(9600);
Serial.println("Start");
}
void loop() {
Serial.println("Running");
delay(500);
}Attempts:
2 left
💡 Hint
Check where Serial.println is called inside the loop.
✗ Incorrect
Serial.println("Running") is inside loop(), so it prints repeatedly every 0.5 seconds after printing "Start" once in setup().
🔧 Debug
advancedWhy does this sketch fail to upload?
This sketch fails to upload to the Arduino board. What is the cause?
Arduino
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
}Attempts:
2 left
💡 Hint
Check punctuation carefully in setup().
✗ Incorrect
The line pinMode(13, OUTPUT) is missing a semicolon at the end, causing a syntax error that prevents uploading.
❓ Predict Output
advancedWhat is the state of pin 12 after running this sketch?
After uploading and running this sketch, what will be the voltage state of pin 12?
Arduino
void setup() {
pinMode(12, OUTPUT);
digitalWrite(12, HIGH);
}
void loop() {
// empty loop
}Attempts:
2 left
💡 Hint
Check what happens in setup() and if loop() changes pin 12.
✗ Incorrect
Pin 12 is set as OUTPUT and immediately set HIGH in setup(). Since loop() does nothing, pin 12 stays HIGH.
🧠 Conceptual
expertWhat happens if you upload a sketch with an empty loop()?
If you upload this sketch to an Arduino, what will be the behavior of the board?
Arduino
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
void loop() {
// empty
}Attempts:
2 left
💡 Hint
Think about what setup() does and what an empty loop() means.
✗ Incorrect
setup() runs once and sets pin 13 HIGH. loop() does nothing, so pin 13 stays HIGH and LED stays on.
