top of page
Writer's pictureSanskruti Ashtikar

Digital Clock with Alarm Using PIC Microcontroller

Introduction


Digital clocks are essential devices used in various applications, from simple household clocks to more complex timing systems. Adding an alarm feature to a digital clock enhances its functionality, making it useful for everyday purposes. This article will guide you through the design and implementation of a Digital Clock with Alarm using a PIC Microcontroller, providing step-by-step instructions on components, circuit design, and programming.


Components Required


  1. PIC Microcontroller: PIC16F877A or similar.

  2. RTC Module (Real-Time Clock): DS1307 or DS3231 for accurate timekeeping.

  3. 7-Segment Display or LCD Display: For displaying the time.

  4. Buzzer: For the alarm sound.

  5. Push Buttons: For setting the time and alarm.

  6. Resistors and Capacitors: For signal conditioning and circuit stability.

  7. Crystal Oscillator: For accurate clock generation.

  8. Power Supply: To power the microcontroller and other components.

  9. Connecting Wires and PCB: For assembling the circuit.


System Overview


The digital clock system is based on a Real-Time Clock (RTC) module, which keeps track of time accurately. The PIC microcontroller reads the time from the RTC module, displays it on a 7-segment or LCD display, and manages the alarm function. Users can set the time and alarm using push buttons, and the alarm is triggered when the current time matches the set alarm time.


Circuit Diagram


Here’s a simplified circuit diagram overview:

  1. RTC Module: The RTC module communicates with the PIC microcontroller via the I2C protocol.

  2. Display: The time is displayed on a 7-segment or LCD display.

  3. Buzzer: The buzzer is connected to a digital output pin of the microcontroller to produce an alarm sound.

  4. Push Buttons: Connect push buttons to the microcontroller's digital input pins for time and alarm setting.


RTC Module Configuration


RTC (Real-Time Clock) Module: The DS1307 or DS3231 RTC module is used for keeping track of the current time. These modules communicate with the PIC microcontroller using the I2C protocol, making them easy to integrate.

Connection:

  • Connect the SDA (data) and SCL (clock) lines of the RTC module to the corresponding I2C pins on the PIC microcontroller.

  • Connect the power (VCC) and ground (GND) pins to the respective rails.


Microcontroller Configuration


The PIC Microcontroller (e.g., PIC16F877A) reads the time from the RTC module, processes user inputs for time and alarm settings, and controls the display and buzzer.


Pin Configuration


  1. I2C Communication: Use the designated I2C pins (SDA and SCL) for communication with the RTC module.

  2. Display Output: Connect the display to appropriate I/O pins for time display.

  3. Buzzer Control: Connect the buzzer to a digital output pin.

  4. Push Button Inputs: Connect the push buttons to digital input pins with pull-up resistors.


Sample Code


Here’s a simplified code snippet for handling time display and alarm functionality:


#include <xc.h>
#include "lcd.h"
#include "ds1307.h"
#define _XTAL_FREQ 4000000
unsigned char hours, minutes, seconds;
unsigned char alarm_hours = 7, alarm_minutes = 0; // Set default alarm time
void main(void) {
    LCD_Init();
    DS1307_Init();
    
    while(1) {
        // Read time from RTC
        DS1307_Get_Time(&hours, &minutes, &seconds);
        
        // Display time on LCD
        LCD_Set_Cursor(1,1);
        LCD_Write_String("Time: ");
        LCD_Write_Number(hours);
        LCD_Write_Char(':');
        LCD_Write_Number(minutes);
        LCD_Write_Char(':');
        LCD_Write_Number(seconds);
        
        // Check if alarm time matches current time
        if (hours == alarm_hours && minutes == alarm_minutes) {
            // Trigger alarm
            PORTBbits.RB0 = 1; // Activate buzzer
            __delay_ms(1000);
            PORTBbits.RB0 = 0;
        }
        
        __delay_ms(1000); // Update every second
    }
}

Working of the System


  1. Initialization: Upon startup, the microcontroller initializes the LCD display and RTC module.

  2. Time Reading: The microcontroller continuously reads the current time from the RTC module.

  3. Display Update: The current time is displayed on the LCD or 7-segment display.

  4. Alarm Checking: The microcontroller compares the current time with the preset alarm time. If they match, the buzzer is activated.

  5. Time and Alarm Setting: Users can set the time and alarm using the push buttons. The microcontroller updates the RTC module with the new time settings.


Testing and Calibration


  1. Component Testing: Verify the functionality of the RTC module, display, and buzzer individually.

  2. RTC Calibration: Ensure that the RTC module is keeping accurate time. This can be checked against a known accurate clock.

  3. Button Functionality: Test the push buttons to ensure they correctly adjust the time and alarm settings.


Additional Features


To enhance the digital clock with alarm functionality, consider adding:

  1. Multiple Alarms: Allow users to set multiple alarms for different times of the day.

  2. Snooze Feature: Implement a snooze function that temporarily disables the alarm for a few minutes.

  3. Battery Backup: Include a battery backup for the RTC module to retain time settings during power outages.

  4. LED Indicator: Add an LED to indicate when the alarm is active.

  5. Temperature Display: Utilize the DS3231's built-in temperature sensor to display the current temperature along with the time.


Conclusion


A Digital Clock with Alarm using a PIC Microcontroller is a practical project that combines timekeeping and user interaction with an embedded system. By following this guide, you can build a functional digital clock with an alarm feature, complete with options for further customization and enhancements.


References


  • PIC16F877A Datasheet: Microchip

  • DS1307/DS3231 RTC Module Documentation: [Manufacturer's Website]

  • MPLAB X IDE: Microchip



Want us to guide you through your project or make the project for you ?







Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 


2 views0 comments

Related Posts

See All

Comments


bottom of page