# How to use a RTC With an Arduino UNO R3 to Create an Accurate Clock

**URL:** <https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331>\
**Category:** Guides\
**Created:** [10 September 2021 05:35 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331 "2021-09-10T05:35:00Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![Jeff105671](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/jeff105671/32/3729_2.png) [@Jeff105671](https://forum.core-electronics.com.au/u/Jeff105671)\
**Post date:** [11 October 2023 04:11 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/21 "2023-10-11T04:11:23Z")

</div>

Are you referring to the picture in the tutorial? All the jumpers there are M,M. The Arduino power leads are actually a mixture, but the end result is M,M. The RTC and LCD have F,F adapters because they use a different style connector: if they are not included with the product then you will need to order them separately.

---

<div class="post-metadata">

**Author:** ![stella258490](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@stella258490](https://forum.core-electronics.com.au/u/stella258490)\
**Post date:** [23 October 2023 01:45 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/22 "2023-10-23T01:45:54Z")

</div>

With the precision clock, when you press the buttons (red,yellow or blue) will the time show up? and when your finger is not on the button will it not show? Can you explain the use of the buttons please

---

<div class="post-metadata">

**Author:** ![James46717](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@James46717](https://forum.core-electronics.com.au/u/James46717)\
**Post date:** [23 October 2023 02:15 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/23 "2023-10-23T02:15:10Z")

</div>

My best guess from looking at the code.  
Date Time is displayed all the time.  
Pressing P1 steps through changing date / time.  
Hour then Minute then Year then Month then Day.  
P2 & P3 step the value up or down.

The code does not have a blank display feature.  
Cheers  
Jim

---

<div class="post-metadata">

**Author:** ![Jeff105671](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/jeff105671/32/3729_2.png) [@Jeff105671](https://forum.core-electronics.com.au/u/Jeff105671)\
**Post date:** [23 October 2023 02:17 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/24 "2023-10-23T02:17:42Z")

</div>

The time is displayed whenever the device is powered up.

```auto
void loop()
{ 
// in which subroutine should we go?
  if (menu==0)
    {
     DisplayDateTime(); // void DisplayDateTime
    }

```

Button 1 is pressed and held to adjust the hour, minute, year, month and day in turn and released to finish the setting, Buttons 2 and 3 adjust the selected item up or down.

```auto
int P1=6; // Button SET MENU'
int P2=7; // Button +
int P3=8; // Button -

```

---

<div class="post-metadata">

**Author:** ![stella258490](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@stella258490](https://forum.core-electronics.com.au/u/stella258490)\
**Post date:** [23 October 2023 06:51 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/25 "2023-10-23T06:51:01Z")

</div>

When I put in the first code, it says that theres an error compiling for Arduino Uno

---

<div class="post-metadata">

**Author:** ![Jeff105671](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/jeff105671/32/3729_2.png) [@Jeff105671](https://forum.core-electronics.com.au/u/Jeff105671)\
**Post date:** [23 October 2023 07:26 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/26 "2023-10-23T07:26:04Z")

</div>

If that is the only message that appears at the end it indicates that you have selected the wrong processor in the Tools / Board menu item. Make sure it is set to UNO.

If that’s not the problem look back through the display output and find the detailed message and post it in full.

---

<div class="post-metadata">

**Author:** ![stella258490](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@stella258490](https://forum.core-electronics.com.au/u/stella258490)\
**Post date:** [23 October 2023 07:47 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/27 "2023-10-23T07:47:53Z")

</div>

I used the 2nd sketch that you provided and It still doesn’t work. Also, the white connector you put in both the screen and the gravity, you only gave me one. I don’t know how I’m supposed to also connect the gravity if I don’t have the white connector. Tell me if It is supposed to have 2 casue I only got one with the package.

 ![image.png](https://canada1.discourse-cdn.com/flex028/uploads/core_electronics/original/2X/b/bc20f480317689f4614305a7809d622864fe1caa.png)

---

<div class="post-metadata">

**Author:** ![stella258490](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@stella258490](https://forum.core-electronics.com.au/u/stella258490)\
**Post date:** [23 October 2023 08:10 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/28 "2023-10-23T08:10:03Z")

</div>

I used the 2nd sketch that you provided and It still doesn’t work. Also, the white connector you put in both the screen and the gravity, you only gave me one. I don’t know how I’m supposed to also connect the gravity if I don’t have the white connector. Tell me if It is supposed to have 2 casue I only got one with the package.

---

<div class="post-metadata">

**Author:** ![Jeff105671](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/jeff105671/32/3729_2.png) [@Jeff105671](https://forum.core-electronics.com.au/u/Jeff105671)\
**Post date:** [23 October 2023 08:15 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/29 "2023-10-23T08:15:13Z")

</div>

Have you fixed the problem with the " Error compiling for Arduino Uno" message?

Firstly, you need to remove the duplicate lines - there should be only one ‘#include’ statement for each library.

The error message shown in your image means that the LCD library has not been installed properly. The instructions for doing this are in the tutorial at the paragraph that starts “Next type in Liquid Crystal\_I2C into the Library Manager search bar.” That first description might not work because I think the IDE does not list archived repositories… The second description (“Finally, you will need to include a library through a zip file”) will work, but you need to go to  
[GitHub - fdebrabander/Arduino-LiquidCrystal-I2C-library: Library for the LiquidCrystal LCD display connected to an Arduino board](https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library)  
select Code, download the ZIP and follow that description for installing a library from ZIP.

If the product you ordered was supposed to come with the cable included then that is a matter you should take up with Core using the email provided with your invoice.

---

<div class="post-metadata">

**Author:** ![James46717](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@James46717](https://forum.core-electronics.com.au/u/James46717)\
**Post date:** [23 October 2023 11:07 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/30 "2023-10-23T11:07:25Z")

</div>

> [@stella258490](#):
>
> I used the 2nd sketch that you provided and It still doesn’t work.

The sketch in the guide definitely does not work, the libraries area needs to be like the graphic below the sketch.  
Use the link to the .zip library at the bottom of the guide.  
Attachment - Code\_and\_Zip\_Library\_Needed.zip.  
The correct sketch is there and the DFRobot\_LCD library. (DFRobot\_LCD-master)

Arduino has an area detailing how to install libraries.

> **[Installing Libraries | Arduino Documentation](https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries#.UxU8mdzF9H0)**
>
> Learn how to install additional libraries in the Arduino IDE 1.

Use the Library Manager instructions to install the RTClib and LiquidCrystal\_I2C libraries.  
Use the Manual install instructions to copy DFRobot\_LCD-master to the libraries area of your Arduino IDE. Use of the .zip files worked for me as I was able to compile the sketch correctly.

 ![Image2](https://canada1.discourse-cdn.com/flex028/uploads/core_electronics/original/2X/d/ddcf61fbc44836232290bd46a63a2664958d3c1c.jpeg)

Regards  
Jim

---

<div class="post-metadata">

**Author:** ![Liam](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/liam/32/3562_2.png) [@Liam](https://forum.core-electronics.com.au/u/Liam)\
**Post date:** [24 October 2023 00:10 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/31 "2023-10-24T00:10:36Z")

</div>

Hi Stella,

Jeff and Jim have you sorted out for the code.

Could you please send through a photo of your wiring just to confirm you have all of the cables?  
There should have been a cable included with the RTC and screen (white on one end and black on the other) - like Jeff said, just send through an email and we’ll sort it out!

Liam

---

<div class="post-metadata">

**Author:** ![stella258490](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@stella258490](https://forum.core-electronics.com.au/u/stella258490)\
**Post date:** [24 October 2023 05:46 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/32 "2023-10-24T05:46:54Z")

</div>

Okay I’ll send it in a few I’m around 30mins till home

---

<div class="post-metadata">

**Author:** ![Rooppoor212784](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Rooppoor212784](https://forum.core-electronics.com.au/u/Rooppoor212784)\
**Post date:** [24 October 2023 19:34 UTC](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331/33 "2023-10-24T19:34:56Z")

</div>

For those who are looking for better accuracy, I suggest DS3231. This is also available in core electronics.

> **[Adafruit DS3231 Precision RTC Breakout](https://core-electronics.com.au/adafruit-ds3231-precision-rtc-breakout.html)**
>
> The datasheet for the DS3231 explains that this part is an "Extremely Accurate I²C-Integrated RTC/TCXO/Crystal". And, hey, it does exactly what it says on the tin!...

One can make simple but more accurate arduino clock like this with DS3231.

> **[Diy RTC Module - Share Project - PCBWay](https://www.pcbway.com/project/shareproject/Diy_RTC_Module_aef8ce7d.html)**
>
> DS3231 RTC chipAt the heart of the module is a low-cost, extremely accurate RTC chip from Maxim – DS3231. It manages all timekeeping functions and features a simple two-wire I2C interface which can be...

[Previous page](https://forum.core-electronics.com.au/t/how-to-use-a-rtc-with-an-arduino-uno-r3-to-create-an-accurate-clock/11331.md?page=1)
