Bird
Raised Fist0
Arduinoprogramming~10 mins

LED blink pattern in Arduino - Step-by-Step Execution

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
Concept Flow - LED blink pattern
Start setup
Set LED pin as OUTPUT
Enter loop
Turn LED ON
Wait delay
Turn LED OFF
Wait delay
Back to loop start
The program sets up the LED pin, then repeatedly turns the LED on and off with delays to create a blinking pattern.
Execution Sample
Arduino
void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(500);
}
This code makes the LED on pin 13 blink on and off every 500 milliseconds.
Execution Table
StepActionPin 13 StateDelay (ms)Next Step
1Setup: pinMode(13, OUTPUT)LOW (default)0Go to loop
2digitalWrite(13, HIGH)HIGH (LED ON)0Wait 500 ms
3delay(500)HIGH (LED ON)500digitalWrite LOW
4digitalWrite(13, LOW)LOW (LED OFF)0Wait 500 ms
5delay(500)LOW (LED OFF)500Repeat loop
6Repeat loopLOW (LED OFF)0digitalWrite HIGH
...Cycle repeatsAlternates HIGH/LOW500 each delayContinues blinking
💡 The loop runs forever, so the LED keeps blinking continuously.
Variable Tracker
VariableStartAfter Step 2After Step 4After Step 6Final
Pin 13 StateLOW (default)HIGH (LED ON)LOW (LED OFF)HIGH (LED ON)Alternates HIGH/LOW
Key Moments - 3 Insights
Why does the LED keep blinking and not stop?
Because the code is inside the loop() function which runs forever, as shown in execution_table rows 5 and 6.
What does delay(500) do in the blink pattern?
It pauses the program for 500 milliseconds, keeping the LED ON or OFF for that time, as seen in execution_table rows 3 and 5.
Why do we set pinMode(13, OUTPUT) in setup()?
To tell the Arduino that pin 13 will send signals to control the LED, as shown in execution_table row 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the state of pin 13 after step 4?
AHIGH (LED ON)
BUndefined
CLOW (LED OFF)
DBlinking
💡 Hint
Check the 'Pin 13 State' column at step 4 in the execution_table.
At which step does the program wait for 500 milliseconds while the LED is ON?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look for delay(500) with LED ON in the execution_table.
If delay(500) is changed to delay(1000), how does the blink pattern change?
ALED blinks slower
BLED blinks faster
CLED stays ON permanently
DLED stays OFF permanently
💡 Hint
Longer delay means longer ON and OFF times, check delay column in execution_table.
Concept Snapshot
Arduino LED Blink Pattern:
- Use pinMode(pin, OUTPUT) in setup() to set LED pin.
- In loop(), turn LED ON with digitalWrite(pin, HIGH).
- Wait with delay(milliseconds).
- Turn LED OFF with digitalWrite(pin, LOW).
- Wait again with delay(milliseconds).
- Loop repeats forever creating blink.
Full Transcript
This Arduino program controls an LED connected to pin 13. First, it sets pin 13 as an output in the setup function. Then, inside the loop function, it turns the LED on by setting pin 13 HIGH, waits 500 milliseconds, turns the LED off by setting pin 13 LOW, and waits another 500 milliseconds. This cycle repeats forever, causing the LED to blink on and off every half second. The delay function pauses the program to keep the LED in each state long enough to see the blink. The loop function runs endlessly, so the blinking continues without stopping.

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