Bird
Raised Fist0
Arduinoprogramming~20 mins

LED blink pattern in Arduino - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
LED Blink 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 LED blink code?
Consider the following Arduino code that blinks an LED connected to pin 13. What will be the LED's behavior?
Arduino
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(500);
}
AThe LED turns on for 0.5 seconds, then off for 0.5 seconds, repeatedly.
BThe LED stays off continuously without blinking.
CThe LED blinks very fast, about every 0.1 seconds.
DThe LED stays on continuously without blinking.
Attempts:
2 left
💡 Hint
Look at the delay times and the order of turning the LED on and off.
Predict Output
intermediate
2:00remaining
What is the LED blink pattern of this code?
Analyze this Arduino code. What pattern will the LED on pin 13 follow?
Arduino
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(200);
}
AThe LED blinks on and off every 0.5 seconds.
BThe LED is on for 0.2 seconds and off for 1 second repeatedly.
CThe LED stays on continuously.
DThe LED is on for 1 second and off for 0.2 seconds repeatedly.
Attempts:
2 left
💡 Hint
Check the delay times after turning the LED on and off.
🔧 Debug
advanced
2:00remaining
What error does this LED blink code cause?
Look at this Arduino code snippet. What error will occur when compiling or running it?
Arduino
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(500);
}
ANo error, code runs and blinks LED correctly
BSyntaxError due to missing semicolon after pinMode(13, OUTPUT)
CSyntaxError due to missing curly braces in loop function
DRuntime error because pin 13 is not set as output
Attempts:
2 left
💡 Hint
Check punctuation carefully in the setup function.
Predict Output
advanced
2:00remaining
What is the LED blink pattern of this code with variable delay?
What pattern will the LED on pin 13 follow when running this Arduino code?
Arduino
int delayTime = 200;

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

void loop() {
  digitalWrite(13, HIGH);
  delay(delayTime);
  digitalWrite(13, LOW);
  delay(delayTime * 2);
}
ALED blinks on and off every 0.2 seconds.
BLED on for 0.4 seconds, off for 0.2 seconds repeatedly.
CLED on for 0.2 seconds, off for 0.4 seconds repeatedly.
DLED stays on continuously.
Attempts:
2 left
💡 Hint
Look at how delayTime is used for on and off durations.
Predict Output
expert
3:00remaining
What is the LED blink pattern of this code with nested loops?
Analyze this Arduino code. What is the total number of LED blinks before the pattern repeats?
Arduino
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  for (int i = 0; i < 3; i++) {
    digitalWrite(13, HIGH);
    delay(300);
    digitalWrite(13, LOW);
    delay(300);
  }
  delay(1000);
}
AThe LED blinks 6 times continuously without pause.
BThe LED blinks 3 times, then pauses for 1 second before repeating.
CThe LED blinks once, then pauses for 1 second before repeating.
DThe LED blinks 3 times with no pause before repeating.
Attempts:
2 left
💡 Hint
Count how many times the loop runs and the delays involved.

Practice

(1/5)
1. What does the delay(1000); command do in an Arduino LED blink program?
easy
A. Pauses the program for 1000 milliseconds (1 second)
B. Turns the LED on for 1000 milliseconds
C. Turns the LED off for 1000 milliseconds
D. Sets the LED brightness to 1000

Solution

  1. Step 1: Understand the delay function

    The delay() function pauses the program for the given time in milliseconds.
  2. Step 2: Interpret the argument 1000

    1000 milliseconds equals 1 second, so the program waits for 1 second before continuing.
  3. Final Answer:

    Pauses the program for 1000 milliseconds (1 second) -> Option A
  4. Quick Check:

    delay(1000) = 1 second pause [OK]
Hint: delay(ms) pauses program for ms milliseconds [OK]
Common Mistakes:
  • Thinking delay turns LED on or off
  • Confusing delay time with brightness
  • Assuming delay is in seconds
2. Which of the following is the correct syntax to set pin 13 as an output in Arduino?
easy
A. pinMode(OUTPUT, 13);
B. pinMode(13, OUTPUT);
C. digitalWrite(13, OUTPUT);
D. digitalWrite(OUTPUT, 13);

