Simple Arduino Projects for Beginners- Real Time Clock with Alarm

We have started Arduino programming guide and project series. In our last article we had a general overview of Arduino and Getting started with Arduino guide by Mr.Jaseem. We received many appreciations form readers and I would like to thank them all. So to make you happier with Arduino circuits here I’m coming with another yet useful Arduino cool project.
You may find many simple Arduino programs in the Arduino IDE software itself (in File → Examples). But this is more powerful beginner Arduino projects which use 16×2 LCD module to display time and alarm settings. 3 push buttons are provided for selecting alarm mode and time mode together with Minute and Hour adjustments.
Projects with Arduino are very easy and simple to implement because of its all in one feature. We have many more Arduino project ideas that will be published one by one. This is one of our Arduino beginner projects with simple Arduino programming.

Real-Time-Clock-Alarm-using-Arduino

What is Arduino?

Arduino is the best Microcontrollers designed for Teachers and Students. It became more popular due to its ease of use and programmability. Please read more about

Arduino Get Started: Getting Started with Arduino- Everything You Need to Know about Arduino

Schematic diagram of Arduino Real Time Clock

Real-Time-Clock-Alarm-using-Arduino-Schematics

Components Required

  1. Arduino board
  2. Arduino software IDE
  3. Resistor (10KΩ x 3)
  4. LCD 16×2
  5. Buzzer / UM66 with speaker
  6. Push button x 3

Working of Arduino Project

  • LCD 16×2 is used to display time and alarm, which is connected to digital pin 2 to 7 of Arduino board.
  • A variable “alm” is declared as Boolean and it will change state between Clock and Alarm when we press the mode button that is connected in pin 9.
  • Initially “alm” declared as FALSE, which helps to display time on the LCD screen at first time when the system is ON.
  • Three push buttons are used here for setting up of time and alarm, one for mode selection, remaining for minute and hour.
  • If mode button is pressed the variable “alm” become TRUE then program control will display alarm.
  • When the system is running in TIME MODE, we can set time by using minute and hour button directly without entering to any mode.
  • The device can be switched to ALARM MODE by pressing the Mode button, then the same buttons (minute and hour) are used to set alarm.
  • How the alarm logic works? It is simple, while system running in any of the mode it compares Clock time with Alarm time with AM/ PM.
  • If the clock time matches with the alarm time then LCD will display “RINGING” and it will set pin 11 which is connected to buzzer or any other audio device, here we used UM66 with buzzer.
  • The duration of Alarm sound is set to 1 minute.
  • There is no external components are used in the Arduino real time clock alarm, that makes our project more flexible.

You can make this as a deviced timer by simple changes in the program and circuit, the delay time that the duration of alarm can be increase and connect a relay at 9th pin with a relay driving transformer. I’m planning to post it in upcoming Arduino series.

Real Time Clock Arduino Program Code

Here I’m adding the Arduino program code for our project.
[cc lang=‘c’]

//include lcd library
#include

//lcd(RS, E, D4,D5,D6,D7);
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
const int backlight =13;
const int buttonHr = 12;
const int buttonMin = 8;
const int buttonalm = 9;
const int buzzer = 11;

int secs =0;
int secs2 = 0;
int mins = -1;
int hrs = 12;
int amins = 1;
int ahrs = 12;
int atime = amins+1;
boolean isAM = true;
boolean isAAM = true;
boolean alm = false;

int milliDivSecs = 1000;
int milliDivMins = 60000;
int milliDivHrs = 360000;

unsigned long prevmillis=0;

int interval = 1000;

void setup()
{
pinMode(backlight, OUTPUT);
pinMode(buttonHr, INPUT);
pinMode(buttonMin, INPUT);
pinMode(buttonalm, INPUT);
pinMode(buzzer, OUTPUT);

digitalWrite(backlight, HIGH);
lcd.begin(16,2);

lcd.setCursor(0,0);
lcd.print(” TIME “);
lcd.setCursor(0,1);
lcd.print(” 12:00:00 AM “);
updateAAMPM();
Serial.begin(9600);
}

