How to use DS1307 RTC with Arduino and LCD/OLED
Hi, and welcome to this tutorial, it’s about another RTC (Real Time Clock) module, it’s the DS1307, previously I did a tutorial about the DS1302, and a project where I set it up using a keypad, then an Alarm Clock project based on that module, I also did a tutorial about the DS3132.

But today we’re about the DS1307, and I’m gonna use it with Arduino UNO board and I’ll also use a LCD i²c screen and OLED display, to show time and date in different formats.
“The DS1307 serial real-time clock (RTC) is a lowpower, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year.”
– MaximeIntegrated datasheet
Parts
For this tutorial I’ll be using the following parts, along side some jump wires and a breadboard these parts:
Wirings
For the LCD i²c version, both are connected with 5v and they both share A4/A5 for SDA/SCL

For the OLED version they both share 5V and A4/A5 for SDA/SCL

Libraries
- DS1307 RTC libraries: – Download here DS1307 library
– Download here Time Library
- LCD i²c library: Download here LCD i²c NewLiquidCrystal library
- OLED libraries: – Download here Adafruit OLED SSD1306 library – Download here Adafruit GFX Library
Codes
For the codes I’ve used to set the RTC module and print the Time/Date on the serial monitor are just examples from the RTC DS1307 library.
Important !! First time you must wire the module and upload the “SetTime” example, it sets the module to the compiling time of the code which is technically your real time and date.
N.B: If you are testing the module with multiple things it’s better to close the “SetTime” example, open it again and upload to the board, otherwise your module will be programmed with the first time the “SetTime” example was compiled, and you may think that your module doesn’t work well !!
And here are the codes I’ve made for the LCD and OLED:
- Download here 3 LCD codes
- Download here 3 OLED codes
Tests
LCD tests:



And for the OLED




That’s it for this RTC module, if you have any problem feel free to get in touch!
Categories
Yassine View All
Automation and Electrical Engineer, Electronics amateur trying to share my little projects.
Hey can you tell me how to change the code for OLED 128*64?
SCREEN_HEIGHT 32 make it 64, then you’ll have more space to play with when using SetCursor function…
Hİ ,
Your project is done ! Thank you 😉
https://ibb.co/F07XdQy
Regards…
how to interface 20×4 16-pin lcd display in code2