RTC DS1307

[ [ images, codes & links ] ]

Gambar 1.

A real-time clock (RTC) is a computer clock (most often in the form of an integrated circuit) that keeps track of the current time.

Although the term often refers to the devices in personal computers, servers and embedded systems, RTCs are present in almost any electronic device which needs to keep accurate time.

<span class="su-quote-cite"><a href="https://en.wikipedia.org/wiki/Real-time_clock" target="_blank">Real-time clock</a></span>

What is an RTC?

A real time clock is basically just like a watch – it runs on a battery and keeps time for you even when there is a power outage! Using an RTC, you can keep track of long timelines, even if you reprogram your microcontroller or disconnect it from USB or a power plug.

Most microcontrollers, including the Arduino, have a built-in timekeeper called millis() and there are also timers built into the chip that can keep track of longer time periods like minutes or days. So why would you want to have a separate RTC chip? Well, the biggest reason is that millis() only keeps track of time since the Arduino was last powered – . That means that when the power is turned on, the millisecond timer is set back to 0. The Arduino doesn’t know that it’s ‘Tuesday’ or ‘March 8th’, all it can tell is ‘It’s been 14,000 milliseconds since I was last turned on’.

OK so what if you wanted to set the time on the Arduino? You’d have to program in the date and time and you could have it count from that point on. But if it lost power, you’d have to reset the time. Much like very cheap alarm clocks: every time they lose power they blink 12:00

While this sort of basic timekeeping is OK for some projects, some projects such as data-loggers, clocks, etc will need to have consistent timekeeping that doesn’t reset when the Arduino battery dies or is reprogrammed. Thus, we include a separate RTC! The RTC chip is a specialized chip that just keeps track of time. It can count leap-years and knows how many days are in a month, but it doesn’t take care of Daylight Savings Time (because it changes from place to place).

~DS1307 Real Time Clock Breakout Board Kit

 

What are Real Time Clocks?

Real time clocks (RTC), as the name recommends are clock modules. The DS1307 real time clock (RTC) IC is an 8 pin device using an I2C interface. The DS1307 is a low-power clock/calendar with 56 bytes of battery backup SRAM. The clock/calendar provides seconds, minutes, hours, day, date, month and year qualified data. The end date of each month is automatically adjusted, especially for months with less than 31 days.

They are available as integrated circuits (ICs) and supervise timing like a clock and also operate date like a calendar. The main advantage of RTC is that they have an arrangement of battery backup which keeps the clock/calendar running even if there is power failure. An exceptionally little current is required for keeping the RTC animated. We can find these RTCs in many applications like embedded systems and computer mother boards, etc.

~www.elprocus.com/rtc-ds1307/

 

 

Arduino Tiny RTC D1307 Tutorial

 

Gambar 2. [henrysbench.capnfatz.com]

Gambar 3. [henrysbench.capnfatz.com]

Gambar 4. [tronixstuff.com]

Connecting your module to an Arduino

Both modules use the I2C bus, which makes connection very easy. If you’re not sure about the I2C bus and Arduino, check out the I2C tutorials (chapters 20 and 21), or review chapter seventeen of my book “Arduino Workshop“.

Moving on – first you will need to identify which pins on your Arduino or compatible boards are used for the I2C bus – these will be knows as SDA (or data) and SCL (or clock).

~ tronixstuff.com

 

 

Tiny RTC

Gambar 5.

Features

  • 5V DC supply
  • Programmable Square-Wave output signal
  • Automatic Power-Fail detect and switch circuitry
  • Consumes less than 500nA in Battery-Backup Mode with Oscillator Running
  • 56-Byte, Battery-Backed, Nonvolatile (NV)RAM for data storage

Gambar 6.

TinyRTC hardware1.jpgGambar 7.

~www.elecrow.com

 

 

RTC DS-1307 with Arduino

DS 1307 RTC Pinout

Gambar 8.

Block Diagram of DS1307

Gambar 9. [Datasheet]

Gambar 10.

~www.theorycircuit.com

 

Terdapat beberapa pustaka/library untuk tiap RTC. Dua yang disampaikan dalam “mashup ini adalah pustaka dari Adafruit dan pustaka dari Makuna.

Contoh-contoh kode program sistem Arduino untuk RTC DS1307.

adafruit: ds1307.ino

[code lang=”C”]// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup ()
{
while (!Serial); // for Leonardo/Micro/Zero

// Serial.begin(57600);
Serial.begin(9600);

if (! rtc.begin())
{
Serial.println("Couldn’t find RTC");
while (1);
}

if (! rtc.isrunning())
{
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date &amp; time this sketch was compiled
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date &amp; time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}

void loop ()
{
DateTime now = rtc.now();

Serial.print(now.year(), DEC);
Serial.print(‘/’);
Serial.print(now.month(), DEC);
Serial.print(‘/’);
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(‘:’);
Serial.print(now.minute(), DEC);
Serial.print(‘:’);
Serial.print(now.second(), DEC);
Serial.println();

Serial.print(" since midnight 1/1/1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");

// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));

Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print(‘/’);
Serial.print(future.month(), DEC);
Serial.print(‘/’);
Serial.print(future.day(), DEC);
Serial.print(‘ ‘);
Serial.print(future.hour(), DEC);
Serial.print(‘:’);
Serial.print(future.minute(), DEC);
Serial.print(‘:’);
Serial.print(future.second(), DEC);
Serial.println();

Serial.println();
delay(3000);
}[/code]

[intense_tabs direction=”right” active_tab_background_color=”#000000″ active_tab_font_color=”#ffff00″ trigger=”click”] [intense_tab title=”Video01″ border=”3px solid #e8e8e8″ link_target=”_self” content_background_color=”#000000″ content_font_color=”#ffffff” icon_size=”1″ icon_position=”left”]

[/intense_tab] [intense_tab title=”Video02″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video03″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [intense_tab title=”Video04″ border=”3px solid #e8e8e8″ link_target=”_self” icon_size=”1″ content_background_color=”#000000″ content_font_color=”#ffffff” icon_position=”left”]

[/intense_tab] [/intense_tabs]