Arduino Clock and Calendar (UNO)

Electronics and Programming tutorials and projects

Arduino Clock and Calendar (UNO)

arduino clock and calendar

This project is an “Alarm Clock and Calendar” firmware (.ino file) for Arduino UNO board with the character LCD shield.

The LCD shield has 5 on-chip buttons which send an analog value to the A0 pin and a reset button.

Also it has 5 ADC/IO pins header and 7 IO pins header (including UART Tx and Rx pins).

The “Alarm Clock and Calendar” project has two alarm programs and temperature sensor which shows in both of Celsius and Fahrenheit degrees, shows the time including seconds, shows the day of week and also the calendar can be selected/adjusted between Gregorian and the ancient Persian calendars.

In this project, A1 works as the temperature sensor input (ADC) and D12 works as the buzzer output for the alarm.

The source code contains the following files:

  1. ArduinoUNOClockCalendar.ino (Main handler file)
  2. functions.ino – Global functions file.
  3. settings.h – Configuration and settings header file.

The project is available in the following link:

Arduino UNO Alarm Clock and Calendar With Temperature Meter Source Code – Rev 1.2

Uploading the project

First open one of the files with Arduino program, then select “Arduino UNO” board in the tools menu.

Then plug your Arduino UNO board’s USB cable and select its “COM Port” and upload the program.

Clock and Calendar Project’s Schematic

Place the LCD shield on the UNO board and connect the buzzer and resistive temperature sensor (10K Ohm NTC) as the following schematic:

arduino uno clock calendar schematic

The schematic is so simple. The A0 pin works as the internal Keypad value ADC, A1 pin works as the temperature sensor ADC input and D12 works as the alarm output.

Also there is an optional battery power block as the alternative power source, when the main power cable is disconnected.

  • You can optionally add three 1.5V AA batteries (Battery Power Block) in case you want to save the time when the power cable is disconnected.
  • The power source (Vin) must be 5V when you are going to use the “Battery Power Block”.
  • The microcontroller doesn’t generate audio frequency, just it pulls up and down D12 and causes the Buzzer’s beep. So use a “5V Buzzer” not a speaker.

Clock and Calendar Settings

There are 5 adjustment buttons on the LCD shield: Select, Left, Up, Down and Right.

You can toggle the temperature value between Celsius and Fahrenheit degrees with pushing the “Left” button.

You can toggle the Calendar between the Gregorian and Persian date by pushing the “Down” button.

The LCD’s backlight can be turned on or off by pushing the “Right” button.

With pushing the select button, the minute will blink and you can adjust it by pressing the up and down buttons.

arduino uno clock calendar

By pressing the “SELECT” button again, the hour, year, month and day can be adjusted and finally the date will be saved in the eeprom memory.

  • It saves the date in eeprom memory every day at 00:00:00.

The “UP” button will lead you to the alarms setting menu.

alarm clock calendar arduino uno

With UP and DOWN buttons you can set the Alarm 1 on or off, then if you press SET again, the alarm’s hour and minute will blink and you can set with up and down buttons.

Then by pressing the Select button again, you can set the Alarm 2 and finally the settings will be saved in the eeprom memory.

  • The stars in the calendar show alarms are enabled.

Programming Manual

In the settings.h, you can define “TEMP_TEST_MODE” then the temperature will be shown in the ADC value.

So you can change the equation, in the “Temperature equation” section of the functions.ino file according to your sensor’s specification.

You can adjust the alarm playing time between 1 to 255 seconds with the following variable:

#define ALARM_TIME                  120 // 1-255 Seconds

The “unsigned const char ucAlarmBeep[32]” variable in settings.h file is the alarm rhythm.

There are 16 paired values in this variable. The first one is the pull-up time (in 16mS unit) and the second one is the pull down time.

With changing the following value, the eeprom data will be re-init:

#define EE_INIT                     0xAB

You can change the start date with the following values:

#define PERSIAN_YEAR_BASE           2580 //2580/01/01 1400/01/01
#define GREGORIAN_YEAR_BASE         2021 //2021/03/21

The total years is limited to 256, if you want more, you can change the following variable:

unsigned char ucCalendarYearsSpent;

to (65536 years):

unsigned short ucCalendarYearsSpent;

The project is available in the following:

More projects in our Blog.


Leave a Reply

Your email address will not be published. Required fields are marked *

2 × four =