It thinks and tells the light when to flicker.
Arduino
The brain
flicker timing with delay()
Flicker an LED with random delay() timing like a candle flame.

Pin connections
| Part 1 | Part 2 | |
|---|---|---|
Arduino pin 13 | → | Resistor pin 2 |
Resistor pin 1 | → | LED anode (+) |
LED cathode (-) | → | Arduino GND |
Let's make a flickering candle!
A little light dances and flickers all by itself, just like a real flame.
Pretend candles and fake fireplaces flicker exactly like this!
The problem
A steady blink looks like a robot. A real candle wobbles and flickers in surprise ways.
Think of it like
It's like a candle flame in the wind — it never dances the exact same way twice.
It thinks and tells the light when to flicker.
Arduino
The brain
Slows the power down so the light does not get hurt.
Resistor
The protector
A tiny light that glows like a candle.
LED
The flame
A quick glow
The light turns on and waits a surprise amount of time — never the same blink twice.
digitalWrite(LED_PIN, HIGH); delay(random(20, 80));
A quick dim
The light goes dim for another surprise wait, so the rhythm feels wobbly like a flame.
digitalWrite(LED_PIN, LOW); delay(random(10, 40));
Sometimes a big flare
Once in a while the candle adds an extra bright glow — like the flame jumping! Then loop() flickers again.
if (random(0, 10) > 7) { ... longer glow ... }Then loop back to step 1
Follow these steps in order. Match the wires to the colors shown.
Place Arduino
Place the Arduino (uno) on the breadboard.
Arduino placed — ready to build!
Place Resistor
Place the Resistor (r1) on the breadboard.
Place LED
Place the LED (led1) on the breadboard.
Connect Arduino pin 13 to Resistor (r1) 2
Connect Arduino pin 13 to Resistor (r1) 2.
Connect Resistor (r1) 1 to LED (led1) anode (+)
Connect Resistor (r1) 1 to LED (led1) anode (+).
Connect LED (led1) cathode (-) to Arduino GND
Connect LED (led1) cathode (-) to Arduino GND.
Get ready and shake the dice
void setup() {
pinMode(LED_PIN, OUTPUT);
randomSeed(analogRead(0));
}setup() gets pin 13 ready, and randomSeed shakes up the surprise numbers so each run flickers differently.
The flicker
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(random(20, 80));
digitalWrite(LED_PIN, LOW);
delay(random(10, 40));Each wait is a surprise number, so the light flickers fast and slow — that is what makes it look alive.
The bonus flare
if (random(0, 10) > 7) {
digitalWrite(LED_PIN, HIGH);
delay(random(100, 300));
}Once in a while this part adds a longer, brighter glow — like the candle flame leaping up.
const int LED_PIN = 13;
void setup() {
pinMode(LED_PIN, OUTPUT);
randomSeed(analogRead(0));
}
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(random(20, 80));
digitalWrite(LED_PIN, LOW);
delay(random(10, 40));
if (random(0, 10) > 7) {
digitalWrite(LED_PIN, HIGH);
delay(random(100, 300));
}
}
Q1. Which part runs again and again?
Q2. Why do we use random() inside delay() here?
Make the flicker snappier — change random(20, 80) to random(10, 50) on line 8.
Hint: Edit both numbers inside random(20, 80).
Add a little note (comment) on the line that shakes up the surprise numbers.
Hint: Type // and your words at the end of line 4.
A line-by-line tour of the sketch — the same steps as in Robot Gurukul Studio.
Program overview
Big idea
Every Arduino program has a top part, a setup() part that runs once, and a loop() part that runs again and again.
In this project
A light flickers with surprise timing so it looks like a real candle.
Tip
Read from the top to the bottom. Tap any word or line if you need help!
const int LED_PIN = 13;
setup()
Big idea
setup() runs one time when the board turns on.
In this project
It gets pin 13 ready for the light and shakes up the surprise numbers.
Why here
Things we do only once go inside setup().
void setup() {
pinMode(LED_PIN, OUTPUT);
randomSeed(analogRead(0));
}loop()
Big idea
loop() runs again and again, forever.
In this project
This is where the light flickers fast and slow, never the same way twice.
Why here
Things that repeat go inside loop().
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(random(20, 80));
digitalWrite(LED_PIN, LOW);
delay(random(10, 40));
if (random(0, 10) > 7) {
digitalWrite(LED_PIN, HIGH);
delay(random(100, 300));
}
}
Try this: Change a number inside loop(), then press Run to make the flicker faster or slower.
pinMode
Big idea
pinMode tells a pin if it will listen or push power out.
In this project
It makes pin 13 ready to push power to the light.
Why here
It goes in setup() because we only set it once.
pinMode(LED_PIN, OUTPUT);
digitalWrite
Big idea
digitalWrite turns a pin ON or OFF.
In this project
ON lights up the candle, OFF makes it dim.
Why here
It goes in loop() so the light can keep flickering.
digitalWrite(LED_PIN, HIGH);
analogRead
Big idea
analogRead reads a number from a pin — anything from 0 to 1023.
In this project
It reads a tiny bit of noise from pin 0 to help pick fresh surprise numbers.
Why here
In setup(), to shake up the randomness before the candle starts.
randomSeed(analogRead(0));
delay
Big idea
delay means wait. Nothing else happens while it waits.
In this project
It waits a surprise amount of time so the flicker looks alive.
Why here
Right after we turn the light on or off.
delay(random(20, 80));
random
Big idea
random picks a surprise number inside a range you choose.
In this project
It picks a different wait time each flicker, so no two blinks match.
Why here
In loop(), where we want a new surprise number every time.
delay(random(20, 80));