Function: what the DS1307 does in a circuit
A small clock module that keeps the time and date, even when the Arduino is switched off.
- Keeps the time and date, even with the power off
- Tells the sketch the hour, minute and second on request
- Lets projects act at set times, such as alarms and timers
DS1307 key facts
| Chip | DS1307 real-time clock |
|---|---|
| Interface | I²C, address 0x68 |
| Supply | 5 V |
| Crystal | 32.768 kHz |
| Backup | CR2032 coin cell, about 5 to 10 years |
| Keeps | seconds, minutes, hours, day, date, month, year (to 2099) |
| Accuracy | about ±2 seconds a day |
| Library | RTClib |
DS1307 pinout
The connections, in the order they appear on the part:
| No. | Name |
|---|---|
| 1 | GND |
| 2 | VCC |
| 3 | SDA |
| 4 | SCL |
| 5 | SQW (square wave out) |
How to connect the DS1307 to an Arduino
Connect GND to GND, VCC to 5V, SDA to A4 and SCL to A5 on an Uno (pins 20 and 21 on a Mega).
Example sketch:
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;
void setup() {
Serial.begin(9600);
rtc.begin();
}
void loop() {
DateTime now = rtc.now();
Serial.print(now.hour());
Serial.print(":");
Serial.print(now.minute());
Serial.print(":");
Serial.println(now.second());
delay(1000);
}Run this in the free simulator
How it works
The DS1307 chip counts the ticks of a 32.768 kHz watch crystal: 32,768 ticks make exactly one second, because 32,768 is 2 to the power 15 and a chain of 15 divide-by-two stages turns it into one pulse per second. It stores seconds, minutes, hours, day, month and year, and a CR2032 coin cell keeps it counting for years without main power. The Arduino asks it for the time over I²C (address 0x68). With RTClib: rtc.begin(), then DateTime now = rtc.now() and now.hour(), now.minute(), now.second().
What it is made of
- Chip: DS1307 silicon chip in a black epoxy package SiCHO
- Crystal: A tiny quartz tuning fork in a metal can SiO
- Backup cell: CR2032 lithium and manganese dioxide coin cell LiMnO
- Board: Glass-fibre and epoxy with copper tracks CuSn
Where the materials come from: Quartz grown from silica; lithium from brines and spodumene; manganese from pyrolusite.
The chemistry
Quartz is piezoelectric: a voltage makes it flex and flexing makes a voltage, so a crystal cut to the right size rings at one exact frequency, like a tuning fork.
Biology connection
Your body has a clock too. The heart keeps its own steady beat from a group of pacemaker cells, which fire on their own rhythm much as the crystal ticks. The heart's electrical system →
Safety and the environment
Without the coin cell the clock forgets the time at every power cut. The DS1307 needs 5 V; it can drift by a few seconds a day as the temperature changes.
Did you know? Almost every quartz watch and clock uses the same 32,768 Hz crystal frequency.
Microcontroller simulator4-digit display (TM1637)Coin cell (CR2032, 3 V) Elements inside: SiCHOLiMnCuSn
Try it in the simulator
Build and code a circuit with a Real-time clock in these practice projects:
Questions students ask
What does the DS1307 do?
A small clock module that keeps the time and date, even when the Arduino is switched off. Main functions: keeps the time and date, even with the power off; tells the sketch the hour, minute and second on request; lets projects act at set times, such as alarms and timers.
Why use a real-time clock when Arduino has millis()?
millis() only counts from the moment the board was switched on and starts again from zero after every reset. A real-time clock knows the actual time of day and keeps counting on its coin cell while the Arduino is off.
What are the connections of the DS1307?
In order: GND, VCC, SDA, SCL, SQW (square wave out).
How do I connect the DS1307 to an Arduino?
Connect GND to GND, VCC to 5V, SDA to A4 and SCL to A5 on an Uno (pins 20 and 21 on a Mega).
How does the DS1307 work?
The DS1307 chip counts the ticks of a 32.768 kHz watch crystal: 32,768 ticks make exactly one second, because 32,768 is 2 to the power 15 and a chain of 15 divide-by-two stages turns it into one pulse per second. It stores seconds, minutes, hours, day, month and year, and a CR2032 coin cell keeps it counting for years without main power. The Arduino asks it for the time over I²C (address 0x68). With RTClib: rtc.begin(), then DateTime now = rtc.now() and now.hour(), now.minute(), now.second().
What is the DS1307 made of?
Chip: DS1307 silicon chip in a black epoxy package. Crystal: A tiny quartz tuning fork in a metal can. Backup cell: CR2032 lithium and manganese dioxide coin cell. Board: Glass-fibre and epoxy with copper tracks.
Is the DS1307 safe? How should it be recycled?
Without the coin cell the clock forgets the time at every power cut. The DS1307 needs 5 V; it can drift by a few seconds a day as the temperature changes.
More sensors
Connected tools
The same idea from another angle, across the site.