loading

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

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

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!

<p>good day, can i use this as a stopwatch with lap times?</p>
<p>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.</p><p>Thanks!</p>
thank you for your reply,<br>however i'm new to this and trying to learn arduno, can guide me,<br>thank you<br><br>
<p>This doesn't include a rtc, but an rtc is not as important in a stopwatch application anyway.</p><p><a href="http://fritzing.org/projects/arduino-lcd-stopwatch" rel="nofollow">http://fritzing.org/projects/arduino-lcd-stopwatc...</a></p><p>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.</p><p>Best of luck!</p>
<p>thank you so much for your help</p>
<p>thank you very much for your help</p>
<p>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.</p><p>thanks</p>
<p>The format for the parameters of setRTCTime() is (sec, min, hr, day of week, day of month, month, year)</p><p>For example: setRTCTime(0, 3, 23, 4, 15, 7, 17);</p><p>Hope this helps!</p>
<p>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?</p>
<p>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.</p>
<p>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</p><p>At the top with other declared vars I put this: int DST = 0; // Used for setting Daylight Savings Time for RTC</p><p>Then with the readRTCTime and setRTCTime functions I put this in the loop function:</p><p>&lt;code&gt;</p><p>readRTCTime(&amp;second, &amp;minute, &amp;hour, &amp;dayOfWeek, &amp;dayOfMonth, &amp;month, &amp;year);</p><p> if (dayOfWeek == 7 &amp;&amp; month == 3 &amp;&amp; dayOfMonth &gt;= 7 &amp;&amp; dayOfMonth &lt;= 14 &amp;&amp; hour == 2 &amp;&amp; DST == 0) {</p><p> // DS3231 seconds, minutes, hours, day, date, month, year</p><p> setRTCTime(second, minute, 3, dayOfWeek, dayOfMonth, month, year);</p><p> DST = 1;</p><p> } else if (dayOfWeek == 7 &amp;&amp; month == 11 &amp;&amp; dayOfMonth &gt;= 1 &amp;&amp; dayOfMonth &lt;= 7 &amp;&amp; hour == 2 &amp;&amp; DST == 1) {</p><p> // DS3231 seconds, minutes, hours, day, date, month, year</p><p> setRTCTime(second, minute, 1, dayOfWeek, dayOfMonth, month, year);</p><p> DST = 0;</p><p> }</p><p>&lt;/code&gt;</p><p>Reason for in the loop is it can check and set right when there is a noticed match in criteria.</p>
<p>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.</p>
<p>hi, I'm afraid you don't understand TimM174 code - this _auto_ DTS changing</p><p>:-)</p><p><a href="https://www.instructables.com/member/TimM174" rel="nofollow"><br></a></p>
<p>My mistake. Thanks for pointing that out! (:</p>
<p>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.</p><p>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.</p>
<p>Gotcha- my mistake. Great work and thanks for sharing this!</p>
<p>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.</p>
<p>your instructable is very awsome </p><p>i am a very very new in arduino big world ,,,</p><p>and i need help in my second or third arduino project.<br>...<br>i need to build a code that repeat it self every 24 hour &quot;every day&quot;<br>without RTC module</p><p>Example like:<br>at 9 clock &quot;pin 3 High&quot;<br>at 11 clock &quot;pin 4 High&quot; <br>at 18 clock &quot;pin 5 High&quot; <br>at 20 clock &quot;pin 6 High&quot; <br>at 22 clock &quot;pin 7 High&quot; <br><br>and repeat that commands every 24 hour &quot;&quot;every day&quot;<br>can you help me with that</p>
<p>Thanks for the kind words!</p><p>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: <a href="http://andrewideas.weebly.com/arduino-delay-practice.html" rel="nofollow"> http://andrewideas.weebly.com/arduino-delay-pract...</a></p><p>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!</p>
<p>Many many thanks for you <a href="https://www.instructables.com/member/AndrewIdeas" rel="nofollow">AndrewIdeas</a> , and I am very happy for your concern</p><p>i will test it and feed you by results</p>
<p>Nicely done. Thanks for sharing this!</p>

About This Instructable

18,350views

51favorites

License:

More by AndrewIdeas:Easy $30 Console Table With 2x4s and 1x4s Wooden Canoe Paddle Restoration Wooden Repurposed Laptop Display Frame 
Add instructable to: