Arduino Real Time Clock using DS1307 | Arduino Tricks
Arduino

Arduino Real Time Clock using DS1307

May 2, 2019

DS1307 Real Time Clock:


Real-time clocks (RTC), because the name recommends square measure clock modules. The DS1307 real clock (RTC) IC is associate eight pin device victimization associate I2C interface. The DS1307 may be a low-power clock/calendar with fifty-six bytes of battery backup SRAM. The clock/calendar provides seconds, minutes, hours, day, date, month and year qualified information.

Real clock (RTC) the aim of associate RTC or a true clock is to supply precise time and date which might be used for varied applications. RTC is an associate device within the sort of associate Integrated Chip (IC) offered in varied packaging choices. it’s high-powered by an inside atomic number 3 battery.

RTC Module

A period clock (RTC) is associate IC that keeps associate updated track of the present time. This info may be browsed by a chip, typically over a serial interface to facilitate the software system activity functions that square measure time-dependent.

We will be victimization the DS1307 real clock that may be low power, binary coded decimal (BCD) clock calendar. It provides seconds, minutes, hours, day, date, month and year info. It adjusts the date for leap years and it additionally adjusts the months that have but thirty-one days in them. The time format may be designated to either twelve or twenty-four hours and electric battery backup is employed to stay time once power is off from the circuit.

Pin description of DS1307 RTC:


 

DS1307 IC

X1 and X2: These are pins for connecting the crystal of frequency 32.768 KHz to enable the internal oscillator. If an external oscillator is connected to X1, then X2 can be left floating.

VBAT: Battery Power Supply Pin. Must be connected to a 3V Lithium cell for backup supply.

SDA: Serial Data Pin. It is the Data Input/Output pin of the I2C Interface. An external pull-up of 5V is required, usually through a 10KΩ Resistor.

SCL: Serial Clock Input Pin. It is the clock input pin of the I2C Interface. It must also be pulled up to 5V through a 10KΩ resistor.

SQW/OUT: Square wave output pin. If not used, it can be left floating.

GND: Ground Pin.

VCC: The main supply pin.      

Required Components:


Required Components with Purchase Link from Ali Express

Connection Diagram:


 

The design of the Arduino RTC Interface is kind of simple. Connect the SDA and SCL pins of the DS1307 RTC to the SDA and SCL pins of Arduino i.e. pins A4 and A5. A 16×2 show LCD digital display alphanumeric display is connected so as to display info and time information. The connections area unit created as per the circuit diagram.

RTC 1307 Module

The following image shows the circuit diagram of the Arduino Real clock DS1307 Interface. This circuit explains simply the essential connections with reference to a DS1307 Module (a board that contains the DS1307 IC in conjunction with the crystal, Battery and pull-up resistors).

We are going to proceed with the interface of Arduino and Real clock. As mentioned earlier, the DS1307 RTC Module uses I2C Communication. within the Arduino Real clock I2C interface, the Arduino Microcontroller continually acts as Master and also the DS1307 acts as Slave. The Master in I2C Communication i.e. Arduino during this case is answerable for the clock signal, bus access, begin and stop signals.

Working Steps:


First Step:

It adjusts the date for leap years and it additionally adjusts the months that have but thirty-one days in them. The time format may be designated to either twelve or twenty-four hours and electric battery backup is employed to stay time once power is far from the circuit. The DS1307 may be employed in your comes like knowledge work to produce a time stamp or for planning functions like Associate in Nursing irrigation controller.

Second Step:

We wire up the clock by connecting the bottom and power pins to the microcontroller’s ground and power pins. Then the I2C wiring is connected mistreatment the clock’s SDA and SCL pins to the microcontrollers SDA and SCL pins that are analog pin five for SCL and analog pin four for SDA. there’s an additional yellow wire that connects the board’s pin a pair of to ground that we’ll investigate a small amount more down the page.

Third Step:

We initially set the time and date variables to the time and date you’d just like the clock to begin at. we tend to enter the computer memory unit variables in decimal type because the code can convert them into binary coded decimal before the values are sent to the clock’s registers.

When you investigate the code, at first it will appear to be a great deal however don’t let that deter you. we’ve not used a clock library, however, are instead dominate the clock directly mistreatment the wire.h library. this fashion you’ll perceive however the I2C communication works once we set and skim the data to and from the clock.

Earlier up the page, we tend to mention the additional yellow wire connecting the board’s pin a pair of to ground. we’ve introduced Associate in Nursing “If-Else” statement, therefore, the clock doesn’t reset on every occasion throughout power up. So, once we tend to transfer the program, we tend to set pin a pair of high and also the clock are set at power up. After that, we are able to connect pin a pair of to ground and leave it that method till we would like to reset the clock once more.

Fourth Step:

Also, I might extremely appreciate it for you to affix my email subscriber list wherever we’ll keep you up thus far with our latest videos, tutorials, and articles regarding microcontrollers, Arduino and alternative physical science data. to create it easier you’ll place a button that goes high once ironed (see the image above). so as to reset the time, the button controls down simply before the board is hopped-up up, and once the time starts to show on the liquid crystal display we are able to unleash the button.

Code:


Code:


You Might Also Like

  • rollex11 download May 7, 2019 at 3:32 am

    Keep your vision of one’s work whilst your success good.
    and keep moving. When you feel yourself resisting something, let
    these questions be your guide. This reduces your anxiety to a
    splendid extent.