Interfacing Arduino with DS1307 real time clock




This topic shows how to interface Arduino with DS1307 real time clock to make a clock and calender.
To understand the project and code easily you have to read the datasheet of the DS1307.
DS1307 Pin assignment:
The picture is taken from ds1307 datasheet and it shows the pin assignment of our chip RTC:
Interfacing Arduino with DS1307 real time clock




Arduino real time clock using DS1307 circuit:
Arduino ds1307 real time clock
On the circuit schematic there are two buttons used to set the time and date.
The LCD display shows both time and date at the same time, and the LED connected to the ds1307 toggles on and off (can be programmed on the software).
The I2C bus needs pullup resistors to run that why I used the 10K as a pullup resistors.
Arduino real time clock using DS1307 code: 
We have to follow the table shown below write/read date to/from ds1307:
DS1307_reg
To write data to the ds1307RTC you have to follow these steps:

1 – Start I2C protocol,
2 – Send the DS1307 address which is in binary 11010000 (0x68),
3 – Send register address according to the below table (for example hour register is 0x02),

4 – Write register value,
5 – Stop the I2C protocol.
Writing data to ds1307 Arduino code:
  Wire.beginTransmission(0x68);//Start I2C with device #0x68
  Wire.write(address); // Set the register pointer to (address) 
  Wire.write(data_);  //Write (data_) to register #(address)
  Wire.endTransmission(); //Stop I2C protocol

To read data from ds1307 you have to do the following:
1 – Start I2C protocol,
2 – Send the DS1307 address which is in binary 11010000,
3 – Send register address,
3 – Stop I2C protocol,
4 – Start I2C protocol in read mode.
Reading data from ds1307 RTC Arduino code:




Clip to Evernote

Leave a Comment

(Spamcheck Enabled)

Read previous post:
Analog Ultrasound Range Finder
Analog Ultrasound Range Finder

When I started my career in control systems I was fascinated with the many different ways that machines could be...

Close
Scroll to top