Arduino Based Digital Clock With Alarm Using 1602 LCD

Introduction: Arduino Based Digital Clock With Alarm Using 1602 LCD

Hi guys in this instructables we will learn how to make a digital clock from arduino using LCD display and we can also set a alarm with as well.

Step 1: Things You Need

These following things you will need for this instructables :

Arduino uno/nano/pro_mini

1602 LCD display
7805 voltage regulator

Resistors


BC547 Transistors


DS1307 RTC


32KHZ CRYSTAL OSCILLATOR

Buzzer

3v coin cell

Connecting wires

Breadboard

Step 2: Circuit Diagram

In this Arduino based digital clock circuit, we have used three major components which are IC DS1307, Arduino Pro Mini Board and 16x2 LCD module.
Here arduino is used for reading time from ds1307 and display it on 16x2 LCD. DS1307 sends time/date using 2 lines to arduino. A buzzer is also used for alarm indication, which beeps when alarm is activated. A block diagram is shown below to understand the working of this Real Time Clock.

As you can see in the circuit diagram, DS1307 chip pin SDA and SCL are connected to arduino pins SDA and SCL with pull up resistor that holds default value HIGH at data and clock lines. 32.768KHz crystal oscillator is connected with DS1307chip for generating exact 1 second delay, and a 3 volt battery is also connected to pin 3rd (BAT) of DS1307 which keeps time running after electricity failure.16x2 LCD is connected with arduino in 4-bit mode. Control pin RS, RW and En are directly connected to arduino pin 2, GND and 3. And data pin D0-D7 is connected to 4, 5, 6, 7 of arduino. A buzzer is connected with arduino pin number 13 through a NPN BC547 transistor having a 1 k resistor at its base.

Three buttons namely set, INC and Next are used for setting alarm to pin 12, 11 and 10 of arduino in active low mode. When we press set, alarm set mode activates and now we need to set alarm by using INC button and Next button is used for moving to digit.

Step 3: Code

Please copy the following following code and upload it to the arduino. :


#include "Wire.h"
#include "EEPROM.h"
#include "RTClib.h"
#include "LiquidCrystal.h"
LiquidCrystal lcd(3, 2, 4, 5, 6, 7);
RTC_DS1307 RTC;
int temp,inc,hours1,minut,add=11;
int next=10;
int INC=11;
int set_mad=12;
#define buzzer 13
int HOUR,MINUT,SECOND;

void setup()
{
Wire.begin();
RTC.begin();
lcd.begin(16,2);
pinMode(INC, INPUT);
pinMode(next, INPUT);
pinMode(set_mad, INPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(next, HIGH);
digitalWrite(set_mad, HIGH);
digitalWrite(INC, HIGH);

lcd.setCursor(0,0);
lcd.print("Real Time Clock");
lcd.setCursor(0,1);
delay(2000);

if(!RTC.isrunning())
{
RTC.adjust(DateTime(__DATE__,__TIME__));
}
}

void loop()
{
int temp=0,val=1,temp4;
DateTime now = RTC.now();
if(digitalRead(set_mad) == 0) //set Alarm time
{
lcd.setCursor(0,0);
lcd.print(" Set Alarm ");
delay(2000);
defualt();
time();
delay(1000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Alarm time ");
lcd.setCursor(0,1);
lcd.print(" has been set ");
delay(2000);
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time:");
lcd.setCursor(6,0);
lcd.print(HOUR=now.hour(),DEC);
lcd.print(":");
lcd.print(MINUT=now.minute(),DEC);
lcd.print(":");
lcd.print(SECOND=now.second(),DEC);
lcd.setCursor(0,1);
lcd.print("Date: ");
lcd.print(now.day(),DEC);
lcd.print("/");
lcd.print(now.month(),DEC);
lcd.print("/");
lcd.print(now.year(),DEC);
match();
delay(200);
}
void defualt()
{
lcd.setCursor(0,1);
lcd.print(HOUR);
lcd.print(":");
lcd.print(MINUT);
lcd.print(":");
lcd.print(SECOND);
}
/*Function to set alarm time and feed time into Internal eeprom*/
void time()
{
int temp=1,minuts=0,hours=0,seconds=0;
while(temp==1)
{
if(digitalRead(INC)==0)
{
HOUR++;
if(HOUR==24)
{
HOUR=0;
}
while(digitalRead(INC)==0);
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Set Alarm Time ");
//lcd.print(x);
lcd.setCursor(0,1);
lcd.print(HOUR);
lcd.print(":");
lcd.print(MINUT);
lcd.print(":");
lcd.print(SECOND);
delay(100);
if(digitalRead(next)==0)
{
hours1=HOUR;
EEPROM.write(add++,hours1);
temp=2;
while(digitalRead(next)==0);
}
}

while(temp==2)
{
if(digitalRead(INC)==0)
{
MINUT++;
if(MINUT==60)
{MINUT=0;}
while(digitalRead(INC)==0);
}
// lcd.clear();
lcd.setCursor(0,1);
lcd.print(HOUR);
lcd.print(":");
lcd.print(MINUT);
lcd.print(":");
lcd.print(SECOND);
delay(100);
if(digitalRead(next)==0)
{
minut=MINUT;
EEPROM.write(add++, minut);
temp=0;
while(digitalRead(next)==0);
}
}
delay(1000);
}
/* Function to chack medication time */
void match()
{
int tem[17];
for(int i=11;i<17;i++)
{
tem[i]=EEPROM.read(i);
}
if(HOUR == tem[11] && MINUT == tem[12])
{
beep();
beep();
beep();
beep();
lcd.clear();
lcd.print("Wake Up........");
lcd.setCursor(0,1);
lcd.print("Wake Up.......");
beep();
beep();
beep();
beep();
}
}
/* function to buzzer indication */
void beep()
{
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer, LOW);
delay(500);
}

Step 4: Testing the Clock

So after uploading the code and connecting everything together and you will see the clock running in the LCD display and you can even set the alarm in it as i did it in images. So have fun making your alarm clock with your arduino.

1 Person Made This Project!

Recommendations

  • Explore Science Challenge

    Explore Science Challenge
  • Make it Real Student Design Challenge #3

    Make it Real Student Design Challenge #3
  • Colors of the Rainbow Contest

    Colors of the Rainbow Contest

Comments

0
wilzzonb
wilzzonb

Tip 11 months ago

muy útil y práctico, gracias por compartir.con cambio en la librería y lineas de código logre adaptarle un módulo I2C (Conversor I2c Pfc8574at ) a la LCD 2X16.
***************************************
.
.
.
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x3F
LiquidCrystal_I2C lcd(I2C_ADDR,2, 1, 0, 4, 5, 6, 7) ;
.
.
.
.
***************************************