Step 6: Arduino Clock Module

We finished the Arduino Time & Date functions using the Sparkfun DS1307 I2C RTC module, a 2 line LCD, and the Arduino Duemilanove. There are four connections from the DS1307 to the Arduino:

//pin SDA to Arduino Analog pin 4
//pin SCL to Arduino Analog pin 5
//pin GND to Arduino GND
//pin VCC to Arduino 5v

To set the time, edit the following section in the code with the correct time and date,

// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
second = 0;
minute = 42;
hour = 9;
dayOfWeek = 1; //Sunday
dayOfMonth = 3;
month = 10; //October
year = 10;

and temporarily remove the // from the following line:

//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);

Upload your code to the Arduino, then put the // back in the above line, and upload again.

The complete code and wiring are posted at http://arduinotronics.blogspot.com/2010/10/ds1307-real-time-clock-working.html

<p>Good instructable, but, his is an old clock check out the newer more accurate DS3231 clock Easier to implement with the new 1604 4 line LCD module with the I2C backpack module it only requires 2 serial data wires as opposed to 7</p>
gr8 keep it up
I was thinking about doing something like this, but with wind speed and rainfall as well. Thanks for the instructable! It'll probably help a lot when I finally get around to building mine.
I'll eventually get those functions in there, probably by sniffing the wireless feed from a lacrosse weather station. easier than making a anemometer and rain gauge.
I thought about making a anemometer and rain gauge, and I've even planned them out, but I don't want to take the time to actually make them. So instead, I just bought them from sparkfun: http://www.sparkfun.com/commerce/product_info.php?products_id=8942<br><br>I'll post an instructable once they arrive at my house and I've programed my arduino!
<p>I know this was quite a while ago. But did you get that SparkFun weather kit? If so, what do you think of it?</p>
<p>We did. It's up and flying. I didn't think it would hold up, as it appears fragile, but after a year or so, it's still going strong. Need to publish the code for that.</p>
<p>Cool, nice to know. The &quot;arms&quot; that hold the anemometer and vane look kind of delicate to me. </p>
<p style="margin-left: 20.0px;">Couple of quick questions, is it impossible to use the Arduino to keep time.... (I was thinking of using pulseIn function at the start/end of the loop to keep time...) <br><br>So if the RTC is essential can you just plug it into 5 consecutive Arduino pins instead of dealing with so much wiring?</p>
<p>There exists an Arduino Time library <a href="http://playground.arduino.cc/Code/Time" rel="nofollow">http://playground.arduino.cc/Code/Time<br></a>But this will not work if running on external power and not connected to the computer of course.</p><p>When I just started with Arduino, I attempted to write a clock code <a href="https://docs.google.com/document/d/1nSeXLC3vC2sNe9FH0mwJZSAChyE0TAnjdgfyfuhzQFs/edit" rel="nofollow">https://docs.google.com/document/d/1nSeXLC3vC2sNe9...</a><br>There was a decent amount of drift over a few hours, but it was still pretty cool. Again, I did this when I just started with Arduino/programming so it's definitely not the best thing around. You could probably find some better stuff if you just Googled, &quot;Arduino clock&quot; or something like that.This is something I found <a href="http://www.instructables.com/id/Make-an-accurate-Arduino-clock-using-only-one-wire/" rel="nofollow">http://www.instructables.com/id/Make-an-accurate-A...</a> Haven't looked at it much though.</p><p>Secondly, in my code, I kept time using the millis() function. You would probably have better luck using interrupts.</p><p>Good luck</p>
If you look at my other instructables, and projects at <a href="http://arduinotronics.blogspot.com" rel="nofollow">http://arduinotronics.blogspot.com</a> you will find network based time clients, gps based, and pc set ds1307 (no need to stay connected) projects.
<p>Thanks pal!</p><p>I will definitely look at those links!!, Personally I am all about doing more with less, and this is up my alley! </p>
<p>Cool. I'm interested to see how your project turns out. Good luck.</p>
the rtc uses two datalines (a4 and a5) in addition to power and ground. you can't just plug the rtc into the arduino, as the pin connections will not line up.
<p>Hmm... I think you can, instead of GND you just digiWrite(pin LOW) and instead of 5V you digiWrite(Pin HIGH)... I know its not best practice but it does seem to work seamlessly<br><br>Have a look at an example with an Ultrasonic sensor: </p><p>https://www.youtube.com/watch?v=pdIUNHps-5s</p>
<p>sda and scl are reversed on this module, so you can't. you'll need to find another module. do you really want to waste your analnog ports defining them as power and ground?</p>
<p>Good point, I guess that depends on what the circuit needs, I really like what you built... especially that its self powered. I just bought some 1W panels + lipo batteries to see if I can build similar circuits. </p>
Hi! We launched a new project of weather map layer for OpenStreetMap <a href="http://openweathermap.org" rel="nofollow">http://openweathermap.org/</a>. It public project that collects data from more than 20,000 meteorological and weather stations around the world. The more weather stations connect the more precise weather data we provide to people. All collected weather data are provided under CC-BY-SA 2.0.You can connect your weather station to the service <a href="http://openweathermap.org/connect" rel="nofollow">http://openweathermap.org/connect</a>
I'm wondering if you ever added the relays and the outdoor temp and humidity.
I added the SSR's, directly addresses by an output pin. This allows control of ac devices, up to 660v and 150 amps, depending on the SSR, with an optically isolated 5v input.<br><br>I also added the outdoor temp and humidity.
Does/Can this setup also log data for an extended period of time (say three months)? I'd love to be able to drop this in an off-grid spot and have it continuously working for me; just check on it every few weeks and dump data to a laptop. Or even better, find a way to dump the data to a server so I can visit it and dl it from anywhere. Would this work?
You can use Gobetwino (http://www.mikmo.dk/gobetwino.html) to log the serial output to a file on a computer connected to the Arduino. If you have a machine that is always on, this is a pretty good way to go, as it doesn't require any additional hardware.<br><br>If not, one of the listed options is pretty nice, especially the storage shields.
Yes, there is a sd card data logging shield that would do this. There's even a wifi shield and ethernet shield for real time communications.<br> <br> <a href="http://www.seeedstudio.com/depot/sd-card-shield-for-arduino-v21-p-492.html">http://www.seeedstudio.com/depot/sd-card-shield-for-arduino-v21-p-492.html<br> <br> http://www.asynclabs.com/store?page=shop.product_details&amp;flypage=flypage.tpl&amp;product_id=26&amp;category_id=6<br> <br> http://www.ladyada.net/make/eshield/</a><br>
This is very cool. When you are ready to integrate forecasted weather for your location to make your HVAC controls predictive, let me know, as we can provide and even integrate your sensor data if we can get at the output.
What OS are you using? I am using Xubuntu 11.04
Ubuntu 11.04 and Windows Vista.
I said to myself 6 months ago how i should do this project, good job getting to it first!
Wait till I get the relays installed and it turns on my a/c and furnace when necessary :-) Should have barometric pressure and time / date functions (for setback thermostat capability) working next weekend. Running out of IO lines, will need a expander. <a href="http://www.embedds.com/arduino-i2c-expansion-io/">http://www.embedds.com/arduino-i2c-expansion-io/</a>
Yea, I have a heat pump, and one of the efficiency tweaks is to not turn on the auxiliary heating when the outside weather is above 0 degF<br><br>I might reuse some of this to add that feature to my &quot;dumb&quot; digital thermostat, which will do a call for &quot;aux heat&quot; if it kicks on and the room temp is 2 degF below the set point.
nice job! how much did it cost you about?
About $70 or so.
That is awesom. Now if i can figure out how to make it send signals back over morse code or something without RF i'll be set.
We both remember the modulated lightbeam kits of the late 70's.
I think one of your wires on your lcd is loose in that first picture. Mine does the funny wierd symbols if a wire temporarily becomes disconnected.
naw, it was a errant carriage return (println instead of print), carried over from the serial output of the original code snippet.

About This Instructable




Bio: Professionally, I'm an IT Engineer (Executive Level) and Electronics Tech. I'm a Amateur Radio Operator (KK4HFJ). I lived off grid, with Solar (PV ... More »
More by sspence:DIY I2C LCD Display with Inputs Raspberry Pi & the Neo 6M GPS Earthquake / Vibration Sensor 
Add instructable to: