Tags: Real, Time, Control, RTC, Module, DS1302, DS1307

Real Time Control RTC Module DS1307

  • 20.00 AED
    • Ex Tax:20.00 AED
    • Product Code: DS1307
    • Availability: In Stock
    An RTC or Real Time Clock is a Timekeeping device, usually in the form of an Integrated Circuit (IC). An RTC is battery powered and keeps track of the current time even when there is no power. Real Time Clock ICs are present in computers, servers, many embedded systems and in fact they are used..

    An RTC or Real Time Clock is a Timekeeping device, usually in the form of an Integrated Circuit (IC). An RTC is battery powered and keeps track of the current time even when there is no power. Real Time Clock ICs are present in computers, servers, many embedded systems and in fact they are used wherever it is required to keep an accurate time

    Description:

    24C32 32K I2C EEPROM memory
    Using LIR2032 rechargeable lithium battery with charging circuit
    Solve the problem of no literacy of the DS1307 with backup battery
    Support timing 1 year of the DS1307 after fully charged
    Leads to the DS1307 clock pin provides a clock signal for the microcontroller
    Other I2C devices can be cascaded
    Size: 27 x 28 x 8.4mm


    Package included:

    1 x DS1307 module ( battery not included )


    and this Tutorial Will help you start programming and wiring the DS1307 real time clock with an Arduino Uno. The DS1307 is used to keep track of time, even when the main power is out using a coin cell battery. This makes it useful for applications like alarm clocks, weather stations, etc.



    For the RTC library, we'll be using a fork of JeeLab's excellent RTC library, which is available on GitHub Click Here . You can do that by visiting the github repo and manually downloading or, easier, just click this button to download the zip

    Install Adafruit_RTCLib library

    For the RTC library, we'll be using a fork of JeeLab's excellent RTC library.

    To begin reading and writing to the RTC, you will need to install the Adafruit_RTClib library (code on our github repository). It is available from the Arduino library manager so we recommend using that.

    From the IDE open up the library manager...

    adafruit_products_managelib.png

    And type in RTClib to locate the library. 

    Look for the Adafruit RTClib (there may be others!)

    Click Install

    adafruit_products_rtclib.png

    First RTC Test

    The first thing we'll demonstrate is a test sketch that will read the time from the RTC once a second. We'll also show what happens if you remove the battery and replace it since that causes the RTC to halt. So to start, remove the battery from the holder while the Arduino is not powered or plugged into USB. Wait 3 seconds and then replace the battery. This resets the RTC chip. Now load up the following sketch (which is also found in Examples→RTClib→ds1307) and upload it to your Arduino with the datalogger shield on!


    adafruit_products_ds1307.png

    Now open up the Serial Console and make sure the baud rate is set correctly at 57600 baud you should see the following:

    adafruit_products_RTCnotrun.gif
    Whenever the RTC chip loses all power (including the backup battery) it will report the time as 0:0:0 and it won't count seconds (its stopped). Whenever you set the time, this will kick start the clock ticking. So basically the upshot here is that you should never ever remove the battery once you've set the time. You shouldn't have to and the battery holder is very snug so unless the board is crushed, the battery wont 'fall out'

    Setting the Time

    With the same sketch loaded, uncomment the line that starts with RTC.adjust like so:
     Download: file
    1. if (! rtc.initialized()) {
    2. Serial.println("RTC is NOT running!");
    3. // following line sets the RTC to the date & time this sketch was compiled
    4. rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

    This line is very cute, what it does is take the Date and Time according the computer you're using (right when you compile the code) and uses that to program the RTC. If your computer time is not set right you should fix that first. Then you must press the Upload button to compile and then immediately upload. If you compile and then upload later, the clock will be off by that amount of time.

    Then open up the Serial monitor window to show that the time has been set.

    adafruit_products_RTCsettimegif.gif
    From now on, you wont have to ever set the time again: the battery will last 5 or more years.

    Reading the Time

    Now that the RTC is merrily ticking away, we'll want to query it for the time. Lets look at the sketch again to see how this is done.
     Download: file
    1. void loop () {
    2. DateTime now = rtc.now();
    3. Serial.print(now.year(), DEC);
    4. Serial.print('/');
    5. Serial.print(now.month(), DEC);
    6. Serial.print('/');
    7. Serial.print(now.day(), DEC);
    8. Serial.print(" (");
    9. Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    10. Serial.print(") ");
    11. Serial.print(now.hour(), DEC);
    12. Serial.print(':');
    13. Serial.print(now.minute(), DEC);
    14. Serial.print(':');
    15. Serial.print(now.second(), DEC);
    16. Serial.println();

    There's pretty much only one way to get the time using the RTClib, which is to call now(), a function that returns a DateTime object that describes the year, month, day, hour, minute and second when you callednow().

    There are some RTC libraries that instead have you call something like RTC.year() and RTC.hour() to get the current year and hour. However, there's one problem where if you happen to ask for the minute right at3:14:59 just before the next minute rolls over, and then the second right after the minute rolls over (so at3:15:00) you'll see the time as 3:14:00 which is a minute off. If you did it the other way around you could get 3:15:59 - so one minute off in the other direction.

    Because this is not an especially unlikely occurrence - particularly if you're querying the time pretty often - we take a 'snapshot' of the time from the RTC all at once and then we can pull it apart into day()or second()as seen above. Its a tiny bit more effort but we think its worth it to avoid mistakes!

    We can also get a 'timestamp' out of the DateTime object by calling unixtime which counts the number of seconds (not counting leapseconds) since midnight, January 1st 1970

     Download: file
                  

    There are no reviews for this product.

    Write a review

    Please login or register to review

    FREE RETURNS

    *for faulty items and in-store drop off for unused items. T&C applies.

    Customer Support

    We really care about you and your order as much as you do. Please contact us without hesitation.

    INTERNATIONAL SHIPPING

    We can ship your order internationally. Please contact us first before proceeding with your order.

    Fast Delivery

    You want your item next day? No problem! We advise contacting us ASAP to insure smooth delivery experience