Rainbow to the pot of gold on an Arduino Uno
A WS2812B strip runs a flowing rainbow along an arch toward four LEDs shimmering gold in a pot at the end, with a knob for the speed. 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 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.
// Rainbow to the pot of gold: an arch of LEDs runs the rainbow toward a pot
// of gold that shimmers at the end, for St. Patrick's Day.
//
// rainbow 20 WS2812B LEDs, DIN <- 330 ohms <- pin 6
// gold 4 WS2812B LEDs in the pot, DIN <- 330 ohms <- pin 5
// knob potentiometer wiper -> A0, ends to 5 V and GND: the speed
//
// The arch is a strip bent over a doorway or along a shelf, and the pot is a
// little black cup with four LEDs in it under some gold paper coins. The
// legend says a pot of gold waits at the end of every rainbow; here it is
// always there.
//
// The rainbow moves by shifting where the color wheel starts. ColorHSV takes
// a hue from 0 to 65535 all the way round, so spreading one turn across the
// 20 LEDs and adding a little to the start every frame makes the colors flow
// along the arch. The knob sets how much is added, from a slow drift to a
// quick run, and the gold LEDs twinkle on their own.
//
// Things to try. Turn the knob. Make the arch flow the other way. Give the
// pot a green shimmer instead.
#include <Adafruit_NeoPixel.h>
const int ARCH = 20, POT = 4;
Adafruit_NeoPixel arch(ARCH, 6, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel gold(POT, 5, NEO_GRB + NEO_KHZ800);
uint16_t start = 0;
unsigned long frames = 0;
void setup() {
Serial.begin(9600);
arch.begin();
gold.begin();
arch.setBrightness(140);
gold.setBrightness(200);
Serial.println("Happy St. Patrick's Day! Follow the rainbow");
}
void loop() {
int speed = map(analogRead(A0), 0, 1023, 32, 1024);
start += speed;
for (int i = 0; i < ARCH; i++) {
uint16_t hue = start + (uint32_t)i * 65536 / ARCH;
arch.setPixelColor(i, arch.gamma32(arch.ColorHSV(hue)));
}
for (int i = 0; i < POT; i++) {
int glint = random(0, 10) == 0 ? 255 : random(140, 200);
gold.setPixelColor(i, glint, glint * 3 / 5, 0);
}
arch.show();
gold.show();
frames++;
if (frames % 200 == 1) {
Serial.print("Rainbow speed ");
Serial.println(speed);
}
delay(20);
}
Parts list
7 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Arduino Uno R3
- 1 × Half breadboard
- 1 × Potentiometer
- 2 × Resistor, 330 Ω
- 2 × Addressable RGB LEDs
How it is wired
7 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 6; Resistor, 330 Ω (1) pin 1
- Arduino Uno R3 pin 5; Resistor, 330 Ω (2) pin 1
- Arduino Uno R3 pin 5V; Potentiometer pin 3; Addressable RGB LEDs (1) pin VDD; Addressable RGB LEDs (2) pin VDD
- Ground: Arduino Uno R3 pin GND; Potentiometer pin 1; Addressable RGB LEDs (1) pin VSS; Addressable RGB LEDs (2) pin VSS
- Arduino Uno R3 pin A0; Potentiometer pin 2
- Resistor, 330 Ω (1) pin 2; Addressable RGB LEDs (1) pin DIN
- Resistor, 330 Ω (2) pin 2; Addressable RGB LEDs (2) pin DIN
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.