Solution

  1. Step 1: Recall pinMode syntax

    The correct syntax is pinMode(pin, mode); where pin is the pin number and mode is INPUT or OUTPUT.
  2. Step 2: Match the correct order

    pinMode(13, OUTPUT); uses pinMode(13, OUTPUT); which matches the correct order and parameters.
  3. Final Answer:

    pinMode(13, OUTPUT); -> Option B
  4. Quick Check:

    pinMode(pin, OUTPUT) sets pin as output [OK]
Hint: pinMode(pin, OUTPUT) sets pin as output [OK]
Common Mistakes:
  • Swapping pin and mode parameters
  • Using digitalWrite instead of pinMode to set mode
  • Missing semicolon at end
3. What will be the output of this Arduino code snippet?
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(500);
}
medium
A. LED on pin 13 blinks on and off every 0.5 seconds
B. LED on pin 13 stays on continuously
C. LED on pin 13 stays off continuously
D. LED on pin 13 blinks on and off every 1 second

Solution

  1. Step 1: Analyze the delay times

    The LED is turned on, then the program waits 500 ms, then turned off, then waits 500 ms again.
  2. Step 2: Calculate total blink cycle

    On time + off time = 500 ms + 500 ms = 1000 ms (1 second) per full blink cycle. Each on or off state lasts 0.5 seconds.
  3. Final Answer:

    LED on pin 13 blinks on and off every 1 second -> Option D
  4. Quick Check:

    delay(500) means 0.5 second blink intervals [OK]
Hint: Sum delays to find blink cycle time [OK]
Common Mistakes:
  • Confusing total blink time with single delay
  • Ignoring delay after turning LED off
  • Assuming delay is in seconds
4. Identify the error in this Arduino code that tries to blink an LED on pin 13:
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(1000)
  digitalWrite(13, LOW);
  delay(1000);
}
medium
A. Missing semicolon after delay(1000)
B. pinMode should be in loop()
C. digitalWrite needs pinMode first
D. delay cannot be used in loop()

Solution

  1. Step 1: Check syntax line by line

    Look at each statement for missing semicolons or syntax errors.
  2. Step 2: Find missing semicolon

    The line delay(1000) is missing a semicolon at the end, causing a syntax error.
  3. Final Answer:

    Missing semicolon after delay(1000) -> Option A
  4. Quick Check:

    Every statement must end with ; [OK]
Hint: Check each line ends with semicolon [OK]
Common Mistakes:
  • Putting pinMode inside loop instead of setup
  • Thinking delay can't be used in loop
  • Ignoring missing semicolon errors
5. You want an LED on pin 13 to blink twice quickly, then pause for 2 seconds, and repeat. Which code snippet achieves this pattern?
hard
A. digitalWrite(13, HIGH); delay(200); digitalWrite(13, LOW); delay(200); delay(2000);
B. for(int i=0; i<2; i++) { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } delay(2000);
C. for(int i=0; i<2; i++) { digitalWrite(13, HIGH); delay(200); digitalWrite(13, LOW); delay(200); } delay(2000);
D. digitalWrite(13, HIGH); delay(500); digitalWrite(13, LOW); delay(500); delay(2000);

Solution

  1. Step 1: Understand the blink pattern

    The LED should blink twice quickly (short on/off), then pause 2 seconds before repeating.
  2. Step 2: Analyze each option's timing

    for(int i=0; i<2; i++) { digitalWrite(13, HIGH); delay(200); digitalWrite(13, LOW); delay(200); } delay(2000); blinks twice with 200 ms on and off delays, then pauses 2000 ms. This matches the pattern.
  3. Step 3: Check other options

    digitalWrite(13, HIGH); delay(200); digitalWrite(13, LOW); delay(200); delay(2000); blinks once only. for(int i=0; i<2; i++) { digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } delay(2000); blinks twice but with 1 second delays (too slow). digitalWrite(13, HIGH); delay(500); digitalWrite(13, LOW); delay(500); delay(2000); blinks once with 500 ms delays.
  4. Final Answer:

    for(int i=0; i<2; i++) { digitalWrite(13, HIGH); delay(200); digitalWrite(13, LOW); delay(200); } delay(2000); -> Option C
  5. Quick Check:

    Loop twice fast blinks + long pause = for(int i=0; i<2; i++) { digitalWrite(13, HIGH); delay(200); digitalWrite(13, LOW); delay(200); } delay(2000); [OK]
Hint: Use loop for repeated quick blinks, then delay for pause [OK]
Common Mistakes:
  • Using delay too long for quick blinks
  • Not looping for multiple blinks
  • Pausing before blinking instead of after