void loop()
{

unsigned long currmillis = millis();

if(digitalRead(buttonalm) == HIGH)
{
updatealm();
delay(400);
}

///////////#############—-ALARM—-###############/////////////////

if(alm)

{
atime = amins+1;
lcd.setCursor(3,0);
lcd.print(“ALARM”);
lcd.setCursor(5,1);
lcd.print(“:”);
lcd.setCursor(8,1);
lcd.print(” “);
updateAmin();
updateAhrs();
AA();

if(digitalRead(buttonHr) == HIGH)
{
delay(25);
ahrs = ahrs+1;
updateAhrs();

//update AMPM on button press
if(ahrs==12)
{
updateAAMPM();
}

delay(400);
}

if(digitalRead(buttonMin) == HIGH)
{
delay(25);
amins = amins + 1;
//Serial.println(mins);
updateAmin();
delay(400);
}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////

else
{
lcd.setCursor(3,0);
lcd.print(” TIME”);
lcd.setCursor(5,1);
lcd.print(“:”);
lcd.setCursor(8,1);
lcd.print(“:”);
updateHrs();
updateMin();
TT();

//detect button pressing
if(digitalRead(buttonHr) == HIGH)
{
delay(25);
hrs = hrs+1;
updateHrs();

//update AMPM on button press
if(hrs==12)
{
updateAMPM();
}

delay(400);
}

if(digitalRead(buttonMin) == HIGH)
{
delay(25);
mins = mins + 1;
updateMin();
delay(400);
}

}

if(currmillis-prevmillis > 999)
{
prevmillis =currmillis;
if(secs<10) { lcd.setCursor(10,1); lcd.print(secs); lcd.setCursor(9,1); lcd.print(0); } else { lcd.setCursor(9,1); lcd.print(secs); } if(secs == 0) { mins = mins+1; updateMin(); } //get new seconds from system time secs = (millis()/milliDivSecs)%60; // divide by 1000 and mod by 60 gives seconds from milliseconds } if(mins == amins && hrs == ahrs && isAAM == isAM) { lcd.setCursor(8,0); lcd.print(" RINGING"); digitalWrite(buzzer, HIGH); } if(mins == atime) { lcd.setCursor(8,0); lcd.print(" "); digitalWrite(buzzer,LOW); } } void updateMin(){ if(mins > 59){
hrs = hrs+1;
updateHrs(); //update hours then
if(hrs==11 && mins >59){
updateAMPM();
}
mins = 0; //reset mins

lcd.setCursor(6,1);
lcd.print(“00”);
}
if(mins < 10) { lcd.setCursor(7,1); } else{ lcd.setCursor(6,1); } lcd.print(mins); } void updateHrs(){ if(hrs> 12)
{
hrs = 1;
}
if(hrs< 10){ lcd.setCursor(3,1); lcd.print(" "); lcd.setCursor(4,1); } else{ lcd.setCursor(3,1); } lcd.print(hrs); } void updateAMPM() { if(isAM) { isAM = false; lcd.setCursor(12,1); lcd.print("PM"); } else { isAM = true; lcd.setCursor(12,1); lcd.print("AM"); } } void updateAmin() { if(amins > 59)
{
ahrs = ahrs+1;
updateAhrs(); //update hours then
if(ahrs==11 && amins >59)
{
updateAAMPM();
}
amins = 0; //reset mins

lcd.setCursor(6,1);
lcd.print(“00”);
}

if(amins < 10) { lcd.setCursor(7,1); } else { lcd.setCursor(6,1); } lcd.print(amins); } //update hour function void updateAhrs() { //display hours - needs fixing for am pm if(ahrs> 12){
//reset to 1
ahrs = 1;
}
if(ahrs< 10){ lcd.setCursor(3,1); lcd.print(" "); lcd.setCursor(4,1); } else{ lcd.setCursor(3,1); } lcd.print(ahrs); } void updateAAMPM() { if(isAAM) { isAAM = false; lcd.setCursor(9,1); lcd.print("PM "); } else { isAAM = true; lcd.setCursor(9,1); lcd.print("AM "); } } void updatealm() { if(alm) { alm = false; } else { alm = true; } } void AA() { if(isAAM) { lcd.setCursor(9,1); lcd.print("AM "); } else { lcd.setCursor(9,1); lcd.print("PM "); } } void TT() { if(isAM) { lcd.setCursor(12,1); lcd.print("AM"); } else { lcd.setCursor(12,1); lcd.print("PM"); } } [/cc] You may also download the .ino file (Arduino program extension) from our download center by the following link.

Download Arduino Program : Real time Clock with Alarm Program

Video Demonstration of Arduino Real Time Clock

I have recorded video demonstration of this Arduino project. I will be uploading it in to our YouTube channel once the editing has been completed. Keep in touch.

Last but not the last let me ask your suggestion regarding this cool Arduino project. Did you try this by your own? Have any doubts? Feel free to comment here. If you got something new from this article, please like our Facebook page and share it. I will get back to you with another interesting Arduino project.

5 thoughts on “Simple Arduino Projects for Beginners- Real Time Clock with Alarm

  1. sorry sir.
    1.how i want to replace buzzer using speaker?
    2.how i want to set the coding to make alarm automatically beeping at 3 times which is 7a.m,2p.m and 10p.m without set the alarm by using that button?
    thank you sir.

  2. Good day my friend . Exallent work . I make an order from Amazon an arduino mega with lcd screen tft but not touch . The lcd screen have one button on the right position and its pin compatible with the arduino . I’m new gay in the programming and I need a clock counter up with big digits from 0 to 99 min and 59 sec . That means I need to see in my screen minuits and seconds . Also I need to reset the time when I push the button on the right position as I told you and simple start the time from the beginning . Is that possible to help me with the code ??? Until learn the methods with the code I need it and I can’t do it .

  3. hello!
    my name is Rishi Kaniyawala. I am I.T(8 sem, b.tech) student.i am currently working on “college bell system”.plz, can you send me your work(with diagram, fig, paper work, which component you used and your code)so, i can implement the system(useing Arduino Mega and RTC DS3231).

Leave a Reply

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