Marigold path on an Arduino Uno
A WS2812B strip glows like a path of marigold petals for Día de los Muertos, with a wave of gold traveling from the door to four LEDs breathing orange at the ofrenda. The whole build, an Arduino Uno and 5 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 About 20 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $37. On Mokxi they're free.
What you'll learn
- Running two LED strips from two pins
- Making a moving wave with a position counter
- Mixing red and green to get orange and gold
- Using a knob to change animation speed
- Fixed-point counting in eighths of an LED
- Difficulty: Beginner
- Time: About 20 minutes
- Board: Arduino Uno R3
- Parts: 7
How it works
Two chains of WS2812B LEDs run from two pins, each through a 330 ohm resistor. Pin 6 drives a path of 16 LEDs, and pin 5 drives an altar of 4. All of them share 5V and ground with a potentiometer on A0.
The whole path glows a soft marigold orange. A brighter wave of gold, 4 LEDs long, moves from LED 0 toward the altar and then starts over. The altar LEDs slowly brighten and dim in deep orange. The knob sets how fast the wave travels, from 1 to 6 units per frame.
Parts list
7 parts, plus the jumper wires. They retail for about $37; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Half breadboard
- 1 × PotentiometerIn Halloween Prop Kit, Starter Projects Kit, MicroPython Pico Kit.
- 2 × Resistor, 330 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 2 × Addressable RGB LEDsIn Claw Machine Kit, Halloween Prop Kit, Christmas Lights Kit.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Resistor, 330 Ω (1) pin 1 | Arduino Uno R3 pin 6 |
| Resistor, 330 Ω (2) pin 1 | Arduino Uno R3 pin 5 |
| Potentiometer pin 3 | Arduino Uno R3 pin 5V |
| Addressable RGB LEDs (1) pin VDD | Arduino Uno R3 pin 5V |
| Addressable RGB LEDs (2) pin VDD | Arduino Uno R3 pin 5V |
| Potentiometer pin 1 | Arduino Uno R3 pin GND |
| Addressable RGB LEDs (1) pin VSS | Arduino Uno R3 pin GND |
| Addressable RGB LEDs (2) pin VSS | Arduino Uno R3 pin GND |
| Potentiometer pin 2 | Arduino Uno R3 pin A0 |
| Addressable RGB LEDs (1) pin DIN | Resistor, 330 Ω (1) pin 2 |
| Addressable RGB LEDs (2) pin DIN | Resistor, 330 Ω (2) pin 2 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Marigold path: a strip of LEDs laid along the floor like a path of marigold
// petals, with a glow of orange and gold that travels from the door to the
// ofrenda, where a cluster of marigold lights glows warm.
//
// path 16 WS2812B LEDs, DIN <- 330 ohms <- pin 6 (LED 0 at the door)
// altar 4 WS2812B LEDs, DIN <- 330 ohms <- pin 5
// knob potentiometer wiper -> A0, ends to 5 V and GND: the pace
//
// For Día de los Muertos, families scatter petals of cempasúchil, the Mexican
// marigold, in a path from the front door to the ofrenda. Their bright color
// and scent are said to guide the spirits home.
//
// The path glows a soft marigold all along, and a brighter wave of gold
// travels slowly from the door toward the altar, again and again. The altar's
// four LEDs breathe in deep orange. Every LED's color is a mix of red and a
// little less green: that is the whole range from orange to gold.
//
// Things to try. Turn the knob to slow the wave. Make the wave longer with
// WAVE. Lay the strip in a curve around the room.
#include <Adafruit_NeoPixel.h>
const int PATH = 16, ALTAR = 4;
const int WAVE = 4; // how many LEDs the bright wave covers
Adafruit_NeoPixel path(PATH, 6, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel altar(ALTAR, 5, NEO_GRB + NEO_KHZ800);
int head = 0; // in 1/8ths of an LED
unsigned long frames = 0;
void setup() {
Serial.begin(9600);
path.begin();
altar.begin();
path.setBrightness(160);
altar.setBrightness(200);
Serial.println("The marigold path is glowing");
}
void loop() {
int pace = map(analogRead(A0), 0, 1023, 1, 6);
head += pace;
if (head >= (PATH + WAVE) * 8) {
head = 0;
Serial.println("The glow reached the ofrenda");
}
for (int i = 0; i < PATH; i++) {
int r = 120, g = 45; // the resting marigold
int d = head / 8 - i; // how far behind the wave's front
if (d >= 0 && d < WAVE) {
r = 255;
g = 150 - d * 25; // gold at the front, orange behind
}
path.setPixelColor(i, r, g, 0);
}
// The altar breathes slowly between deep orange and gold.
int t = (frames * 3) % 512;
int glow = t < 256 ? t : 511 - t;
for (int i = 0; i < ALTAR; i++) altar.setPixelColor(i, 200 + glow / 5, 60 + glow / 4, 0);
path.show();
altar.show();
frames++;
delay(25);
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Starts serial and both strips, and sets their brightness: 160 for the path and 200 for the altar. Then it prints a message saying the path is glowing.
void setup() {
Serial.begin(9600);
path.begin();
altar.begin();
path.setBrightness(160);
altar.setBrightness(200);
Serial.println("The marigold path is glowing");
}loop sketch.ino
Reads the knob and uses map to turn it into a pace of 1 to 6, then adds that to head, counted in eighths of an LED so slow speeds stay smooth. For each path LED it picks the resting orange, or gold if it is within WAVE LEDs behind the front. The altar's glow rises and falls with a counter. Both strips are shown, then it waits 25 ms.
void loop() {
int pace = map(analogRead(A0), 0, 1023, 1, 6);
head += pace;
if (head >= (PATH + WAVE) * 8) {
head = 0;
Serial.println("The glow reached the ofrenda");
}
for (int i = 0; i < PATH; i++) {
int r = 120, g = 45; // the resting marigold
int d = head / 8 - i; // how far behind the wave's front
if (d >= 0 && d < WAVE) {
r = 255;
g = 150 - d * 25; // gold at the front, orange behind
}
path.setPixelColor(i, r, g, 0);
}
// The altar breathes slowly between deep orange and gold.
int t = (frames * 3) % 512;
int glow = t < 256 ? t : 511 - t;
for (int i = 0; i < ALTAR; i++) altar.setPixelColor(i, 200 + glow / 5, 60 + glow / 4, 0);
path.show();
altar.show();
frames++;
delay(25);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- One strip stays dark. This project
The path data comes from pin 6 and the altar from pin 5, each through its own 330 ohm resistor to DIN. - The wave does not change speed. This project
Check the potentiometer: its ends go to 5V and GND and the middle pin goes to A0. - The reading jumps around or only covers part of the range. Potentiometer
Wire the two outer legs to 5 V and ground and the middle leg (the wiper) to an analog pin. Using the wrong two legs gives a dead or partial range. - Turning the knob does nothing, or the value is stuck at 0 or 1023. Potentiometer
Check that the wiper goes to an analog input (A0 to A5 on an Uno), not a digital pin. Make sure both ends are connected, since a floating end gives noise. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure. - A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground. - The first LED flickers, shows wrong colors, or the whole strip glitches. Addressable RGB LEDs
Join the grounds of the strip and the controller. Add a 300 to 500 ohm resistor in series with the data line. Put a 1000 uF capacitor across the strip's 5 V and GND. - The strip works at low brightness but dims, turns yellow, or resets when many LEDs go white. Addressable RGB LEDs
Each LED can draw about 60 mA at full white. Use a 5 V supply sized for the count, feed power in at several points, and lower the brightness in code.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.