Built-in project · Arduino Uno R3

Hanukkah menorah on an Arduino Uno

Nine flickering WS2812B lights, eight candles and the shamash: each press is the next night, the shamash lights first and then tonight’s candles, newest first, left to right. The whole build, an Arduino Uno and 3 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.

Hanukkah menorah · Arduino Uno R3live0.000 s 0.00x
Press the button for the first night
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Hanukkah menorah: nine flickering lights, eight candles and the shamash in
// the middle. Each press of the button is the next night: the shamash lights
// first, then it lights tonight's candles one by one, newest first.
//
//   candles   9 WS2812B LEDs in a row, DIN <- 330 ohms <- pin 6
//             (LED 4, the middle one, is the shamash)
//   button    pin 2 -> button -> GND        (INPUT_PULLUP): the next night
//
// Hanukkah lasts eight nights, with one more candle each night. The candles
// go into the menorah from right to left: the first night's candle on the
// far right, the second night's just to its left, and so on. The shamash,
// the helper candle, is lit first every night and is used to light the
// others, and those are lit from left to right, so the newest candle is
// always lit first. The sketch follows that order exactly.
//
// The shamash stands apart from the eight. On this row it is the middle LED;
// in a real build, mount it higher than the others, as many menorahs do.
//
// Every flame flickers on its own, a warm white that dips now and then, and
// the shamash glows a little brighter. After the eighth night, the next press
// puts every light out, ready for next year.
//
// Things to try. Press the button for each night. Slow the lighting with
// LIGHT_MS so you can follow the order.

#include <Adafruit_NeoPixel.h>

const int LIGHTS = 9;
const int SHAMASH = 4;
const int BUTTON_PIN = 2;
const unsigned long LIGHT_MS = 600;

// The eight candle places, left to right, skipping the shamash.
const int PLACES[8] = {0, 1, 2, 3, 5, 6, 7, 8};

Adafruit_NeoPixel menorah(LIGHTS, 6, NEO_GRB + NEO_KHZ800);

bool lit[LIGHTS];
int night = 0;

void flame(int i) {
  int v = random(0, 15) == 0 ? random(110, 170) : random(200, 256);
  if (i == SHAMASH) v = v < 230 ? v + 25 : 255;
  menorah.setPixelColor(i, v, v * 3 / 4, v / 4);
}

void draw() {
  for (int i = 0; i < LIGHTS; i++) {
    if (lit[i]) flame(i);
    else menorah.setPixelColor(i, 0);
  }
  menorah.show();
}

// Wait while every lit flame keeps flickering.
void wait(unsigned long ms) {
  unsigned long until = millis() + ms;
  while (millis() < until) {
    draw();
    delay(40);
  }
}

void lightNight(int n) {
  for (int i = 0; i < LIGHTS; i++) lit[i] = false;
  draw();
  Serial.print("Night ");
  Serial.print(n);
  Serial.println(": the shamash first");
  lit[SHAMASH] = true;
  wait(LIGHT_MS);
  // Tonight's candles are the n rightmost places, lit from the left.
  for (int k = 8 - n; k < 8; k++) {
    lit[PLACES[k]] = true;
    Serial.print("  candle in place ");
    Serial.println(k + 1);
    wait(LIGHT_MS);
  }
  Serial.print(n);
  Serial.println(n == 1 ? " candle and the shamash" : " candles and the shamash");
}

void setup() {
  Serial.begin(9600);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  menorah.begin();
  menorah.setBrightness(170);
  menorah.show();
  Serial.println("Happy Hanukkah! Press the button for the first night");
}

void loop() {
  if (digitalRead(BUTTON_PIN) == LOW) {
    night++;
    if (night > 8) {
      night = 0;
      for (int i = 0; i < LIGHTS; i++) lit[i] = false;
      draw();
      Serial.println("All eight nights done. Until next year");
    } else {
      lightNight(night);
    }
    while (digitalRead(BUTTON_PIN) == LOW) draw();
  }
  draw();
  delay(40);
}

Parts list

5 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

5 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 Ω pin 1
  • Arduino Uno R3 pin 2; Pushbutton pin 1a
  • Arduino Uno R3 pin 5V; Addressable RGB LEDs pin VDD
  • Ground: Arduino Uno R3 pin GND; Pushbutton pin 2a; Addressable RGB LEDs pin VSS
  • Resistor, 330 Ω pin 2; Addressable RGB LEDs 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.