Built-in project · Arduino Uno R3

Eid greeting card on an Arduino Uno

A 16x2 LCD with a hand-drawn crescent and star says Eid Mubarak, and a button turns to the same wish in Arabic, Malay, Hausa and Somali while a lamp glows. 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 About 15 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $34. On Mokxi they're free.

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

What you'll learn

  • Custom LCD characters with createChar
  • Storing text in a table of strings
  • Stepping through a list with the modulo operator
  • A smooth breathing glow with PWM
  • Difficulty: Beginner
  • Time: About 15 minutes
  • Board: Arduino Uno R3
  • Parts: 6

How it works

The LCD shows "Eid Mubarak" with a small crescent and star drawn in the bottom right corner. Those two symbols are custom characters, each built from 8 rows of 5 dots.

Each press of the button on pin 2 moves to the next greeting in a list of five, then wraps back to the first. The serial monitor prints the same text.

A yellow LED on pin 5 glows softly and slowly gets brighter and dimmer. It never stops, even while the greetings change.

Kits that can build it

These 3 starter kits have every part in the circuit. Each kit's page lists what else it can build.

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 pinConnects to
Resistor, 220 Ω pin 1Arduino Uno R3 pin 5
Pushbutton pin 1aArduino Uno R3 pin 2
Character LCD with I2C backpack pin VCCArduino Uno R3 pin 5V
Pushbutton pin 2aArduino Uno R3 pin GND
LED, yellow pin CArduino Uno R3 pin GND
Character LCD with I2C backpack pin GNDArduino Uno R3 pin GND
Character LCD with I2C backpack pin SDAArduino Uno R3 pin A4
Character LCD with I2C backpack pin SCLArduino Uno R3 pin A5
LED, yellow pin AResistor, 220 Ω pin 2

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
// Eid greeting card: an LCD with a little crescent and star drawn on it
// that says Eid Mubarak, and a button that turns to the same wish in other
// languages Muslims around the world use.
//
//   LCD       16x2 with an I2C backpack: SDA -> A4, SCL -> A5
//   button    pin 2 -> button -> GND        (INPUT_PULLUP)
//   lamp      pin 5 -> 220 ohms -> yellow LED -> GND, a warm glow
//
// Eid Mubarak means "blessed Eid" in Arabic and is said everywhere. The card
// also has Eid Saeed (Arabic, "happy Eid"), Selamat Hari Raya (Malay and
// Indonesian, "happy day of celebration"), Barka da Sallah (Hausa, spoken in
// Nigeria and Niger) and Ciid Wanaagsan (Somali, "happy Eid").
//
// The crescent and the star are custom characters. A 16x2 LCD lets a sketch
// draw eight of its own, each 5 dots wide and 8 tall, one byte per row.
//
// Things to try. Press the button. Add your family's own greeting to
// GREETINGS: the wish, a second line if it is long, and the language.

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

const int BUTTON_PIN = 2;
const int LAMP_PIN = 5;

LiquidCrystal_I2C lcd(0x27, 16, 2);

const uint8_t CRESCENT[8] = {0b00110, 0b01100, 0b11000, 0b11000, 0b11000, 0b01100, 0b00110, 0b00000};
const uint8_t STAR[8] = {0b00100, 0b00100, 0b11111, 0b01110, 0b01010, 0b10001, 0b00000, 0b00000};

// The wish, a second line if it needs one, and the language.
const char *GREETINGS[][3] = {
  {"Eid Mubarak", "", "Arabic"},
  {"Eid Saeed", "", "Arabic"},
  {"Selamat Hari", "Raya", "Malay"},
  {"Barka da Sallah", "", "Hausa"},
  {"Ciid Wanaagsan", "", "Somali"},
};
const int COUNT = sizeof(GREETINGS) / sizeof(GREETINGS[0]);

int shown = 0;

