Keywords : RTC, Real Time Clock, DS1307, I2C Communication, RTC Library
INTRO : Real Time clocks are very much useful to keep track of time in most of the electronic appliances. Refer the below images for your reference. However if you are designing a circuit, it would important to make a one yourself rather than using a breakout board which would be much expensive and less convenient. Lets see how to get this done.
In this example I've selected DS1307 serial real time clock which actually would cost few cents.
You can download the datasheet from here. DS1307
Highlights from DS1307 Datasheet |
DS1307 typical connection Schematic |
DS1307 and Arduino Uno Connection Diagram |
Required components
- DS1307 Integrated IC (I've selected a DIP version of this)
- 32.768 KHz Watch Crystal (Very cheap and commonly available)
- CR2032 Battery and Battery Holder (Can use any other 3V Battery)
- 2 x 4.7k resistors (Pull-Up resistors for I2C communication)
- Breadboard
- Jumper Wires
- Arduino Uno (Can use any other microcontroller with I2C, Arduino is much easy)
See How I've Connected the circuit on breadboard,
DS1307 Arduino Circuit Assembly |
- Copy the I2C Scanner Code. (You can find the code from here)
- Connect Arduino to the PC
- From Tools, Select the Board and Port
- Then Upload the I2C Scanner Code
- Open the Serial Monitor (Select Baud rate as 9600)
DS1307 I2C Scan result |
Now Lets download the RTC Library.
1) Go to "Sketch" >> "Include Library" >> "Manage Libraries"
Installing RTC Library |
Installing RTC Library |
Installing RTC Library |
Now Lets try the example code
1) Go to "file" >> "examples" >> "RTCLib By NeiroN" >> "rtc_format" and open the code.
RTC Example Run |
2) Go to Tools and select the board and port
3) Upload the code
4) Open the Serial Monitor (Do not forget to change the Baud Rate to "57600"
RTC DS1307 Results |