Runs your sketch
Arduino
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 |
Random flicker like a real flame!
random() picks different delay() times so the glow feels alive.
Fake candles and fire effects use random timing.
The problem
A steady blink feels robotic — you want organic flicker.
Think of it like
Like a candle flame — never blinks on the exact same beat.
Runs your sketch
Arduino
Brain
Limits current to the LED
Resistor
Safety
Shows output from the code
LED
Light
Quick glow
random(20, 80) picks a different short ON time every pass — not a fixed blink.
digitalWrite(LED_PIN, HIGH); delay(random(20, 80));
Quick dim
OFF time is random too, so the rhythm feels uneven like a flame.
digitalWrite(LED_PIN, LOW); delay(random(10, 40));
Sometimes brighter
About 30% of the time the candle adds an extra bright pulse, 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!
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.
Random seed
void setup() {
pinMode(LED_PIN, OUTPUT);
randomSeed(analogRead(0));
}randomSeed() in setup() makes random() give different flicker each run. pinMode prepares the LED output.
Random flicker
void loop() {
digitalWrite(LED_PIN, HIGH);
delay(random(20, 80));
digitalWrite(LED_PIN, LOW);
delay(random(10, 40));Each delay(random(...)) picks new wait times — that is what makes the candle feel alive.
Bonus bright pulse
if (random(0, 10) > 7) {
digitalWrite(LED_PIN, HIGH);
delay(random(100, 300));
}The if block sometimes adds a longer glow — like a flame jumping.
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. Where does repeating work belong?
Q2. Why use random() inside delay() here?
Make flicker snappier — lower the random ON range to random(10, 50) on line 8.
Hint: Edit both numbers inside random(20, 80).
Add a comment on the randomSeed line explaining why we need it.
Hint: Line 4 in setup().
A line-by-line tour of the sketch — the same steps as in Robo Gurukul Studio.
Program overview
Technical
Sketches have globals, then setup() once, then loop() forever.
In this project
Flicker an LED with random delay() timing like a candle flame.
Why here
Read from top to bottom. Hover words or lines for help!
const int LED_PIN = 13;
setup()
Technical
Runs one time when the board turns on.
In this project
Sets up pins and libraries for Electronic Candle.
Why here
One-time setup belongs here—not in loop().
void setup() {
pinMode(LED_PIN, OUTPUT);
randomSeed(analogRead(0));
}loop()
Technical
Runs again and again after setup() is done.
In this project
This is the main action you see in Electronic Candle.
Why here
Repeating work (blink, read sensors) goes here.
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 numbers in loop(), then compile and run the simulator.
pinMode
Technical
Tells a pin if it listens or drives something.
In this project
Gets the Electronic Candle circuit ready in the simulator.
Why here
Goes in setup() because we only set pins once at the start.
pinMode(LED_PIN, OUTPUT);
digitalWrite
Technical
Turns a pin ON or OFF.
In this project
Controls lights, motors, or buzzers in Electronic Candle.
Why here
Goes in loop() so it can keep changing while the program runs.
digitalWrite(LED_PIN, HIGH);
analogRead
Technical
Reads a sensor number from 0 to 1023.
In this project
Turns a sensor signal into a number for Electronic Candle.
Why here
Goes in loop() to keep checking the sensor.
randomSeed(analogRead(0));
delay
Technical
Waits for some time. Nothing else runs during the wait.
In this project
Controls speed so you can see Electronic Candle in the simulator.
Why here
Right after an action that should stay the same for a moment.
delay(random(20, 80));
random
Technical
Picks a random number in a range.
In this project
Adds randomness in Electronic Candle.
Why here
In loop() when you want different values each time.
delay(random(20, 80));