Arduino Alarm Clock with Time Setting

In the post-Arduino alarm clock with time setting you will learn to make a digital clock using the RTC DS3231 module with alarm and temperature indication facility. Previously, we had already posted various types of clock circuits using Arduino and RTC DS3231 like “Arduino NTP Clock using NodeMCU and DS3231”, “Arduino Digital Clock using DS3231 Pi Module“. Before starting to circuit part and software code part let’s see its features:

Features of Arduino alarm clock with time setting

  1. Display date and time (day and second indication).
  2. Alarm time setting
  3. Display temperature without using a dedicated temperature sensor.
  4. Can adjust time according to your requirement
  5. Dedicated four pushbuttons for time and alarm time setting.

Component required for Arduino alarm clock with time setting

  1. Arduino UNO Board x 1
  2. RTC Module DS3231 x 1
  3. 16×2 LCD x 1
  4. Push-to-on Switch x 4
  5. Buzzer x 1
  6. 470-ohm resistor x 1
  7. 10k-ohm Variable resistor x 1

Circuit Description of Arduino alarm clock with time setting

The circuit is shown in figure 1, built around the Arduino Uno board, etc module, 16×2 LCD, and a few other electronic components. LCD is connected in higher-order mode i.e. higher-order digital pin of LCD (D4 – D7) is used to receiver the data to display. LCD Pin D4, D5, D6, and D7 are connected to Arduino digital pin D7, D8, D9, and D10 respectively as shown in the circuit diagram. Reset/Set (RS) pin of LCD is connected to Arduino digital pin D12 where enable pin (E) of LCD is connected to D11 of Arduino. Vss, RW, and LED- pin (i.e. LCD pin 1, 5, and 16) is connected to the ground potential where VDD pin (Pin 2) of LCD is connected to +5V supply from Arduino.

Arduino Alarm Clock with Time Setting

VEE pin (pin 3) of LCD must be connected to lower potential than VDD and higher potential than the ground. Thus, we are using a variable resistor VR1 of 10K, on the fixed terminal of the variable resistor VR1 is connected to +5V where another fixed terminal is connected to the ground. The wiper or variable pin of the variable resistor is connected to pin 3 of the LCD. The voltage at this pin (pin 3) is responsible for LCD contrast. If the LCD does not show any characteristic adjust the variable resistor. LED+ pin (pin 15) of LCD is also connected to +5V through a current limiting resistor R1 (470-ohm). LED+ and LED- pin is for the backlight of LCD.

If you have any difficulties on interfacing LCD with Arduino then please do watch the making video of “Tutorial on Interfacing of 16×2 LCD to Arduino”.
RTC module DS3231 uses the I2C protocol for communication, thus we are using the SDA and SCL pin (A4 and A5) of Arduino. There are various regions of using DSD3231 over DS, a few of these reasons are listed below.

1. No external crystal thus higher accuracy.
2. Inbuilt temperature sensor
3. External temperature does not affect much.

For this prototype, we are using the DS3231 Pi model. + pin and – pin of DS3231 is connected to +5 volt and ground respectively. Where D and C pin is connected to SDA and SCL pin (Pin A4 and A5) respectively as shown in the circuit diagram.

Four Push-to-on switches are used to adjust the time and alarm connected to Arduino digital pin D2 to D5 as shown in the circuit diagram. Instead of using an external pull-up or pulldown resistor, we are using an internal pull-up resistor as defined in software code.

S.N. Switch Remarks
1.

2.

3.

4.

SW1

SW2

SW3

SW4

Set Alarm Time

Set Date and Time

Increase Value

Decrease value

author prototype of Arduino Alarm Clock with Time Setting

Figure 2: Author Prototype of Arduino Alarm Clock with Time Setting

Software Code:

The software code of the Arduino alarm clock with time setting is written in Arduino programming language and compiled using Arduino IDE. Here, we had used a different library, so before using this code upload this header file to the library folder of Arduino.

