Skip to content

Arduino Alarm Clock Project

Build a fully functional alarm clock with an Arduino Uno, LCD display, and buttons. Set the time, configure alarms, and wake up to a piezo buzzer.

  • Arduino
  • Intermediate
  • 60 to 90 minutes
  • 6 steps

Shop this project

Cart

Prices from vilros.com. Tax and shipping at checkout.

Before you start, you'll need

  • An Arduino Uno (or compatible board) with USB cable
  • A computer with Arduino IDE installed
  • A breadboard and at least 13 jumper wires
  • Four 10kΩ resistors and one 100Ω resistor
  • A 20x4 LCD screen with serial connection
  • Seven pushbuttons
  • A piezo speaker/buzzer

Connect power rails

About 5 minutes

Establish 5V and ground power distribution on the breadboard.

  1. Connect a jumper wire from the Arduino's 5V pin to one of the + rails on the breadboard.
  2. Connect a jumper wire from the Arduino's GND pin to the - rail next to the + rail you chose.

You should see

Power and ground rails are connected to the Arduino and ready to distribute to components.

Connect the LCD screen

About 5 minutes

Wire the LCD display for serial communication.

  1. Connect the LCD screen's power pin to the 5V rail on the breadboard.
  2. Connect the LCD screen's ground pin to the GND rail.
  3. Connect the LCD screen's TX (transmit) pin to Arduino digital pin 1.

You should see

The LCD screen is wired for power and serial communication through pin 1.

Wire the buttons and resistors

About 15 minutes

Place seven buttons with pull-down resistors for time and alarm controls.

  1. Place seven pushbuttons on the breadboard with their legs across the center gap.
  2. Connect 10kΩ resistors from each button's bottom-left pin to the GND rail (pull-down configuration).
  3. Connect jumper wires from each button's bottom-right pin to the 5V rail.
  4. Wire the button pins (where resistors connect) to Arduino pins 6, then 8 through 13 (one button per pin).

You should see

Seven buttons are wired with pull-down resistors. From left to right, they connect to pins 13, 12, 11, 10, 9, 8, and 6.

It didn't work
  • Buttons don't respond or respond erratically.

    Check that each button's legs span the breadboard center gap. Verify 10kΩ resistors connect the button pins to GND, and 5V connects to the opposite side.

Wire the piezo speaker

About 5 minutes

Connect the alarm buzzer.

  1. Place the piezo speaker on the breadboard.
  2. Connect Arduino pin 7 to the speaker's positive (power) pin.
  3. Connect a 100Ω resistor from the speaker's negative pin to the GND rail.

You should see

The piezo speaker is wired to pin 7 with a current-limiting resistor to ground.

Upload the alarm clock sketch

About 20 minutes

Program the Arduino to display time, read button inputs, and trigger alarms.

  1. Open a new sketch in the Arduino IDE and paste the complete code below.
  2. Verify the code compiles without errors.
  3. Click Upload to send the sketch to your Arduino.
Arduino C++
// Arduino Alarm Clock Project
// 20x4 LCD, 7 buttons, piezo speaker

// Initialize variables
int hour = 0;           // Current hour
int minute = 0;         // Current minute
int second = 0;         // Current second
int hour_a = 0;         // Alarm hour
int minute_a = 0;       // Alarm minute
bool am_pm = false;     // Current AM/PM (false = AM, true = PM)
bool am_pm_a = false;   // Alarm AM/PM
int set_hr = 13;        // Pin 13: set current hour
int set_min = 12;       // Pin 12: set current minute
int set_am_pm = 11;     // Pin 11: set current AM/PM
int set_hr_a = 10;      // Pin 10: set alarm hour
int set_min_a = 9;      // Pin 9: set alarm minute
int set_am_pm_a = 8;    // Pin 8: set alarm AM/PM
int speaker = 7;        // Pin 7: speaker output
int quiet = 6;          // Pin 6: silence alarm button
bool alarm = false;     // Alarm active flag
bool quieted = false;   // Alarm silenced flag
int cur_time = 0;       // Current millis() snapshot
int etime = 0;          // Elapsed time

void setup() {
  // Initialize LCD at 9600 baud
  Serial.begin(9600);
  Serial.write(17);     // Backlight on
  Serial.write(24);     // Display on, cursor, no blink
  Serial.write(12);     // Clear screen
  Serial.write(128);    // Cursor to top-left
  
  // Set pin modes
  pinMode(set_hr, INPUT);
  pinMode(set_min, INPUT);
  pinMode(set_am_pm, INPUT);
  pinMode(set_hr_a, INPUT);
  pinMode(set_min_a, INPUT);
  pinMode(set_am_pm_a, INPUT);
  pinMode(speaker, OUTPUT);
  pinMode(quiet, INPUT);
  
  // Prompt user to set current time
  Serial.print("Set the current time");
  delay(2000);
  Serial.write(12);
  printTimes();
  cur_time = millis();
}

