This is an old revision of the document!
• The goal and purpose of this project is to build and design a simple Digital Clock with Alarm and LED Matrix Display, to displays the current time on LED display and it also can be set to sound an Alarm on a specific time. The clock uses an LED matrix to display the time, and a buzzer to sound the alarm.
• The idea of this project comes from an actual Digital clock but I added the Alarm function.
The following components are required for this project:
• Tiny RTC module with I2C interface
• LED matrix (8×8 or higher)
• 3 Push buttons
• Buzzer for alarm sound
• Arduino Uno
• Breadboard
* 3 Resistors
• Wires
The following software requirements are necessary for this project:
• RTC library (e.g., DS1307)
• GPIO library for controlling LED matrix
• Timer function to update the time and trigger the alarm
• Button input and buzzer output code
#include <Wire.h>
#include <RTClib.h>
#include <LedControl.h>
const int buttonPin = 2;
const int buzzerPin = 9;
const int dinPin = 12; Data input pin const int clkPin = 11; const int csPin = 10; LedControl ledMatrix = LedControl(dinPin, clkPin, csPin, 0); Use type 0 for MAX7219
const int rtcSdaPin = A4; RTC SDA pin const int rtcSclPin = A5; RTC SCL pin
RTC_DS1307 rtc;
int alarmHourSet = 0;
int alarmMinuteSet = 0;
byte digitPatterns[10][8] = {
{B0111110, B1000001, B1000001, B1000001, B1000001, B1000001, B1000001, B0111110}, // Digit 0
{B0000000, B0000001, B0000001, B0000000, B0000000, B0000000, B0000001, B0000001}, // Digit 1
{B0111011, B1000100, B0000100, B0000100, B0000100, B0000100, B1000100, B1111111}, // Digit 2
{B0111110, B0000001, B0000001, B0111110, B1000000, B1000000, B1000000, B0111110}, // Digit 3
{B1000001, B1000001, B1000001, B1111111, B0000001, B0000001, B0000001, B0000001}, // Digit 4
{B1111111, B1000000, B1000000, B1111110, B0000001, B0000001, B1000001, B0111110}, // Digit 5
{B0011110, B0100001, B1000000, B1111110, B1000001, B1000001, B1000001, B0111110}, // Digit 6
{B1111111, B0000001, B0000001, B0000001, B0000001, B0000001, B0000001, B0000001}, // Digit 7
{B0111110, B1000001, B1000001, B0111110, B1000001, B1000001, B1000001, B0111110}, // Digit 8
{B0111110, B1000001, B1000001, B1000001, B1000001, B0111110, B0000001, B0000001} // Digit 9
};
void setup() {
Serial.begin(9600); Wire.begin();
pinMode(rtcSdaPin, INPUT_PULLUP); pinMode(rtcSclPin, INPUT_PULLUP); rtc.begin();
pinMode(buttonPin, INPUT_PULLUP); pinMode(buzzerPin, OUTPUT);
ledMatrix.shutdown(0, false); // Wake up the MAX7219 module ledMatrix.setIntensity(0, 1); // Set the LED matrix brightness (0-15) ledMatrix.clearDisplay(0); // Clear the display
// Set the initial alarm time setAlarmTime();
}
void loop() {
checkButton(); displayTime();
}
void setAlarmTime() {
Serial.println("Enter alarm time (hh:mm):"); while (!Serial.available()) { // Wait for input from the serial monitor } delay(100);
String input = Serial.readString(); int separatorIndex = input.indexOf(':');
if (separatorIndex > 0) { String hourString = input.substring(0, separatorIndex); String minuteString = input.substring(separatorIndex + 1);
alarmHourSet = hourString.toInt(); alarmMinuteSet = minuteString.toInt();
Serial.print("Alarm time set: "); Serial.println(input); } else { Serial.println("Invalid input format. Please try again."); setAlarmTime(); }
}
void checkButton() {
static bool buttonPressed = false;
if (digitalRead(buttonPin) == LOW && !buttonPressed) { // Button is pressed for the first time, activate the buzzer toggleAlarm(); buttonPressed = true; } else if (digitalRead(buttonPin) == HIGH && buttonPressed) { // Button is released, reset the button pressed flag buttonPressed = false; }
}
void toggleAlarm() {
static bool alarmOn = false; alarmOn = !alarmOn;
if (alarmOn) { digitalWrite(buzzerPin, HIGH); } else { digitalWrite(buzzerPin, LOW); }
}
void displayTime() {
DateTime now = rtc.now(); int currentHour = now.hour(); int currentMinute = now.minute();
int hourTens = currentHour / 10; int hourOnes = currentHour % 10; int minuteTens = currentMinute / 10; int minuteOnes = currentMinute % 10;
// Display the hour tens digit for (int i = 0; i < 8; i++) { byte pattern = digitPatterns[hourTens][i]; ledMatrix.setRow(0, i, pattern); }
// Display the hour ones digit for (int i = 0; i < 8; i++) { byte pattern = digitPatterns[hourOnes][i]; ledMatrix.setRow(0, i + 8, pattern); }
// Display the minute tens digit for (int i = 0; i < 8; i++) { byte pattern = digitPatterns[minuteTens][i]; ledMatrix.setRow(0, i + 16, pattern); }
// Display the minute ones digit for (int i = 0; i < 8; i++) { byte pattern = digitPatterns[minuteOnes][i]; ledMatrix.setRow(0, i + 24, pattern); }
}
What were the results obtained after the realization of your project.
An archive (or more if necessary) with the files obtained as a result of the project: sources, schemes, etc. A README file, a ChangeLog, a build script and automatic copy on uC always make a good impression .
The files are uploaded to the wiki using the Add Images or other files feature. The namespace in which the files are uploaded is of the type :pm:prj20??:c? or :pm:prj20??:c?:student_name (if applicable). Example: Dumitru Alin, 331CC → :pm:prj2009:cc:dumitru_alin.
You can also have a journal section where the project assistant can track the progress of the project.
List of documents, datasheets, Internet resources used, possibly grouped by Software Resources and Hardware Resources.