ShawnMuller
Published © LGPL

Alarm Clock

A digital alarm clock utilizing an LCD screen, button, speaker and LED.

IntermediateShowcase (no instructions)732
Alarm Clock

Things used in this project

Hardware components

Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Switch Actuator, Head for spring return push-button
Switch Actuator, Head for spring return push-button
×1
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1
5 mm LED: Green
5 mm LED: Green
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Story

Read more

Schematics

lcd circuit diagram

Code

Arduino Alarm Clock

C/C++
The initial times can be changed in the void set up. Upload to the arduino and it will run.
// Author: Shawn Muller on 7/5/18
// Modified 8/13/19
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// arduino pin number connections
// LCD pins
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int buttonPin = 8;   // pushbutton pin
const int speakerPin = 7;  // speaker pin

//initialilization of variables
int AM = 1;
int PM = 0;
int hour = 6;
int minute = 55;
int alarmHour = 7;
int alarmMinute = 0;
String alarmTOD = "AM";
String timeOfDay = "AM";
int buttonState = 0; // variable for tracking if the button is on or off
int speakerState = 0; // variable for tracking if the speaker is on or off
void setup() {
  pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
  pinMode(speakerPin, OUTPUT); // initialize the speaker pin as an output
  // set up the LCD's columns and rows:
  lcd.begin(16,2);
  //Time set up
  lcd.setCursor(0,0);
  lcd.print("Time:");
  lcd.setCursor(9,0);
  lcd.print("06");
  lcd.print(":");
  lcd.print("55");
  lcd.print(timeOfDay);
  //Alarm set up
  lcd.setCursor(0,1);
  lcd.print("Alarm:");
  lcd.setCursor(9,1);
  lcd.print("07");
  lcd.print(":");
  lcd.print("00");
  lcd.print("AM");
}

void loop() { 
//if the alarm time is the current time 
  if(hour == alarmHour && minute == alarmMinute && alarmTOD.equals(timeOfDay)){ 
//clear lcd screen
    lcd.setCursor(0,0);
    lcd.print("                            ");
    lcd.setCursor(0,1);   
    lcd.print("                            ");
//print alarm message
    lcd.setCursor(5,0);
    lcd.print("Wake Up!");
    lcd.setCursor(3,1);
    lcd.print("It's ");
//if hour < 10 print a zero first
    if(alarmHour < 10)
    lcd.print("0");
    lcd.print(alarmHour);
    lcd.print(":");
//if minute < 10 print a zero first
  if(alarmMinute < 10)
    lcd.print("0");
    lcd.print(alarmMinute);
    lcd.print(alarmTOD);
    // turn on the speaker
    digitalWrite(speakerPin, HIGH);
    // read the state of the pushbutton value:
    buttonState = digitalRead(buttonPin);
    tone(7, 800);  // generates a tone of 800 Hz 
    // while the button is not pressed, display wake up  
    while (buttonState != HIGH){
      buttonState = digitalRead(buttonPin); // gets current state of the button
      // run until the button is pressed
    }
    noTone(7); // turn off the speaker
    digitalWrite(speakerPin, LOW); // turn off the speaker
//clear lcd screen
    lcd.setCursor(0,0);
    lcd.print("                            ");
    lcd.setCursor(0,1);   
    lcd.print("                            ");
    // display good morning
    lcd.setCursor(2,0);
    lcd.print("Good Morning");
    lcd.setCursor(3,1);
    lcd.print("Shawn Muler");
    delay(5000); // 5 second delay
//clear lcd screen
    lcd.setCursor(0,0);
    lcd.print("                            ");
    lcd.setCursor(0,1);   
    lcd.print("                            ");
//print Time:
    lcd.setCursor(0,0);
    lcd.print("Time: ");
    lcd.setCursor(9,0);
//if hour < 10 print a zero first
  if(hour < 10)
    lcd.print("0");
    lcd.print(hour);
    lcd.print(":");
    if(minute < 10)
    lcd.print("0");
    lcd.print(minute);
    lcd.print(timeOfDay); 
//print alarm time
    lcd.setCursor(0,1);
    lcd.print("Alarm:");
    lcd.setCursor(9,1);
    if(alarmHour < 10)
    lcd.print("0");
    lcd.print(alarmHour);
    lcd.print(":");
    if(alarmMinute < 10)
    lcd.print("0");
    lcd.print(alarmMinute);
    lcd.print(alarmTOD); 
    delay(2000);  
}
// adjust variables for clock
//60 second delay
    delay(60000);
// 1 second delay
  //delay(1000);
  minute++;
// resets minute
  if(minute == 60){
    hour++;
    minute = 0;}
// resets hour
  if(hour == 13)
    hour = 1;
//Adjusts AM and PM
// to PM
  if(hour == 12 && minute == 0 && AM == 1){
    AM = 0;
    PM = 1;
    lcd.setCursor(14,0);
    lcd.print("PM");
    timeOfDay = "PM";}
// to AM
  else if(hour == 12 && minute == 0 && PM == 1){ 
    PM = 0;
    AM = 1;
    lcd.setCursor(14,0);
    lcd.print("AM");
    timeOfDay = "AM";}
// Update lcd screen
//print hour
  lcd.setCursor(9,0);
  if(hour < 10)
  lcd.print("0");
  lcd.print(hour);
//print minute
  lcd.setCursor(12,0);
  if(minute < 10)
  lcd.print("0");
  lcd.print(minute);
} 

Credits

ShawnMuller
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.