Help with date specific alarm

Basically, I wanted to create a little box for my friend and my friend's birthday is on December 28, 2021. so basically a bit over a month. The plan was that the box would be locked using some sorta mechanism and a servo and when it's 12/28/21 at midnight the box would unlock itself revealing whatever gifts I have collected for them. also, i kinda want the screen to display a message saying happy birthday when the date hits. any help will be appreciated
the code below is what I have.
using A Arduino Uno
with PCF 8523 Rtc
and a 16x2 display

////////////////////
// Date and time functions using a PCF8523 RTC connected via I2C and Wire lib
#include "RTClib.h"
#include <LiquidCrystal.h>
RTC_PCF8523 rtc;
int T;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
Serial.begin(9600);
lcd.begin(16, 2);
#ifndef ESP8266
while (!Serial);
#endif

if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1) delay(10);
}

if (! rtc.initialized() || rtc.lostPower()) {
Serial.println("RTC is NOT initialized, let's set the time!");

rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

rtc.adjust(DateTime(2021, 11, 17, 12, 55, 40));
}

rtc.start();

float drift = 43;
float period_sec = (7 * 86400);
float deviation_ppm = (drift / period_sec * 1000000);
float drift_unit = 4.34;

int offset = round(deviation_ppm / drift_unit);

}

void loop () {

if (Serial.available()) {

delay(100);

lcd.display();

while (Serial.available() > 0) {
  
  lcd.write(Serial.available());
}    }
DateTime now = rtc.now();

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();


// calculate a date which is 7 days, 12 hours and 30 seconds into the future
DateTime future (now + TimeSpan(0,0,7,-36));

lcd.print(future.year(), DEC);
lcd.print('/');
lcd.print(future.month(), DEC);
lcd.print('/');
lcd.print(future.day(), DEC);
lcd.setCursor(0, 1);
lcd.print(' ');
lcd.print(future.hour(), DEC);
lcd.print(':');
lcd.print(future.minute(), DEC);
lcd.print(':');
lcd.print(future.second(), DEC);
/////////////////////////////
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);

Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();

Serial.println();
delay(1000);

lcd.clear();

}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

If the box will be battery powered, you will need to make heavy use of deep sleep mode, and basically turn off the power to everything but the RTC.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.