Ofrenda candles on an Arduino Uno
Six LED candles for a Día de los Muertos ofrenda, one for each person remembered: a button lights one at a time, and each flickers on its own PWM pin like a real flame. The whole build, an Arduino Uno and 13 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Ofrenda candles: six candle lights for an ofrenda, the home altar of Día de
// los Muertos. Press the button to light one candle at a time, one for each
// person you are remembering, and each one flickers like a real flame.
//
// candles pins 3, 5, 6, 9, 10, 11 -> 220 ohms -> yellow LED -> GND, six
// button pin 2 -> button -> GND (INPUT_PULLUP)
//
// On Día de los Muertos, on November 1st and 2nd, families in Mexico and
// around the world welcome back the spirits of loved ones who have died. The
// ofrenda holds their photos, their favorite foods, marigolds, sugar skulls
// and candles, often one for each person, to light their way home.
//
// Every candle has its own PWM pin, the six an Uno has, so each can flicker
// on its own: every few milliseconds it picks a brightness near the top,
// with an occasional deeper dip, so no two candles move together. LEDs are a
// good choice for an ofrenda full of paper decorations and dry flowers.
//
// Press the button once more after the sixth and they all fade out together.
//
// Things to try. Press the button six times. Make the flames calmer by
// raising the lowest brightness in flicker().
const int CANDLES = 6;
const int PINS[CANDLES] = {3, 5, 6, 9, 10, 11};
const int BUTTON_PIN = 2;
int lit = 0;
void flicker() {
for (int i = 0; i < CANDLES; i++) {
if (i < lit) {
int v = random(0, 12) == 0 ? random(60, 140) : random(170, 256);
analogWrite(PINS[i], v);
} else {
analogWrite(PINS[i], 0);
}
}
}
void setup() {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP);
for (int i = 0; i < CANDLES; i++) pinMode(PINS[i], OUTPUT);
Serial.println("Ofrenda ready: press the button to light a candle");
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW) {
if (lit < CANDLES) {
lit++;
Serial.print("Candle ");
Serial.print(lit);
Serial.println(" lit");
} else {
for (int v = 200; v >= 0; v -= 5) {
for (int i = 0; i < CANDLES; i++) analogWrite(PINS[i], v);
delay(20);
}
lit = 0;
Serial.println("All candles out");
}
while (digitalRead(BUTTON_PIN) == LOW) flicker();
delay(50);
}
flicker();
delay(random(40, 90));
}
Parts list
15 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Arduino Uno R3
- 1 × Full-size breadboard
- 6 × Resistor, 220 Ω
- 6 × LED, yellow
- 1 × Pushbutton
How it is wired
14 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Arduino Uno R3 pin 11; Resistor, 220 Ω (6) pin 1
- Arduino Uno R3 pin 10; Resistor, 220 Ω (5) pin 1
- Arduino Uno R3 pin 9; Resistor, 220 Ω (4) pin 1
- Arduino Uno R3 pin 6; Resistor, 220 Ω (3) pin 1
- Arduino Uno R3 pin 5; Resistor, 220 Ω (2) pin 1
- Arduino Uno R3 pin 3; Resistor, 220 Ω (1) pin 1
- Arduino Uno R3 pin 2; Pushbutton pin 1a
- Ground: Arduino Uno R3 pin GND; LED, yellow (1) pin C; LED, yellow (2) pin C; LED, yellow (3) pin C; LED, yellow (4) pin C; LED, yellow (5) pin C; LED, yellow (6) pin C; Pushbutton pin 2a
- Resistor, 220 Ω (1) pin 2; LED, yellow (1) pin A
- Resistor, 220 Ω (2) pin 2; LED, yellow (2) pin A
- Resistor, 220 Ω (3) pin 2; LED, yellow (3) pin A
- Resistor, 220 Ω (4) pin 2; LED, yellow (4) pin A
- Resistor, 220 Ω (5) pin 2; LED, yellow (5) pin A
- Resistor, 220 Ω (6) pin 2; LED, yellow (6) pin A
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.