First a simple example using only an Arduino Uno R3 and a DFRobot DS1307 RTC Module - then incorporating an LCD display & three buttons to make a functional, accurate, digital clock.

Transcript

Hey gang, Tim here at Core Electronics, and today we're getting hands-on with an RTC and an Arduino. We're going to be finishing up by making ourselves a functional clock. The RTC, which stands for real-time clock, used here is the DF-Robot RTC. It enables accurate timekeeping even when unpowered, thanks to a little slot for a button battery underneath.

As a side note, it is true that you can create a clock with an Arduino Uno without an RTC, but it's not going to keep accurate time. It may lose around 30 seconds of time each day. Most modern electronics, like everyone's mobile phone, have an RTC to keep track of time even when their main battery is drained.

So let's get right in and connect the DF-Robot Gravity RTC to the Arduino Uno R3. I've been connecting everything using JST white connectors and adding male-to-male jumper cables to the end of those connections. It's always a good idea to use consistent colors for wires. Red is live, and black is ground, which is the standard attitude.

Now, let's connect the other ends of these jumper wires to the Arduino. The black wire needs to go to the ground pin on the Arduino Uno, and the power wire needs to go to the 5V pin on the Arduino Uno. The SCL pin needs to connect to the C on the RTC, and the SDA pin needs to connect to the D on the RTC. These are the wires required for I2C communication.

I will also throw up a wiring schematic on the screen so you can see exactly what to do. Now would be a good time to put the button battery into the back of the RTC. For this module, a CR1220 battery is required.

With everything attached, let's now plug in the A to B peripheral cable.Into the Arduino Uno R3 and then put the other side into a USB port on your computer. This connection means we can now code to the Arduino Uno R3 using the Arduino IDE and also supply power to the system.

Open up the software, click on the sketch drop down menu and then click on the manage library setting. This button will open up a library manager window. In this window we're going to type into the search bar the following RTC LIB. Then click install making sure to select the newest version. Depending on your real-time clock used in the project you may need to use a different library or alter the code so that it will function for you. So long as you're running a real-time clock that has a DS1307 chip like the one inside this DFR robot RTC the code is going to work fine.

Having done the library requirements we can now start coding. The code used here is available on the article link down below. Copy and paste the article code into the Arduino IDE coding section deleting anything that was written in there beforehand and then save, verify and upload the code to your Arduino Uno R3.

Having done this you can then open up the serial monitor using the tool drop down menu like so. This will open up another window which will be receiving date and time information directly from the RTC. Nicely done it's now working. A sweet bit of code basically the hello world for RTC devices.

A quick troubleshoot if the message being written on the serial monitor comes back looking like gobbly gook then alter the board rate in the serial monitor here.

Take a quick look at the code you can see that we are including two libraries one being the library we just added andAnother called wire.

Next, you can see the exact chip that is on the DF robot being referenced, which is that RTC DS1307.

We can also see an array being set up to represent the seven days, with 12 being the maximum amount of characters in the word.

After this, there are some if statements. So, if the RTC is not correctly connected, it's going to display an error setting. And if it is correctly connected, it's going to print a whole bunch of information to the serial monitor.

At the very end, it delays for three seconds, so it's going to keep doing this every three seconds.

So now we have a fully functioning RTC with our Arduino Uno. What would be something rad to make? Why not a fully functional adjustable clock?

Today, we're going to do some tinkering with the breadboard and making these three components work together: this RTC, the liquid crystal display, and the Arduino Uno.

Let us start by seeing where the power is flowing. The power starts from the USB cable and is fed into the Arduino.

This Arduino then sends out five volts of power to the Arduino Uno, and then the Arduino Uno sends out five volts of power to the breadboard.

So the power starts from the USB cable and is fed into the Arduino.

This Arduino then sends out five volts down a red wire to the breadboard onto the power rail. I always use red wire for power lines.

The way breadboards work means that the whole length along this line is now going to be five volts.

So if we follow this line along, we can see that the power is going to go to the buttons. The power is also going to go to the RTC, and the power is also going to go to our LCD screen.

So that's perfect. Now let's check that all of...These are having the power returned to a shared ground. We're going to start from the Arduino and see that this black wire is coming out of the ground pin and it's going to this rail because it's all the way along is going to be a shared ground. So we can see that the RTC is connected to the ground and the LCD is connected to the ground. Also we can see that these resistors are connected to the ground which will complete a circuit when the buttons are pressed.

Now let's check the wires which let the electronics mingle and do their communicating. The SCL is the clock line which syncs all the data transfers correctly so there's no confusion. For this setup I've used green wires for the SCL and blue wires for the SDA. You can see here that these wires all come together in the middle of this breadboard and the same colors are in the same column. Three wires for the SCL, one from the Arduino, one from the RTC and one from the LCD display and the same for the SDA. When you're in the middle of the breadboard all the columns will be connected electronically together. So by connecting all the blue wires like this in a column it is the same effectively as soldering the wires together. The same thing's happening over here with these buttons.

Now finally we need our buttons to affect the Arduino so it can tell the LCD display to act correctly. For that I have these three colored wires coming off the buttons like so. These wires are connected to pin six, seven and eight. So that's all the breadboarding completed for this project.

So let's turn on our computer and flash our Arduino with the code I have already written for it. Code can be found in the article.Linked down below, it is worth noting for the clock code we will need to have two extra libraries on top of the extra library we already added. Liquid crystal I2C and the DF robot LCD dot H. To obtain the functionality of the DF robot LCD control library, you will need to download the file, see the article, and add it using the add dot zip library button in the Arduino IDE.

Once you've saved and verified the code, flash it away to your Arduino and with that, you should have a fully functioning clock. So with that, the clock is complete. Let me show off some of the features.

You can see here that it displays the date and the time. If we click on here, we can change the hour and the date to exactly what we want by going through a series of menus. Saving in progress. It's still working, it's all happy. If I take the electricity away from the Arduino, everything turns off. Then, if I put the power back in, you can see it has remembered the time and it's remembered the day.

So, with the knowledge on how to combine an RTC with an Arduino Uno and also how to create a functional clock using one, that's all for today. Until next time, stay cozy.

Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.