void loop() {
  // Update time
  keepTime();
  
  // Check if alarm should sound
  if ((hour == hour_a && minute == minute_a && !quieted) || alarm) {
    tone(speaker, 2000, 500);  // 2000 Hz for 500ms
    delay(500);
    if (!alarm) {
      alarm = true;  // Start alarm
    }
  }
  
  // Silence alarm if quiet button pressed
  if (alarm && !quieted && digitalRead(quiet)) {
    alarm = false;
    quieted = true;
  }
  
  // Reset quieted flag when minute changes
  if (!alarm && quieted && minute != minute_a) {
    quieted = false;
  }
  
  // Button inputs: set current hour
  if (digitalRead(set_hr) && hour < 12) {
    hour++;
    printTimes();
    debounce();
  } else if (digitalRead(set_hr) && hour == 12) {
    hour = 1;
    printTimes();
    debounce();
  }
  
  // Set current minute
  if (digitalRead(set_min) && minute < 59) {
    minute++;
    printTimes();
    debounce();
  } else if (digitalRead(set_min) && minute == 59) {
    minute = 0;
    printTimes();
    debounce();
  }
  
  // Set current AM/PM
  if (digitalRead(set_am_pm) && am_pm) {
    am_pm = false;
    printTimes();
    debounce();
  } else if (digitalRead(set_am_pm) && !am_pm) {
    am_pm = true;
    printTimes();
    debounce();
  }
  
  // Set alarm hour
  if (digitalRead(set_hr_a) && hour_a < 12) {
    hour_a++;
    printTimes();
    debounce();
  } else if (digitalRead(set_hr_a) && hour_a == 12) {
    hour_a = 1;
    printTimes();
    debounce();
  }
  
  // Set alarm minute
  if (digitalRead(set_min_a) && minute_a < 59) {
    minute_a++;
    printTimes();
    debounce();
  } else if (digitalRead(set_min_a) && minute_a == 59) {
    minute_a = 0;
    printTimes();
    debounce();
  }
  
  // Set alarm AM/PM
  if (digitalRead(set_am_pm_a) && am_pm_a) {
    am_pm_a = false;
    printTimes();
    debounce();
  } else if (digitalRead(set_am_pm_a) && !am_pm_a) {
    am_pm_a = true;
    printTimes();
    debounce();
  }
}

// Debounce: wait until all buttons released, then delay
void debounce() {
  while (digitalRead(set_hr) || digitalRead(set_min) ||
         digitalRead(set_am_pm) || digitalRead(set_hr_a) ||
         digitalRead(set_min_a) || digitalRead(set_am_pm_a)) {}
  delay(250);
}

// Update LCD display with current time and alarm
void printTimes() {
  Serial.write(12);  // Clear screen
  Serial.print("Current Time:");
  Serial.write(148); // Move cursor to second line
  
  if (hour < 10) Serial.print("0");
  Serial.print(hour);
  Serial.print(":");
  if (minute < 10) Serial.print("0");
  Serial.print(minute);
  Serial.print(":");
  if (second < 10) Serial.print("0");
  Serial.print(second);
  Serial.print(am_pm ? " PM" : " AM");
  
  Serial.write(168); // Move cursor to third line
  Serial.print("Alarm Set for:");
  Serial.write(188); // Move cursor to fourth line
  
  if (hour_a < 10) Serial.print("0");
  Serial.print(hour_a);
  Serial.print(":");
  if (minute_a < 10) Serial.print("0");
  Serial.print(minute_a);
  Serial.print(am_pm_a ? " PM" : " AM");
}

// Keep time using millis()
void keepTime() {
  etime = millis() - cur_time;
  
  if (etime >= 1000 && second < 59) {
    second++;
    cur_time = millis();
    printTimes();
  } else if (etime >= 1000 && second == 59 && minute < 59) {
    second = 0;
    minute++;
    cur_time = millis();
    printTimes();
  } else if (etime >= 1000 && second == 59 && minute == 59 && hour < 12) {
    second = 0;
    minute = 0;
    hour++;
    cur_time = millis();
    printTimes();
  } else if (etime >= 1000 && second == 59 && minute == 59 && hour == 12) {
    second = 0;
    minute = 0;
    hour = 1;
    am_pm = !am_pm;
    cur_time = millis();
    printTimes();
  }
}

This sketch uses Serial communication for the LCD (9600 baud). Button layout from left to right: set hour, set minute, set AM/PM, set alarm hour, set alarm minute, set alarm AM/PM, silence alarm.

You should see

The sketch uploads successfully. The LCD prompts you to set the current time.

It didn't work
  • LCD shows garbled text or nothing at all.

    Check the LCD wiring (power, ground, TX to pin 1). Ensure the LCD is configured for 9600 baud serial communication. Some LCDs require initialization commands that differ from this sketch.

  • Compilation error about 'Serial'.

    Make sure you've selected the correct board (Arduino Uno) under Tools → Board. The Serial library is built into Arduino.

Set the time and test the alarm

About 10 minutes

Verify time-keeping and alarm functionality.

  1. Use the first three buttons to set the current hour, minute, and AM/PM.
  2. Use the next three buttons to set an alarm time a few minutes ahead.
  3. Watch the LCD update the current time every second.
  4. When the current time matches the alarm time, the piezo speaker should beep repeatedly.
  5. Press the seventh button (pin 6) to silence the alarm.

You should see

The clock keeps accurate time, the alarm sounds at the set time, and the silence button stops the alarm.

It didn't work
  • Time doesn't increment or increments too fast/slow.

    The sketch uses millis() for timing. Check that the Arduino isn't resetting (power issue). If time drifts significantly, the millis() clock runs at the chip's speed, which can vary slightly.

  • Alarm doesn't sound.

    Verify the piezo speaker wiring (pin 7 to positive, 100Ω resistor to ground). Test the speaker by uploading a simple tone() sketch to confirm the speaker works.

  • Buttons increment values multiple times per press.

    The debounce() function should prevent this. Check that all button pins are wired correctly and that pull-down resistors are in place.

What to do next

Stuck? Contact Vilros Support with your board model and what you see on screen.