In this session we are going to Interface Real Time Clock Module DS1307 with Raspberry PI to make an Alarm Clock. Although Raspberry Pi has an internal clock, but without internet connection this internal clock resets after every reboot. So to get accurate TIME without internet connection, we need to interface a RTC Module DS1307 to Raspberry Pi. RTC module has button battery for backup so the TIME will not reset. We have also built Alarm Clock using Arduino and using ATmega32 AVR Microcontroller, check them too.
In this Raspberry Pi Digital Clock, a 16*2 Character LCD is to display Real Time, Alarm time and status of the alarm (ON/OFF). Once the program starts running in Pi, we can disconnect the monitor and can set the alarm with the help of this LCD and five buttons.
Each of 17 GPIO pins can deliver or draw a maximum of 15mA current. So do not play with GPIO pins and check the connections twice before powering the Raspberry Pi. Learn more about GPIO Pins and interfacing button with Raspberry Pi here. Also check our Raspberry Pi Tutorial Series along with some good IoT Projects.
Here we are using Raspberry Pi 2 Model B with Raspbian Jessie OS. All the basic Hardware and Software requirements are previously discussed, you can look it up in the Raspberry Pi Introduction and Raspberry PI LED Blinking for getting started, other than that we need:
- Raspberry Pi with pre-installed OS
- RTC Module DS1307 with Battery
- Power supply
- 1KΩ resistor (6 pieces)
- 5 buttons
- 1000uF capacitor (2 pieces)
- 16*2 character LCD
- 2N2222 transistor
Setup Raspberry Pi for Alarm clock:
Before going any further, we need to configure Raspberry Pi a little bit and install the library file for RTC Module, follow below steps:
Step 1: First go to Raspberry Pi configuration menu and enable I2C option as shown below:
Step 2: Create a new folder on Raspberry Pi desktop screen and name it as “Alarm Clock”
Step 3: Download the Header File for RTC module from below link:
Step 4: Unzip the downloaded zip file into the folder (Alarm Clock) created on DESKTOP, as told in previous step.
Step 5: Open the terminal window in Raspberry Pi and enter below command, then press enter:
sudo apt-get install i2c-tools
This command installs I2C tools required for interfacing RTC module. Then reboot the Raspberry pi by issuing ‘sudo reboot’ command.
Step 6: Now we need to check the I2C address of RTC module. Before checking the address, first connect the RTC module as shown in the Circuit Diagram below.
Then enter below in terminal window.
sudo i2cdetect -y 0 OR sudo i2cdetect -y 1
Step 7: If either of above commands works, you will see something like this:
Step 8: You will see I2C address 0x68 if RTC module is connected properly, record the value.
With this all the necessary adjustments are done with Raspberry Pi configuration.