Always on time with the DS1307 and DS3231 REAL time clock modules

Placed on
REAL time clock modules REAL time clock modules

REAL time clock versions

The REAL time clock series contains many different type numbers, all with comparable functionality. In this series only 2 versions are 'mainstream', namely the DS1307 and the DS3231. These chips both have the option to connect a battery and have a sqw output pin, with which the controller can receive a clock pulse of (1Hz, 1.024kHz, 4.096kHz, 8.192kHz). Both ICs also have a One-Wire interface, which makes it possible to connect them over I2to address C.
DS1302 Real Time Clock Module - SPIThe DS1302 Real Time Clock Module has an SPI interface through which it can tell the time. Out of stock € 1,85
Real time clock module DS3231Real time clock module with the DS3231 chip. This module ensures that the Arduino knows the exact time at all times. By connecting the Arduino to the ´qw´ pin, it is possible to generate an interrupt every second with which sensor values or a display can be addressed. In stock € 3,95

Connecting the RTC module to the Arduino UNO

The RTC modules come in different shapes and sizes, but the connection to the Arduino is the same for all modules. The module must in any case be powered with 5V, furthermore the I2C interface will have to be connected to the SDA (Serial data) SCL (Serial clock) pins of the Arduino (these are pins A4 and A5 on the Arduino UNO). Furthermore, the SQW output can be connected to any pin of the Arduino to receive a clock pulse from the RTC.

DS1307 connection Arduino UNO DS1307 connection Arduino UNO

BC Code

The numerical values in the RTC chips are stored in BCD format. BCD code is easier to use than decimal numbers on a hardware level, but these codes are not very useful in software. The numbers to and from the chip must therefore be encoded and decoded so that the controller and RTC understand each other.

Write the current time to the RTC

The time only needs to be written to the RTC once when it is connected to the battery. The RTC itself keeps time and continues counting, even when it is not connected to the controller.
Hard drive clock Hard drive clock

De tijd van de RTC lezen

Show the time

With these functions together, the time can be determined by the Arduino . With the function below this data is written to the serial monitor, but the possibilities for displaying the time are endless.

SQW frequentie instellen

With this code a complete clock can be built, which can display the time. This can be done on a 7-segment display, as an analog clock, with smoke signals or it can even be spoken when requested. In addition, the time can also be used in home automation / home automation, coffee maker switches on in the morning at 8 am, the microwave at 5.15 pm in the evening and the curtains close at 7.01:05 pm. Everything is possible.
Posted by Website I am interested in electronics, programming and especially the combination between them. For Opencircuit I write blogs in which I explain how electronics and modules work.


Webwinkelkeur Kiyoh Trustpilot Opencircuit