Challenge - 5 Problems
Delay Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output timing behavior of delay()?
Consider this Arduino code snippet. What will be the timing behavior of the LED blinking?
Arduino
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}Attempts:
2 left
💡 Hint
Think about what delay(1000) means in milliseconds.
✗ Incorrect
The delay(1000) pauses the program for 1000 milliseconds (1 second). So the LED turns on, waits 1 second, turns off, waits 1 second, then repeats.
❓ Predict Output
intermediateWhat happens if delay(0) is used?
What is the effect of calling delay(0) in an Arduino sketch?
Arduino
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(0);
digitalWrite(LED_BUILTIN, LOW);
delay(0);
}Attempts:
2 left
💡 Hint
Think about what a zero millisecond delay means.
✗ Incorrect
delay(0) means no delay, so the loop runs as fast as possible toggling the LED on and off quickly.
❓ Predict Output
advancedWhat is the output of this code with nested delays?
Analyze the timing of the LED blinking in this code:
Arduino
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}Attempts:
2 left
💡 Hint
Add the delays when the LED is on.
✗ Incorrect
The two delay(500) calls add up to 1000 ms while LED is on, then delay(1000) while off.
❓ Predict Output
advancedWhat error occurs if delay() is called with a negative value?
What happens if you write delay(-100) in an Arduino sketch?
Arduino
void loop() {
delay(-100);
}Attempts:
2 left
💡 Hint
Check how delay() handles unsigned integers internally.
✗ Incorrect
delay() takes an unsigned long, so negative values convert to large positive numbers (e.g., ~4.29 billion ms for -100), causing a very long delay.
🧠 Conceptual
expertWhy does delay() block other code execution?
Explain why using delay() in Arduino sketches can cause problems with multitasking or reading sensors frequently.
Attempts:
2 left
💡 Hint
Think about what happens to the program flow during delay().
✗ Incorrect
delay() is a blocking function that stops the program from doing anything else until the time passes, so other tasks cannot run simultaneously.
