This is part 10 of the Arduino tutorial series, which will be shown the operation of a real-time clock and a project example.
The DS3231SN chip
These are the two sides of real-time clock shield ZS-042. Uses the integrated circuit DS3231SN, which can show data and hours properly.
The lithium battery is used as backup voltage in case Arduino’s energy is cut. It communicates with Arduino by I2C protocol. The DS3231SN stores information of day, month, year, and hour, with leaf-year correction until 2100. Has an oscillator with crystal and temperature compensator. To detect energy fallout, a comparator circuit with a voltage reference and temperature compensation verifies the supply voltage and sends a reset signal to use the battery.
Module’s schematics
This is the module’s schematics.
The 8-pin AT24C32N chip is a 32k EEPROM memory, these are other external components. The 1 is the indicator that the module is on, 2 is a resistor set and 3 is a protection circuit against excess voltage with a zener diode.
In addition to the supply pins VCC and GND, other pins are:
- 32K: 32 kHz oscillator output.
- SQW: Optional output of square wave signal.
- SCL: I2C clock pin.
- SDA: I2C data pin.
Project with real-time clock (RTC)
How to connect the RTC module with Arduino Uno? Must connect the SCL in analog input 5 and SDA in analog input 4. If your battery is CR2032, like mine, VCC must stay at 3.3V, because this battery isn’t rechargeable.
If the board is Arduino Mega, SDA must be linked in the digital input 20 and SCL in digital input 21. In Leonardo board, SDA is in digital input 2 and SCL in digital 3. Before writing the code, it is necessary to download the RTClib library, click on this link. Get the code that comes with the library. To open this example, do like is shown in the video below.
This is the complete code of an example with DS3231.
You must see this on the serial screen.