#include <DS3231.h>, For date, time, and temperature. Download DS3231.h
#include <Wire.h>, For I2C communication.
#include <LiquidCrystal.h>, For 16×2 liquid crystal display. Download LiquidCrystal.h
#include <Button.h>, For push-to-on button, Download Button.h

Download the library file and code and upload the code to your Arduino board without commenting date and timeline. Must define date and time as shown below.

Again, upload the entire code with comments on setTime and setDate.

Working off the clock.

  1. Connect all the components as shown in the circuit diagram.
  2. Upload the code without comment set date and set timeline.
  3. Again, upload the code with comments on these two lines.

Date and time setup

  1. Press the switch SW2 (DATE), the day will start to blink.
  2. Now, press the switch DEC or INC. (SW1 or SW2) according to your requirement, and then again press the DATE Switch (SW2).
  3. Now, the month starts to blink. Here also press the INC or DEC switch for a set month and then again press the DATE switch (SW2).
  4. Do the same process until you set the date and time.
  5. After setting the date and time it will display the message “SET DATE FINISHED” and “SET TIME FINISHED”

Alarm Time Setup

  1. Press the switch SW1 (ALARM), a message will display “SET Alarm” with the time and duration of the alarm.
  2. Now press the INC or DEC switch to set the alarm time (time is in 24-hour format), followed by the alarm switch.
  3. You can also adjust the duration of the alarm by pressing INC or DEC button, by default alarm duration is of 5 minutes.
  4. After setting alarm time press the Alarm switch, it will display the message “Set Alarm finished with a time of alarm”.

18 Thoughts to “Arduino Alarm Clock with Time Setting”

  1. Babak

    Hello dear
    I have an error In this line:
    DS3231 rtc(SDA, SCL);
    and not verify or upload to Arduino
    .
    .
    .
    Arduino UNO R3
    LCD 1602 I2C

    Please help me…

    1. Hi babak, code is tested and verified please check if you have install all the library specially #include .
      And also check if you have install multiple library.

  2. Enrico

    Hello.
    I always get the following error message when copying:
    no matching function for call to Button: ‘Button (int &, bool, bool, int)’.
    What am I doing wrong? I am not a programmer.

    VlG Enrico

    1. Hi enrico, first you have to add button.h library to your Arduino IDE.
      For that download button.h library and then add to your Arduino IDE.
      This will solve the error.

  3. Enrico

    Hi there,
    Thanks for the hint. But there are several “button liberys” in the library management. What exactly is it? Perhaps you can tell me the name of the library in question, or what it is labeled. Possibly the name of the programmer.

    best regards, Enrico

    1. Hi, please go through the software section of this article, there you will find all the required libraries. Please download the required one and add it to your Arduino IDE.

  4. Enrico Scherwinsky

    Hello my friend
    I have now integrated your “bottom.master” library about 100 times.
    Nevertheless, the red error bar in line 21 remains when compiling and the following error message is displayed: “no matching function for call to ‘Button: Button (int &, Bool, Bool, int). I’m slowly not sure what to do. Greetings,” Enrico

    1. There is no code error.
      Possible regions for error messages are
      1. Either you have installed another button library
      2. Or you had been installed the library in a different folder.

  5. arcasha foley

    Its possible to add lcd i2c to the code for more simple wire?

    Thanks

    1. Hi, you can use an I2C LCD but before that, you have to change the LCD library to the I2C LCD library.

  6. Eks

    Hi..
    How to add more (multiple) alarm based on days of week ?
    Thanks,

  7. Shreyank Vispara

    Hello,
    Could we set more than one alarm in this code?

  8. Asmi

    do we really need the set time, month, and date buttons?

    1. Hi,
      yes we do need if you wish to setup date and time externally (without code).

  9. nathan

    I have exactly the same problem, did you manage to fix it?

    1. What type of problem you had faced, please elaborate.

  10. Asmi

    Could I connect this circuit and add the wake up by light features to it sincethey both are connected to PWM pin 9

  11. nathan

    When I run the code in the simulation it jumps straight to the time settings in addition it does not show the day on the screen

Leave a Comment