Features

  • Shows date and time on serial monitor.
  • Shows date and time on a mini LCD.
  • Alarm clock - turn ON or turn OFF an IO pin.
  • Settings can be set via serial interface or push button switches.
  • Keeps time running after electricity failure.
  • Using an Arduino UNO & a LCD Keypard Shield.
  • Using a DS1307 RTC module.

Software Library

You need to download and install the following libraries before you can upload sketch to your Arduino.

  • Time.h
    The Time library adds timekeeping functionality to Arduino with or without external timekeeping hardware. This library is often used together with TimeAlarms and DS1307RTC.
  • DS1307RTC.h
    Allows you to access real time clock (RTC) chips compatible with the DS1307.

LCD Keypad Shield

The LCD Keypad shield includes 6 momentary push buttons and a blue backlight LCD which can display two row of 16 characters. The buttons are connected to only one analog input (A0) in order to saving on input/output pins.

Pin Allocation

PinFunction
Analog 0Button (Select, Up, Right, Down and Left)
Digital 4DB4
Digital 5DB5
Digital 6DB6
Digital 7DB7
Digital 8RS (Data or Signal Display Selection)
Digital 9Enable
Digital 10Backlit Control

DS1307RTC Module

The DS1307 serial real-time clock (RTC) is a low- power, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. DS1307 works on I2C protocol which can interfaces to most microcontrollers.

A 3 volt lithium coin cell battery (CR2032) is connected to the DS1307 which keeps time running after electricity failure. The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the backup supply.

The module also include a 24C32 32K I2C EEPROM which is not using in this project.


Source Code

This project includes three examples that shows how to display real time on a LCD display with or without using a RTC module.

  1. LCD Digital clock without RTC module.
  2. DS1307RTC LCD Digital clock.
  3. DS1307RTC LCD Digital clock with Alarm.

The Arduino code is breaking into multiple files which make it more readable and hence easy to maintain.


Key Functions
KeysFunction 1Function 2
LeftSet Time
RightSet Date
UpSet Alarm TimeIncrease value by one
DownDisable/Enable AlarmDecrease value by one
Selecttoggle between 12 or 24 hour formatAccept input

Set Date/Time via Serial Interface
  • Run the Serial terminal.
  • Make sure you have selected the the correct COM port.
  • Make sure the baud rate is set correctly at 9600 bps. You should see the following:

  • To set the system date, send a string to the serial port with the following syntax:
    Dyymmnn
    E.g. D160415 will set the system date to 2016 April 15th
  • To set the system time, send a string to the serial port with the following syntax:
    Thhmmss 
    E.g. T012345 will set the system time to 1AM 23minute 45seconds
  • To set the Alarm time, send a string to the serial port with the following syntax:
    Ahhmmss
Set the Date via Push Buttons
  • Push the Right button in order to change the system date.
  • Use the Up/Down buttons to change the date.
  • Push the Select button to accept changes.
  • Timeout will occur after idle for 10 seconds, changes made will not save.
Set the Time via Push Buttons
  • Push the Left button in order to change the system time.
  • Use the Up/Down buttons to change the time.
  • Push the Select button to accept changes.
  • Timeout will occur after idle for 10 seconds, changes made will not save.
Set the Alarm Time via Push Buttons
  • Push the Up button in order to change the alarm time.
  • Use the Up/Down buttons to change the time.
  • Push the Select button to accept changes.
  • Timeout will occur after idle for 10 seconds, changes made will not save.
Disable/Enable Alarm
  • Push the Down button to disable or enable Alarm.
  • If Alarm is enabled, its time is shown on the right corner of the LCD.
  • If Alarm is disabled, its time is hidden.