In this tutorial Robo India explains how to make an Alarm Clock on LCD using Arduino.
1. Introduction:
In this tutorial we have made an alarm clock on LCD.
For this, we have attached four push buttons for setting time and alarm time as well. A buzzer attached, will start to beep when the time matches with the alarm time.
2. Required Hardware
Following Hardware will be required to perform this circuit.
S.No. | Item | Quantity |
1 | Arduino UNO | 1 |
2 | Breadboard | 1 |
3 | I2C LCD Backpack | 1 |
4 | Push Buttons | 4 |
5 | Buzzer | 1 |
6 | Male to Female Jumper | 4 |
7 | Male to Male Jumper | 11 |
3. Building Circuit
Make the following connections with Arduino-
4. Programming
You may download this Arduino Sketch from here.
//Robo India tutorial on LCD Alarm Clock //Hardware Required: LCD & Arduino //https://www.roboindia.com/tutorials #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <stdio.h> #include <ctype.h> LiquidCrystal_I2C lcd(0x3F,20, 4); // SET I2C Address /*---------Declaring Variables-----------*/ int starttime; int activetime; int prevoustime = 0; int hours = 0; int mins = 0; int ahours = 0; int amins = 0; /*---------Variables Declared -----------*/ void setup() { lcd.init(); lcd.backlight(); // makes Backligh ON. lcd.clear(); // Clears LCD lcd.print("00:00"); //display on LCD after code upload lcd.setCursor(10, 0); lcd.print("00:00"); lcd.setCursor(0, 1); lcd.print("Time"); lcd.setCursor(10, 1); lcd.print("Alarm"); pinMode(8, INPUT); pinMode(9, INPUT); pinMode(10, INPUT); pinMode(11, INPUT); pinMode(3, OUTPUT); digitalWrite(8, HIGH); digitalWrite(9, HIGH); digitalWrite(10, HIGH); digitalWrite(11, HIGH); digitalWrite(3, LOW); starttime = millis()/1000; } void loop() { /*------------------------------------------------ -------------------------------------------------- ------------------Code begins to set Alarm-------- -------------------------------------------------- --------------------------------------------------*/ while(digitalRead(8) == LOW) { lcd.setCursor(10,1); lcd.print("Alarm"); lcd.setCursor(10,0); if(digitalRead(11) == LOW) //while pressing button connected to D8 { amins++; } else if (digitalRead(10) == LOW) { ahours++; } lcd.setCursor(10,0); /*-----Code to display alarm time in 00:00 format------*/ if(ahours < 10) { lcd.print("0"); lcd.print(ahours); } else { lcd.print(ahours); } lcd.print(":"); if (amins < 10) { lcd.print("0"); lcd.print(amins); } else { lcd.print(amins); } /*----Validation for 24 hours clock------*/ if(amins > 59) { ahours++; amins = 0; } if(ahours > 23) { ahours = 0; } delay(500); } /*------------------------------------------------ -------------------------------------------------- ------------------Code begins to set Time-------- -------------------------------------------------- --------------------------------------------------*/ if(digitalRead(9) == LOW) { lcd.setCursor(0,1); lcd.print("Time"); lcd.setCursor(0,0); if(digitalRead(11) == LOW) //while pressing button connected to D9 { mins++; } else if (digitalRead(10) == LOW) { hours++; } } /*--------Validation for 24 hours clock value----------*/ activetime = (millis() / 1000) - starttime; if(prevoustime < (activetime - 59)) { mins++; prevoustime = activetime; } if(mins > 59) { hours++; mins = 0; } if(hours > 23) { hours = 0; } /*--------code to display Time in 00:00 format----------*/ lcd.setCursor(0,0); if(hours < 10) { lcd.print("0"); lcd.print(hours); } else { lcd.print(hours); } lcd.print(":"); if (mins < 10) { lcd.print("0"); lcd.print(mins); } else { lcd.print(mins); } if (ahours == hours && amins == mins && amins != 0) { digitalWrite(3, HIGH); delay(200); digitalWrite(3, LOW); delay(200); } }
5. Output
Let say, the button connected to D8 pin of Arduino — Button 1.
The button connected to D9 pin of Arduino — Button 2.
The button connected to D10 pin of Arduino — Button 3.
The button connected to D11 pin of Arduino — Button 4.
Button 1 is to set Alarm time and Button 2 is to set Time displays on LCD. Button 3 is used to set hours and button 4 is used to set minutes according to Arduino IDE code.
To set TIME press button 3 and button 4, while holding button 2.
Similarly, to set ALARM time press button 3 and button 4, while holding button 1. Above code display time in 24 hours clock format. You can modify the code according to clock format.
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team
Robo India
https://roboindia.com