I tried to make digital clock which just display the time.
I used: Arduino Uno R3, DS1307 (rtc module), ssd1306 (OLED Display), 3V coin cell battery
Libraries: Wire.h, RTClib.h, Adafruit_SH1106.h
I made real time clock successfully but problem is that rtc module (ds1307) is not keeping track of time. Whenever I shutdown Arduino it starts from beginning from where time was configured during compilation/uploading. I checked voltage of coin cell battery & it was perfect.
Another thing I noticed is that there is difference of 8-10 seconds between actual time & time displayed by rtc.
comment the line
rtc.adjust(DateTime(F(DATE),F(TIME)));
in your setup and check again. i beleive that this line took date and time of system on compilation time and made it part of code. it was supposed to be used only for first time.
@Waheed_Shah & @Delta_G from your P.O.V, I need to 1st upload a code that sets the time on RTC which will contain line "rtc.adjuct......" & after that I need to upload code of my project. Did I understand in right way?
@ruilviana I am not powering Arduino Uno R3 with 3V. I am using my laptop to turn on Arduino. what do you mean by schematic of my project? I don't know much. I am a beginner.
you'll find difference between RTC Module shown in image & shared URL but situation is that I wanted to give you animated schema & it was the only RTC that was available on that website but you can consider the connections in actual way.
How can you set the real time? There are no buttons and routines to do that. There isn't NTP connection. There isn't GPS connection. The DS1307 can't know what the actual time is. The only thing he know is the compile time. Between compile time and real time there is a difference of x seconds, minutes or days.
The screen gives a time? Than all that you have programmed is doing what it must doing.
@yash_7200 I am almost certain that this explains the problem you are having.
The DS1307 is like the clock on your microwave oven. In order for it to show the correct time, first you need to set the correct time.
What this line of code does, is
rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
it sets the time on the RTC to the time that the code was compiled. Every time this line of code runs, it will set your RTC to the same time, the time the code was compiled.
I uploaded code of my project (after commenting time adjusting line)
Now, rtc is able to keep a track of time but now there is again issue of accuracy.
Now I noticed that accuracy is decreased. There is a difference of 20-21 seconds between actual time & time being display on OLED.
Please read what I wrote in Post #18, above.
If you put in the date and time yourself, you can set it to whatever time you want. If your clock is 20 seconds behind, then set it to a time that is 20 seconds ahead, and see if that helps.
It will give you the time started at Christmas 2025.
You must make something with buttons to set the correct hour and date. At least 2 buttons, 1 for set/select and 1 to increase. Then push set to select the setting procedure, push the increase button to set the correct hour, push set (save the hour and select minutes) , push increase until the minutes are correct, push set (save the minutes and select seconds), .....
Other way is using an extern time. GPS, NTP, DCF (radiaclock) or similarly.
Or setting the time with serial connection from PC (IDE serial monitor, Putty, ...)