Introduction: Arduino DS3231 RTC Clock With LCD

Picture of Arduino DS3231 RTC Clock With LCD

To familiarize myself with a DS3231 RTC (real time clock), I built a simple arduino based 24 hour clock. It has 3 buttons with the following functions: press any button to enter the time setting mode, increase and decrease the time in minutes with two of the buttons, and set the clock with the third button. You can checkout a video of it working at vimeo.com/andrewideas/simplearduinoclock.

Materials Required:

  • An arduino development board (I used an Uno)
  • A standard 16x2 HD44780 based LCD display
  • A DS3231 based RTC (I got mine on Amazon)
  • Three push buttons
  • Three resistors (~10K ohm)
  • A potentiometer (~10K ohm)
  • A breadboard
  • Several jumper wires

Step 1: Wiring

Picture of Wiring

Refer to the drawing for wiring instructions. The buttons are connected to pins A0, A1, and A2. The RTC uses pin A5 for SCL and pin A4 for SDA. The potentiometer varies the contrast on the LCD and the LCD uses digital pins 2 through 7.

Step 2: Programming

Picture of Programming

Use the arduino IDE to upload my sketch to your arduino.

My code was partly based on the code provided here. And, of course, my code is explained in its comments.

You can download the sketch from this instructable.

Step 3: Continuing on With Your Life

You did it! Unless you didn't- in which case comment below and I'll do my best to help you out. Otherwise, go on ahead and do even greater things!

As a student, I do not always have the finance to fund projects. I love making and sharing things with the world, but sometimes supplies are expensive. There is by no means any pressure, but if you like my work and want to help show appreciation and offset the cost of some of my projects, I have an Amazon Wishlist where you can donate items or gift-cards. You also check out my complete list of ways to help at arwhitus.weebly.com/help.html.

Thanks!

Comments

MarloG1 (author)2017-04-19

good day, can i use this as a stopwatch with lap times?

AndrewIdeas (author)MarloG12017-04-20

Hey, this project was designed to be a clock rather than a stopwatch. However, you could use a similar hardware design and make use of the RTC to keep good time and print the output to the LCD.

Thanks!

MarloG1 (author)AndrewIdeas2017-04-20

thank you for your reply,
however i'm new to this and trying to learn arduno, can guide me,
thank you

AndrewIdeas (author)MarloG12017-04-21

This doesn't include a rtc, but an rtc is not as important in a stopwatch application anyway.

http://fritzing.org/projects/arduino-lcd-stopwatc...

It is a simple stopwatch, and if you want to incorporate an rtc simply connect it to I2C like I did and use the setRTCTime() and readRTCTime() methods to access the time from the rtc. From there, you should be able to use arithmetic to calculate the passing of time.

Best of luck!

MarloG1 (author)AndrewIdeas2017-04-22

thank you so much for your help

MarloG1 (author)AndrewIdeas2017-04-22

thank you very much for your help

bicchef (author)2017-03-02

having trouble and not sure how the time should look in the code i just get a back lit screen doesn't respond to the potentiometer anyone that can help me.

thanks

AndrewIdeas (author)bicchef2017-03-27

The format for the parameters of setRTCTime() is (sec, min, hr, day of week, day of month, month, year)

For example: setRTCTime(0, 3, 23, 4, 15, 7, 17);

Hope this helps!

KarlC1 made it! (author)2016-10-05

Great instructable! Worked first time out of the box. I am going to use this program to program my RTC's. Question do you have code for intergrating Daylight Savings Time?

AndrewIdeas (author)KarlC12016-12-04

Thanks! I have not written code to handle daylight savings time. You could write this code yourself based around existing lists of data, though it would most likely be easier just to manually adjust the time as needed.

TimM174 (author)AndrewIdeas2017-01-08

I have written in a bit to handle DST for my timezone which is Pacific eg. -7 PDT or -8 UCT offset right now PST

At the top with other declared vars I put this: int DST = 0; // Used for setting Daylight Savings Time for RTC

Then with the readRTCTime and setRTCTime functions I put this in the loop function:

<code>

readRTCTime(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

if (dayOfWeek == 7 && month == 3 && dayOfMonth >= 7 && dayOfMonth <= 14 && hour == 2 && DST == 0) {

// DS3231 seconds, minutes, hours, day, date, month, year

setRTCTime(second, minute, 3, dayOfWeek, dayOfMonth, month, year);

DST = 1;

} else if (dayOfWeek == 7 && month == 11 && dayOfMonth >= 1 && dayOfMonth <= 7 && hour == 2 && DST == 1) {

// DS3231 seconds, minutes, hours, day, date, month, year

setRTCTime(second, minute, 1, dayOfWeek, dayOfMonth, month, year);

DST = 0;

}

</code>

Reason for in the loop is it can check and set right when there is a noticed match in criteria.

AndrewIdeas (author)TimM1742017-01-15

Nice. You'll need to change your code every year as day light savings times starts and ends on a different date every year, though. Also I would change your 'int DST' to a boolean since you are using it as 1 or 0, and a boolean will use less memory than an int.

zipp_1001 (author)AndrewIdeas2017-01-28

hi, I'm afraid you don't understand TimM174 code - this _auto_ DTS changing

:-)


AndrewIdeas (author)zipp_10012017-01-29

My mistake. Thanks for pointing that out! (:

TimM174 (author)AndrewIdeas2017-01-28

Good point with boolean type. I didn't have much concern for my use simply cause my code didn't take up much room anyway.

When I wrote this DST change, my idea was to have it change based on the known factors such as first/second Sunday and check what month it is. The other thing I did is put it in my loop and use a millis timer to run it once a second to keep it as up-to-date as can be... and cause I have other things that run a check that often too.

AndrewIdeas (author)TimM1742017-01-29

Gotcha- my mistake. Great work and thanks for sharing this!

TimM174 made it! (author)2017-01-08

It works great as a start for what I was already trying to do. I later added a way to sync with the compile time so it is a bit more automated. I plan to write a simple library to do this and it may include timezones and DST auto-change given timezone and/or location. The posted images are of the one I copied for this project and a current working model of much more than just this project but is great to show anyway.

MahmoudE36 (author)2015-11-12

your instructable is very awsome

i am a very very new in arduino big world ,,,

and i need help in my second or third arduino project.
...
i need to build a code that repeat it self every 24 hour "every day"
without RTC module

Example like:
at 9 clock "pin 3 High"
at 11 clock "pin 4 High"
at 18 clock "pin 5 High"
at 20 clock "pin 6 High"
at 22 clock "pin 7 High"

and repeat that commands every 24 hour ""every day"
can you help me with that

AndrewIdeas (author)MahmoudE362015-11-12

Thanks for the kind words!

Without an RTC you will run the risk of loosing time accuracy over time, but you can accomplish something what you are asking about by using the delay function. I quickly wrote up a sketch to do what I think you are describing and put it on my site at: http://andrewideas.weebly.com/arduino-delay-pract...

Hopefully you can use this code to work on your project, but bear in mind I have not tested it. None the less, it should be a good starting point for you. Thanks!

MahmoudE36 (author)AndrewIdeas2015-11-13

Many many thanks for you AndrewIdeas , and I am very happy for your concern

i will test it and feed you by results

seamster (author)2015-07-16

Nicely done. Thanks for sharing this!

About This Instructable

23,128views

52favorites

License:

Bio: I am a college student who loves to make things and share them. If you would like to support my projects, check out the &quot;help ... More »
Add instructable to: