• Worldwide Shipping

  • 24/7 Customer Support

  • FAQ
  • Worldwide Shipping

  • 24/7 Customer Support

  • FAQ

HUM: RTC - Real Time Clock DS1307

You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect module with Croduino and the basic code. Everything else is left to your imagination.

What is RTC?

Real-Time Clock is an electronic device which closely monitors time. In this tutorial we will deal with a newer DS3231SN.
RTC
RTC modules mainly use 32.768 kHz frequency crystal oscillator, which is also used in quartz watches. In comparison to the DS1307, the model DS3231 has a built-in TCXO (Temperature Compensated Crystal Oscillator), which brings stability that could not be achieved with a regular oscillator, while changing temperature. Together, they make up a whole which allows long-term and precise time monitoring.

Characteristics:

Voltage: 3.3V - 5.5V
Current: 170uA (stand-by 5.5V)
Communication: 400kHz I2C (default address 0x68)
Temperature: -40°C do +85°C (for the SN model which is on the breakout in our offer)
Dimensions: 38mm x 22mm x 14mm

What, and how does it work ?

RTC follows seconds, minutes, hours, days of the week, date: days of the month, months and years. Once we set the time we can follow the calendar up until 2100. This means that the date at the end of the month is automatically transferred, the same goes for the leap years. The clock works in both 24 and 12 hour format, and two programmable alarms are installed. The module and controller are connected via two-way I2C communication. All you need for this communication is on the breakout. If you have the need to change the I2C address, you can do this by connecting the A0, A1 and A2 falls to the breakout of the module.

The battery is used with the module for the purpose of preserving the set time. When the system within the DS3231 detects that a permanent power supply is interrupted, it is switched to the battery. The battery corresponding to the breakout is CR2032, and its capacity is 240mAh. The same thing is automatically done in the opposite direction.

Connecting it to Croduino

Connectivity, library and sample sketch can be used for DS3231 and DS3232 models. 

Povezivanje RTC na CRoduino

Arduino code

Download the library here.

Time setting code:

#include "DS3231.h"
DS3231 rtc(SDA, SCL);
void setup()
{
rtc.begin();
rtc.setDOW(WEDNESDAY); // set the day of the week
rtc.setTime(9, 17, 0); // set the time, 24h format (hour, minute, second)
rtc.setDate(17, 2, 2016); // set the date (day, month, year)
}
void loop()
{
}

Serial time tracking code:

#include "DS3231.h"
DS3231 rtc(SDA, SCL);
void setup()
{
Serial.begin(115200); // do not forget to set the BAUD rate to 115200 in Serial Monitor
rtc.begin();
}
void loop()
{
// shows the day of the week
Serial.print(String(rtc.getDOWStr())+"\t");
// shows the date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// shows the time
Serial.println(rtc.getTimeStr());
// pause 1s
delay (1000);
}
Leave a Reply