void show(int n) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(GREETINGS[n][0]);
  lcd.setCursor(0, 1);
  lcd.print(GREETINGS[n][1][0] ? GREETINGS[n][1] : GREETINGS[n][2]);
  lcd.setCursor(14, 1);
  lcd.write(0);   // the crescent
  lcd.write(1);   // the star
  Serial.print(GREETINGS[n][0]);
  if (GREETINGS[n][1][0]) {
    Serial.print(" ");
    Serial.print(GREETINGS[n][1]);
  }
  Serial.print(" (");
  Serial.print(GREETINGS[n][2]);
  Serial.println(")");
}

void setup() {
  Serial.begin(9600);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(LAMP_PIN, OUTPUT);
  lcd.init();
  lcd.backlight();
  lcd.createChar(0, CRESCENT);
  lcd.createChar(1, STAR);
  analogWrite(LAMP_PIN, 120);
  show(0);
}

void loop() {
  if (digitalRead(BUTTON_PIN) == LOW) {
    shown = (shown + 1) % COUNT;
    show(shown);
    while (digitalRead(BUTTON_PIN) == LOW) delay(10);
    delay(50);
  }
  // A slow breathing glow on the lamp.
  int t = (millis() / 8) % 512;
  analogWrite(LAMP_PIN, 60 + (t < 256 ? t : 511 - t) / 2);
  delay(10);
}

Code walkthrough

The key functions of the sketch, and what each one does.

show sketch.ino

Clears the LCD and prints greeting n. The first line is the wish. The second line is the continuation if there is one, otherwise the language name. Then it writes the crescent and star at column 14. It also prints the greeting to serial.

void show(int n) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(GREETINGS[n][0]);
  lcd.setCursor(0, 1);
  lcd.print(GREETINGS[n][1][0] ? GREETINGS[n][1] : GREETINGS[n][2]);
  lcd.setCursor(14, 1);
  lcd.write(0);   // the crescent
  lcd.write(1);   // the star
  Serial.print(GREETINGS[n][0]);
  if (GREETINGS[n][1][0]) {
    Serial.print(" ");
    Serial.print(GREETINGS[n][1]);
  }
  Serial.print(" (");
  Serial.print(GREETINGS[n][2]);
  Serial.println(")");
}

setup sketch.ino

Starts serial, sets the button to INPUT_PULLUP and the lamp pin to output. It starts the LCD and backlight, and defines the crescent as character 0 and the star as character 1. Then it shows the first greeting.

void setup() {
  Serial.begin(9600);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(LAMP_PIN, OUTPUT);
  lcd.init();
  lcd.backlight();
  lcd.createChar(0, CRESCENT);
  lcd.createChar(1, STAR);
  analogWrite(LAMP_PIN, 120);
  show(0);
}

loop sketch.ino

When the button reads LOW, it moves shown forward and shows that greeting. It waits for release and a short 50 ms settle. Every pass also sets the lamp brightness from millis() using a triangle wave.

void loop() {
  if (digitalRead(BUTTON_PIN) == LOW) {
    shown = (shown + 1) % COUNT;
    show(shown);
    while (digitalRead(BUTTON_PIN) == LOW) delay(10);
    delay(50);
  }
  // A slow breathing glow on the lamp.
  int t = (millis() / 8) % 512;
  analogWrite(LAMP_PIN, 60 + (t < 256 ? t : 511 - t) / 2);
  delay(10);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The crescent and star show as odd symbols This project
    Call createChar after lcd.init() and before show. Characters 0 and 1 must be defined before they are written.
  • The greeting skips ahead by two This project
    The sketch waits for the button to be released after each press. If you remove that wait, one press will count many times.
  • The LED does not glow This project
    Put the LED in series with the 220 ohm resistor from pin 5 to ground, with the long leg on the resistor side.
  • The input reads random HIGH and LOW when the button is not pressed. Pushbutton
    A floating pin picks up noise. Add a 10 k pull-down or pull-up resistor, or use INPUT_PULLUP and wire the button between the pin and GND. Then pressed reads LOW.
  • The button seems always pressed, or never changes. Pushbutton
    A 4-leg tactile switch has legs joined in pairs. Place it across the breadboard center gap so the pairs sit on different rows. Wired along one side, the legs are already connected.
  • 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 LED does not light, or it lights once and then dies. LED
    LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.