We use LED blink patterns to show simple signals or messages with lights. It helps us learn how to control hardware step by step.
LED blink pattern in Arduino
Introduction
Syntax
Arduino
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn LED on
delay(1000); // wait 1 second
digitalWrite(LED_BUILTIN, LOW); // turn LED off
delay(1000); // wait 1 second
}pinMode sets the LED pin as output so we can control it.
digitalWrite turns the LED on or off.
Examples
Arduino
digitalWrite(LED_BUILTIN, HIGH); // LED on
delay(500); // wait half a second
digitalWrite(LED_BUILTIN, LOW); // LED off
Arduino
for (int i = 0; i < 3; i++) { digitalWrite(LED_BUILTIN, HIGH); delay(300); digitalWrite(LED_BUILTIN, LOW); delay(300); }
Sample Program
This program makes the LED blink three times quickly, then waits for one second before repeating the pattern.
Arduino
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// Blink pattern: 3 quick blinks, then pause
for (int i = 0; i < 3; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(200);
digitalWrite(LED_BUILTIN, LOW);
delay(200);
}
delay(1000); // pause before repeating
}Important Notes
Use delay() to control how long the LED stays on or off.
LED_BUILTIN is the built-in LED on most Arduino boards, usually on pin 13.
Changing the delay times changes the blink speed and pattern.
Summary
LED blink patterns help us communicate simple signals with light.
Use digitalWrite and delay to create blink effects.
Loops let us repeat blink sequences easily.
Practice
1. What does the
delay(1000); command do in an Arduino LED blink program?easy
Solution
Step 1: Understand the delay function
Thedelay()function pauses the program for the given time in milliseconds.Step 2: Interpret the argument 1000
1000 milliseconds equals 1 second, so the program waits for 1 second before continuing.Final Answer:
Pauses the program for 1000 milliseconds (1 second) -> Option AQuick 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
Solution
Step 1: Recall pinMode syntax
The correct syntax ispinMode(pin, mode);where pin is the pin number and mode is INPUT or OUTPUT.Step 2: Match the correct order
pinMode(13, OUTPUT); usespinMode(13, OUTPUT);which matches the correct order and parameters.Final Answer:
pinMode(13, OUTPUT); -> Option BQuick 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
Solution
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.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.Final Answer:
LED on pin 13 blinks on and off every 1 second -> Option DQuick 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
Solution
Step 1: Check syntax line by line
Look at each statement for missing semicolons or syntax errors.Step 2: Find missing semicolon
The linedelay(1000)is missing a semicolon at the end, causing a syntax error.Final Answer:
Missing semicolon after delay(1000) -> Option AQuick 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
Solution
Step 1: Understand the blink pattern
The LED should blink twice quickly (short on/off), then pause 2 seconds before repeating.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.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.Final Answer:
for(int i=0; i<2; i++) { digitalWrite(13, HIGH); delay(200); digitalWrite(13, LOW); delay(200); } delay(2000); -> Option CQuick 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
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
