Projects / Birthday countdown display

Birthday countdown display

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO

    Wire the clock

    SDA to A4, SCL to A5, 5V and GND.

  2. NANO

    Wire the display

    CLK to D5, DIO to D6, 5V and GND.

  3. NANO

    Wire the buttons and buzzer

    Day on D2, month on D3, buzzer on D8.

  4. NANO

    Upload the sketch

    The display shows the days to 1 January.

  5. NANO

    Press the month and day buttons

    The date shows for two seconds as MM.DD.

  6. NANO

    Set the birthday

    The display shows the days left.

  7. NANO

    Set today's date as the birthday

    The display flashes 8888 and a tune plays.

In short

How do you build a birthday countdown display?

A little display counts the days to a birthday and, on the day, flashes a party pattern and plays a short tune. Two buttons set the date. A cheerful use of a clock chip and a good way to learn about date sums. You need Arduino Nano, DS3231 RTC module, TM1637 4-digit display, Tactile push button 6 mm × 2, Passive buzzer, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 80 minutes.

Level
Beginner
Time
About 80 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
RTC SDA and SCLNano A4 and A5I2C data and clock
RTC VCC and GNDNano 5V and GNDPower for the clock module
Display CLKNano D5Clock line
Display DIONano D6Data line
Display VCC and GNDNano 5V and GNDPower
Day buttonNano D2 and GNDAdds one to the birthday's day
Month buttonNano D3 and GNDAdds one to the birthday's month
Passive buzzer + and -Nano D8 and GNDA short tune on the day

Code

The clock chip keeps the date even when the Nano is off, and the sketch works out how many days are left until the next birthday. It does this by building two dates at midnight, today and the next time the birthday comes round, which is this year if the birthday has not passed yet and next year if it has, and dividing the gap in seconds by 86400, the number of seconds in a day. The display shows the number of days left. The two buttons set the birthday: the day button adds one each press and wraps from 31 back to 1, the month button does the same up to 12, and the month and day are shown for two seconds as 07.15 while you set them. The birthday is kept in the Nano's EEPROM so it is still there after a power cut. On the day itself the display flashes 8888 and the buzzer plays a short tune once, and on the next day the countdown to next year starts. A birthday of 29 February is shown on 1 March in years that have no 29 February. The clock is set from your computer's time when the sketch is first uploaded, or when its battery has been out. If the clock module has a coin cell, fit it with the right polarity, never charge it, and keep it away from small children. Install "RTClib" and "TM1637" by Avishay Orpaz from the Library Manager.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// Libraries: RTClib by Adafruit and TM1637 by Avishay Orpaz (TM1637Display).
#include <Wire.h>
#include <EEPROM.h>
#include <RTClib.h>
#include <TM1637Display.h>

RTC_DS3231 rtc;
TM1637Display disp(5, 6);                 // CLK on D5, DIO on D6

const uint8_t BTN_DAY = 2;
const uint8_t BTN_MONTH = 3;
const uint8_t BUZZ = 8;

uint8_t bMonth = 1, bDay = 1;             // the birthday
bool tunePlayedToday = false;
unsigned long showSetUntil = 0;           // show the date while it is being set
bool prevDay = false, prevMonth = false;

void saveBirthday() {
  EEPROM.update(0, 0xB1);
  EEPROM.update(1, bMonth);
  EEPROM.update(2, bDay);
}

void loadBirthday() {
  if (EEPROM.read(0) == 0xB1) {
    bMonth = EEPROM.read(1);
    bDay = EEPROM.read(2);
    if (bMonth < 1 || bMonth > 12) bMonth = 1;
    if (bDay < 1 || bDay > 31) bDay = 1;
  }
}

long daysToBirthday() {
  DateTime now = rtc.now();
  DateTime today(now.year(), now.month(), now.day(), 0, 0, 0);
  DateTime next(now.year(), bMonth, bDay, 0, 0, 0);
  if (next.unixtime() < today.unixtime()) next = DateTime(now.year() + 1, bMonth, bDay, 0, 0, 0);
  return (long)((next.unixtime() - today.unixtime()) / 86400UL);
}

void playTune() {
  const int notes[] = {523, 523, 587, 523, 698, 659};
  const int lens[]  = {180, 180, 360, 360, 360, 600};
  for (uint8_t i = 0; i < 6; i++) {
    tone(BUZZ, notes[i], lens[i]);
    delay(lens[i] + 60);
  }
}

void setup() {
  pinMode(BTN_DAY, INPUT_PULLUP);
  pinMode(BTN_MONTH, INPUT_PULLUP);
  pinMode(BUZZ, OUTPUT);
  Serial.begin(9600);
  disp.setBrightness(5);
  if (!rtc.begin()) { Serial.println(F("No RTC found")); while (true) {} }
  if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  loadBirthday();
}

void loop() {
  bool d = (digitalRead(BTN_DAY) == LOW);
  bool m = (digitalRead(BTN_MONTH) == LOW);
  if (d && !prevDay)   { bDay = bDay % 31 + 1;   saveBirthday(); showSetUntil = millis() + 2000; }
  if (m && !prevMonth) { bMonth = bMonth % 12 + 1; saveBirthday(); showSetUntil = millis() + 2000; }
  prevDay = d;
  prevMonth = m;

  if (millis() < showSetUntil) {          // month and day while setting, such as 07.15
    disp.showNumberDecEx(bMonth * 100 + bDay, 0x40, true);
    delay(30);
    return;
  }

  long days = daysToBirthday();
  if (days == 0) {                        // it is the day: flash and play once
    bool on = (millis() / 400) % 2;
    if (on) disp.showNumberDecEx(8888, 0xFF, true);
    else disp.clear();
    if (!tunePlayedToday) { playTune(); tunePlayedToday = true; }
  } else {
    tunePlayedToday = false;
    disp.showNumberDec(days, false);
  }
  delay(30);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

No RTC found

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Set a date next weekThe display shows about 7
Month buttonMonth goes up and wraps after 12
Day buttonDay goes up and wraps after 31
Power cutThe birthday is remembered
Birthday set to todayFlashing 8888 and one tune
Next dayThe countdown restarts for next year

If it does not work

Prints No RTC found

Check the clock's SDA and SCL wires.

Wrong date

Re-upload to set the clock, or fit a new coin cell.

Display blank

Check CLK on D5 and DIO on D6.

Tune plays every loop

Check the clock keeps the right date.

Buttons do nothing

Check each goes to its pin and GND.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the birthday countdown display?

Arduino Nano, DS3231 RTC module, TM1637 4-digit display, Tactile push button 6 mm × 2, Passive buzzer, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the birthday countdown display take to build?

About 80 minutes for a beginner maker, in 7 steps.

How do I know the birthday countdown display works?

Set a date next week: The display shows about 7. Month button: Month goes up and wraps after 12. Day button: Day goes up and wraps after 31.

Prints No RTC found: what should I check?

Check the clock's SDA and SCL wires.

Wrong date: what should I check?

Re-upload to set the clock, or fit a new coin cell.

Display blank: what should I check?

Check CLK on D5 and DIO on D6.

Tune plays every loop: what should I check?

Check the clock keeps the right date.