Built-in project · Arduino Uno R3

Kwanzaa kinara on an Arduino Uno

Seven WS2812B candle lights in red, black and green on a kinara: each press is the next day of Kwanzaa, lighting one more candle and showing that day’s principle on a 16x2 LCD. The whole build, an Arduino Uno and 4 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.

Kwanzaa kinara · Arduino Uno R3live0.000 s 0.00x
Press the button for the first day of Kwanzaa
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
// Kwanzaa kinara: seven candle lights, three red, one black and three green,
// with the day's principle on a little screen. Each press of the button is the
// next day of Kwanzaa, and one more candle is lit.
//
//   candles   7 WS2812B LEDs in a row, DIN <- 330 ohms <- pin 6
//             (left to right: red, red, red, black, green, green, green)
//   LCD       16x2 with an I2C backpack: SDA -> A4, SCL -> A5
//   button    pin 2 -> button -> GND        (INPUT_PULLUP): the next day
//
// Kwanzaa runs from December 26th to January 1st, a celebration of African
// American culture and heritage with a principle for each day, the Nguzo
// Saba. The kinara holds the mishumaa saba, the seven candles: the black one
// in the middle for the people, three red on the left for the struggle, and
// three green on the right for the future and hope.
//
// The black candle is lit first, on the first day. After that, one common
// order alternates from the outside in: the first red on the far left, then
// the first green on the far right, and so on toward the middle. Families
// differ a little in the order they use, so it is one line, ORDER, to change.
//
// Each candle's LED glows in its candle's color, red, warm white for the
// black candle, and green, with a flame's flicker on top.
//
// Things to try. Press the button for each day. Change ORDER to the one your
// family uses.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_NeoPixel.h>

const int CANDLES = 7;
const int BUTTON_PIN = 2;

// Which place lights on each day: the black candle, then outside in.
const int ORDER[CANDLES] = {3, 0, 6, 1, 5, 2, 4};

const char *PRINCIPLES[CANDLES][2] = {
  {"Umoja", "Unity"},
  {"Kujichagulia", "Self-Determination"},
  {"Ujima", "Collective Work and Responsibility"},
  {"Ujamaa", "Cooperative Economics"},
  {"Nia", "Purpose"},
  {"Kuumba", "Creativity"},
  {"Imani", "Faith"},
};

Adafruit_NeoPixel kinara(CANDLES, 6, NEO_GRB + NEO_KHZ800);
LiquidCrystal_I2C lcd(0x27, 16, 2);

int day = 0;
bool lit[CANDLES];
const char *marquee = "";   // the bottom line, scrolled when it is long
int marqueeAt = 0;
unsigned long nextScroll = 0;

// Show the bottom line, sliding along one letter at a time if it is wider
// than the screen, with a pause at each end.
void scrollLine() {
  int len = strlen(marquee);
  if (len <= 16 || millis() < nextScroll) return;
  lcd.setCursor(0, 1);
  for (int i = 0; i < 16; i++) lcd.print(marquee[marqueeAt + i]);
  nextScroll = millis() + (marqueeAt == 0 || marqueeAt == len - 16 ? 1200 : 300);
  marqueeAt = marqueeAt >= len - 16 ? 0 : marqueeAt + 1;
}

// The candle's color at place i: red on the left, black (shown warm white)
// in the middle, green on the right, scaled by the flame's level.
void candle(int i, int v) {
  if (i < 3) kinara.setPixelColor(i, v, 0, 0);
  else if (i == 3) kinara.setPixelColor(i, v, v * 3 / 4, v / 3);
  else kinara.setPixelColor(i, 0, v, 0);
}

void setup() {
  Serial.begin(9600);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  kinara.begin();
  kinara.setBrightness(170);
  kinara.show();
  lcd.init();
  lcd.backlight();
  lcd.print("Habari Gani?");
  lcd.setCursor(0, 1);
  lcd.print("Press for day 1");
  Serial.println("Kwanzaa kinara: press the button for the first day");
}

void loop() {
  if (digitalRead(BUTTON_PIN) == LOW) {
    day++;
    if (day > CANDLES) {
      day = 0;
      for (int i = 0; i < CANDLES; i++) lit[i] = false;
      marquee = "";
      lcd.clear();
      lcd.print("Heri za Kwanzaa");
      Serial.println("Heri za Kwanzaa! All seven days are done");
    } else {
      lit[ORDER[day - 1]] = true;
      lcd.clear();
      lcd.print(PRINCIPLES[day - 1][0]);
      lcd.setCursor(0, 1);
      for (int i = 0; i < 16 && PRINCIPLES[day - 1][1][i]; i++) lcd.print(PRINCIPLES[day - 1][1][i]);
      marquee = PRINCIPLES[day - 1][1];
      marqueeAt = 0;
      nextScroll = millis() + 1200;
      Serial.print("Day ");
      Serial.print(day);
      Serial.print(": ");
      Serial.print(PRINCIPLES[day - 1][0]);
      Serial.print(", ");
      Serial.println(PRINCIPLES[day - 1][1]);
    }
    while (digitalRead(BUTTON_PIN) == LOW) delay(10);
  }

  for (int i = 0; i < CANDLES; i++) {
    if (lit[i]) candle(i, random(0, 15) == 0 ? random(120, 180) : random(200, 256));
    else kinara.setPixelColor(i, 0);
  }
  kinara.show();
  scrollLine();
  delay(50);
}

Parts list

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

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 Ω pin 1
  • Arduino Uno R3 pin 2; Pushbutton pin 1a
  • Arduino Uno R3 pin 5V; Addressable RGB LEDs pin VDD; Character LCD with I2C backpack pin VCC
  • Ground: Arduino Uno R3 pin GND; Pushbutton pin 2a; Addressable RGB LEDs pin VSS; Character LCD with I2C backpack pin GND
  • Arduino Uno R3 pin A4; Character LCD with I2C backpack pin SDA
  • Arduino Uno R3 pin A5; Character LCD with I2C backpack pin SCL
  • 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.