Arduino - DS1307 RTC
HTML-код
- Опубликовано: 29 мар 2014
- In this video we will be looking at how to control a Real Time Clock. RTC using the Arduino Leonardo.
Library Downoad
github.com/adafruit/RTClib
Checkout the Forum!!
themagicsmoke.proboards.com/
Follow me on Instructables
www.instructables.com/misperry
Follow me on Twitter
/ misperryee
T-Shirts
www.zazzle.com/misperry Наука
Such an amazing video. Been through many others but none are as useful as yours. Got my time module working.
Sir this video tutorial of yours has helped me a lot in my project. I really want to thank you. Cheers!!
+Linus Miranda Hey there thank you very much for the wonderful comment. I am very glad that it was able to help you. It is viewers like you that keeps me inspired to keep making more videos. Thanks again for your comment.
i am new in programming an arduino and i have a question i need a time 17:59:59 (read it) and will set an output 13 HIGH for 10sec how did i make that. endtime 18:00:09 set output pin 13 LOW
Great work misperry. Just wondering whether you can explain how to attach a LCD to this project which can display time and date. Thank you very much
Very helpful tutorial. But I have a little problem. I removed the lines with 50s and just added the lines to switch the led off after a second after its on at 30s. Now after it is off the time in the serial monitor suddenly switches to 2000/0/1 0:1:0 or something like that.
Very nice job.
This is the simplest way i have ever seen that someone uses DS1307.
I have joined this code with some other codes and i have great result.
thanks
Hey there, I am very glad to hear that this was helpful for you. Thanks for the great comment.
Cheers.
Can an rtc send a signal to an Arduino to make a pin go high once an hour? If so any clue on how to go about it ?
can I do this with DS1302 or DS3231
could you help me? there is no display in my lcd.
Thank you. Worked wonders.
I didn't find the explanation of the circuit useful because I have a data logging shield but the code walkthrough was great. Thanks!
Hey there thank you for your comment. I am glad part of it was helpful to you.
Thanks so much for this video!
It is a nice post. I really love it. Can I ask you about utilizing the rest memory of DS1307, (from 07H to 3FH)? When I set a bunch of scheduled time points, I need them be kept safe with the battery. Then what commands to write and read there? Thanks for the video and for your time, too!
Hey there thanks for the comment. I am glad you enjoyed this video. To answer your question about the nvram on the ds1307 if you open up the RTClib.h file you will see the functions for calling the nvram. I have listed them below. This should help you access these.
void readnvram(uint8_t* buf, uint8_t size, uint8_t address);
void writenvram(uint8_t address, uint8_t data);
void writenvram(uint8_t address, uint8_t* buf, uint8_t size);
do u need the delay?
Thanks for amazing video. Can I ask u a question? I use RTC module DS3231, i get the time and everything is like what u showed in the video until i turn off the arduino, after 5 minutes I turn it on. In the serial port the time continues where it left off which means 5 minutes later than real time. Can u tell me where i did wrong? I think with the RTC module it is supposed to keep time without the power thanks to the battery.
Hey there, thanks for the comment. If it is just picking up where it left off I would check your battery connections. Also I would make sure that in your code you are not saving the current time and re initializing the RTC with that time uppon boot. I did that and didn't notice it and my clock would start from the same time regardless what actual time it was and I noticed that I was putting the initial time set in every time it booted. Once you set the time, as long as you have the battery connected, it should never need to be set again, unless you need to change it for other reasons. Hope this helps.
misperry thanks much, that's very helpful. It's working fine now. Just like u said, i did initialize the time again on every boot. I'm making a RTC switch for my dad to water his orchid garden, twice a day. thanks again.
Cool. I am glad you got it working. An orchid garden watering system that sounds great! Have you checked out the automated sprinkler system? I have a vegetable garden and I thought this up one day while watering. ruclips.net/video/S7TrhZua1dw/видео.html
Hey Thank you for this wonderful video tutorial. I made one RTC module and its working fine. I have a doubt regarding that can I connect the RTC's SDA and SCL pin to any pins other that A4 and A5 of Arduino??
Hey there thanks for the comment. Unfortunately no you cannot connect the RTC to any other pins than the A4 & A5. The reason is because no other pins access the I2C hardware inside the Atmel chip that the arduino uses. Thus, you have to use A4 & A5 for I2C communication.
Thank you
I am having issues getting this to run on my serial monitor. I have copied the code exactly the way it was provided but the date and time simply won't display.
I managed to narrow down the problem in this section of the code:
rtc.adjust(DateTime(2015, 5, 21, 18, 0, 0));
DateTime now = rtc.now();
By commenting out this section, I can get the serial monitor to run a simple text message. But with these two lines active, nothing is displayed. Any suggestions?
+Yuann Wang Hmm First check your hardware connections and ensure you are not using too big of a pull up resistor.
hello im new att this. i wonder if its posible to make a line that says that i like the led to start when i press a bottom and be on x time and then turn another light for a xtime
maybe 72h
yes you could. you would just use the now.minute, now.hour, and now.sec function calls I believe and just check for the hour, min, and maybe second that you are wanting to wait for and turn on/off led's accordingly.
Great tutorial, thanks!
Hey there, Thanks for the great comment. I am glad you enjoyed the video.
thanks a lot bro... its working fine....
actually wondeful! :)
Thanks for the video tutorial. I especially like the way you use schematics. I have used pic chips then moved up to basic stamp2 but this arduino sketch format is making me feel old.
💾
Hey there, thanks for the comment. You can use this module with a pic micro or arm processor as well. I was thinking of making other videos using those two platforms as well to show how to make your own DS1307 library.
i want to turn the servo in specific time.it this right. pls help
if (now.second () == 02)
{
myservo.write(100);
}
Serial.println();
delay(3000);
}
Well this will activate the sensor once a minute whenever the seconds equal 2. If you are wanting it to be every 2 seconds you will need to take into consideration multiples of 2.
Also if you are wanting to do every 2 seconds waiting 3 seconds after performing the action will throw you off.
Hope this helps.
Very nice video.
Thank you.
Hey there, thanks for the comment. I am glad that you enjoyed the video.
Hey! Great video!
I have one problem. My serial monitor does not display anything. I have set the serial monitor to 57600 baud, but still doesn't work. Any ideas why?
Hey there, thanks for the comment. make sure that your monitor window at the lower right corner is set to 57600 and that in your code you set the 57600 baud as well using the Serial.begin(57600)
I have done everything right as per your video. I am facing two problems:
1. First of all, the compiler says no function of the form DateTime found, had to change the syntax i.e. i had the define the time before the date, after that was resolved , i still got garbage values in the Serial Monitor.
2. Second of all i copied your code exactly and then uploaded it but then then serial monitor stopped displaying anything!
I also wanted to ask you that, Do we have to change settings in the control panel, i.e. to change the bits per second in the device manager properties from the default 9600 to 57600
Sir what's that some ic kind of thing on the breadboard is it necessary for the circuit
Yes that is the DS1307 RTC clock IC. That is whats keeping the time.
@@misperry thank u sir
.
Can you add external buttons to change time without the use of computer?
You totally could. You would just have to add them to the code so you would be always scanning to see if one is pressed and then upon pressing one you perform the action. Or you could wait for one to be pressed for a period of time then do whatever.
Hi, do I get this right, if I remove rtc.adjust line (just set the time once) then module should count itself (i have one with battery on) and when I remove power and connect it again it should display current date/time?
Instead upon every reset/power disconnect just displaying fixed values which was set with rtc.adjust and not counting.
Hey there, thanks for the comment. Yes you are correct. As long as you have a battery you only need to set the clock with the rtc.adjust command only once. What I usually do is put a button or something on a digital port and code the arduino to where when the button is pressed at power up it goes into the rtc.adjust and resets the clock otherwise skip the rtc.adjust and continue with the current time that has been kept. Hope this helps.
Hey, thank You for the reply. That's really clever idea with the button pressed. But when I remove rtc.adjust command and remove the power or reset the arduino, I am getting strange readings, like Year 2106 :( Does that mean my battery is gone in RTC module perhaps? ATM I can't read its voltage, because battery in my multimeter is gone too :)
RoSi4You Hey there. Yeah checking with a good fresh battery would be a good idea. However, you could, if you have one available, use a power supply and set it for 3V to simulate a coin cell battery and connect that to the BATT input. Also ensure that the polarity you are connecting the battery up to the RTC is correct as well. Trust me I have put many a battery in backwards in my life time lol. Hope this is helpful and good luck.
Hm, battery on module is soldered, so bought one for my multimeter, measured it and I am reading 3.27V on it :/ So probably error is coming from somewhere else.
RoSi4You Hmmm yeah it sounds like it. Check your connections and be sure you have connected the bat to the correct places on the chip and with the right polarity. Also if you are using a bread board be sure that the bread board sockets are not loose. I have chased problems in the past the resulted in the breadboard not making contact with a wire I plugged in because the contact inside the bread board was bent out from a large diode's lead spreading it too far. Check things like this. good luck
does the same library, class and functions work for any rtc???
Only chips architecturally similar to the ds1307. Other RTC's may have different command structures and different ways of accessing them. You will have to look at the data sheet to see how they are accessed.
Can we stop this rtc ds1307
Nice video.....can you please do a video using this RTC with SURE Electronics LED 3216 matrix.. would really appreciate it.
Hey there, Thanks for the comment and the suggestion. This looks like a good idea to me. I am glad that you enjoyed the video and keep watching I may have to check out one of those SURE Electronics 32x16 matrix screens. Thanks again.
wery naise your video am stading ths metheed sooper your video thanks sir
Nice!
Did this project take long to build?
No it only took as long as soldering the components and programming. The code is located on my project code link that is on my channel's home page.
when the power is off, the time still running, right?
As long as you have the coin cell 3V battery in...yes it will keep running.
Hello Sir; First of all thank you such a clear and nice explanation. I am making a project which has multifunctions . Now I am using a bluetooth module which works at bode rate of 9600 and this Ds1307 works at bode rate of 57600.So how can I use both of this different bode rates in same programe. Thank You in advance.
Manish Singh Check out how to configure a software UART. You will use what is called the bit-bang approach to make a virtual UART on the arduino that will have one baud rate and then you will use the hardware UART at a different baud to do the other.
Hope this helps.
there is a way to determinate the day of the week? (I mean Monday, tuesday...) Nice video, thanks for sharing ;)
Yes, if you go to the example code once you download the library, the first example has days of week printing.
Is there any chance for Arduino Uno to work?
Yes that should work fine. The library, I beleive, is universal. Good question.
Thank you alot for this video ,it's really useful ,but i have a problem
it says RTC not running ,
2165/165/165 165:165:85
2165/165/165 165:165:85
and counting like this , i dont know whats wrong with it
He there, thanks for your comment. I would check your hardware connections. Ensure that you are using the proper resistance value on your I2C lines. This will cause some very strange data to come out if you have the wrong resistances. Also ensure that you have the correct baud rate. I have set mine to 57600 in this example. If you need to post your sketch and I can take a look at it. Hope this helps.
This may not apply to your problem. But when I connected the 3231 RTC board I accidentally reversed the SCL/SDA lines. For reference on an Arduino UNO (I'm running an R3) analog pin A5 should connect to SCL and A4 to SDA. Does that fix your problem?
Hi, first of all thanks for this video ...... I've download the library into arduino but i have this error ==>
sketch_mar06a.ino:20:20: error: RTClib.h: no such file or directory
+karar sabih You will have to install the RTClib.h file into your arduino directory since it is a header file. Here is the adafruit link on how to do so.
learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/arduino-library
+misperry I've installed it but i had the same problem.......!!
+karar sabih Make sure you are calling it with quotes like "RTClib.h" and not like this check at 9:00 in vid
Hi Sir, I'm having probems setting exact time using DS1307. I've watched this video and I followed your codes pattern, but I can't come out with what I'm expecting. Could please help me? At the last part of the video you said something like setting exact time, could you please send me some example codes. Thankyou so much! =)
This will be a great help in my project.
+Yixingsmoo Aeri Hey there thanks for the comment. What exact time were you needing? Are you wanting to know how to set it up to perform a task at a specific time and date?
I needed it turn on every 7:30am and stay on for 10mins and then off and it will turn again at 4:00pm and stay on for 10mins also then off. I want to make it happen everyday. Is this possible using DS1307?
If you can help me in coding, I'll appreciate it very much. Thanks. :)
+misperry I needed it turn on every 7:30am and stay on for 10mins and then off and it will turn again at 4:00pm and stay on for 10mins also then off. I want to make it happen everyday. Is this possible using DS1307? And by the way, I just wanna ask if it is okay if we dont use LCD in this? Hope you'll response sir. Thanks! =)
+Yixingsmoo Aeri in my example you can use the now.hour() and there is a day of the week function that will return the day of the week. There is a bunch of information in the link in the description. I have included that here. github.com/adafruit/RTClib Also I could give you some sample code but it will take a while since I am very busy. Hope this helps.
it was an awesome helpful video, thank you and appreciate you. can you show me how to interface with lcd
+fikadu shewit gidey Hey there, thanks for the comment. Yeah I will have to do a video on how to use the arduino and an LCD. Good Idea.
das it work for ds1302?
Andraž Zupan I am not sure since I have not tested it on that device. You can check it out.
how can i get day of week. ex: sunday?
Trần Trung Hey there, I believe it is the weekday() function i.e. now.weekday(). It looks like the software library may have been updated since I made this video so you can check it out on this page: playground.arduino.cc/code/time
misperry i tried. Error: 'class DateTime' has no member named 'weekday'.
Hmm, well I was looking at the latest code for that library. You could always look at the source for the library and see if there is anything available for the week day. If not you could either see if there is an updated library at raspberrypi.org or you can check out the data sheet for the ds1307 and make your own function to read the register that has that information. I know the ds1307 hardware supports this feature. Take care
need code
My rtc is showing nothing, do you know what is happening ?
check your wiring and ensure that everything is connected properly. Ensure the crystal for the clock is connected.
Try the debugging section of this video: ruclips.net/video/drU3dQa-8CE/видео.html
The DS1`307 RTC is a nice clock but if the temperature isn't 25 degrees celcius it is not very precise.
Hey there, thanks for your comment. Yes but it is not due to the device since the device has a temp range fo -40C to 85C. Where the error comes in is with the crystal selection. Depending on the temp drift of the crystal and the capacitive trimming of it will effect your clock's accuracy. So if you need a wide temp range then you need to be very selective of your crystal that you will use to get the maximum precision out of the clock. For selecting the crystal you can refer to maxim's application note 58 located below.
www.maximintegrated.com/app-notes/index.mvp/id/58
Awesome work man well done. this work fine but sometimes i have a problem instead of show 09:07:05 shows something like this 9:7:5
TIfail L Hmmm I am not sure why it is doing that. did you set 24hr clock or 12hr?
Ds1307 can only run on 5v
Check out my Siemens S7-1200 Realtime function
ruclips.net/video/jY117f6YryU/видео.html
Very nice vidéo i really like it :)
can you help me in my project based on arduino Uno ? how to use real time in my code of "the automatic spray of gardin" with preset time !!
i really appreciate your attention and help :)
Maher Marwen Hey there, sure I have a video doing exactly that it is called the automated sprinkler. Give it a look: ruclips.net/video/S7TrhZua1dw/видео.html
misperry thank you very much i really appreciate your help but it doesn't compile at the end of the code .. PS: i use a carte of Arduino UNO