Arduino Alarm Clock
In this tutorial, I will try to explain how to implement a Real Time Clock (RTC) with alarm which is a battery powered clock that measures power even when there is no external power or the microcontroller is reprogrammed.
The battery which is connected to the RTC is a separate one and is not related or connected to the main power supply. An RTC displays clock and calendar with all timekeeping functions. Below are the hardware components required for this project.
- Arduino UNO
- 3 Push Buttons
- DS 1307 RTC Module
- 16x2 LCD Display
- 2 10K resistors
- 10K potentiometer
Now onto the hardware description!
I will give you a brief introduction about DS 1307 first and then a summary of the circuit design.
DS 1307 is basically the frequency used RTC IC for clock and calendar. The clock function provides seconds, minutes and hours while the calendar function provides day, date, month and year values. The clock can either operate in 12 hour with AM/PM indication or 24-hour format. A 3V backup battery must be connected to the RTC so that the IC can automatically switch to backup supply in case of power failure.
Now let’s talk about the circuit. The communication between the microcontroller (UNO) and DS 1307 is serial I2 C bidirectional bus. There are two pins on Arduino for I2 C communication. Analog pins 4 and 5 will act as SDA (Serial Data) and SCL (Serial Clock). These are connected to the SDA and SCL pins of DS 1307. Both of these pins are pulled high using 10K resistors. An LCD is used to display the clock. 6 pins of LCD must be connected to UNO, RS, E, D5, D6, D7 (Pins 4,6,11,12,13 and 14) of LCD are connected to pins 2,3,4,5,6 and 7 of UNO. Three buttons are used to set the alarm. These pins are connected to pins 8,9 and 10 of UNO. A buzzer is connected to pin 11 of UNO and acts as an alarm. Below is the hardware overview of the project.
NOTE: I have assumed that you are aware of the communication protocol we are using here and the DS 1307 module requires 5V battery but I have used 3V battery here for demonstration purposes.
We can now focus in the software design!
Pins 8,9 and 10 as you know represent the pushbuttons. Pin 8 represents the NEXT pushbutton, pin 9 the INCREMENT pushbutton and pin 10 represents the SET pushbutton. The working of the code is explained in the below points.
- The code will be uploaded to UNO and the LCD will display the current date and time.
- In order for the alarm to be set, the SET pushbutton must be pressed which will make it go alarm mode. It will ask for hours with current time being displayed, the INCREMENT button be pressed to change the hours.
- The clock is 24 hour format so the hours will be incremented between 0 and 23. Once the hours of the alarm is set we will go to the minutes by pressing the NEXT button.
- The INCREMENT button is pressed again to change the minutes. SET button is pressed again and the alarm will be set.
- The values entered as alarm are stored in EEPROM of the UNO. These values are compared continuously with the present time.
- When stored values matches the current value, the buzzer will go off. In order to stop the alarm, the NEXT button is pressed.
Below is the code for the whole project.
Share this post
- 0 comment
- Tags: engineering, iot, MCU's, modemcu, power, power supply, powerup, programming, project, raspberry pi, resistors, reverse engineering, sensor