This is the part 10 of Arduino tutorial series, will be shown the operation of a real time clock and an example of project.
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 hour properly.
The lithium battery is used as backup voltage in case the 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 fall out, a comparator circuit with voltage reference and temperature compensation verify the supply voltage and sends a reset signal to use the battery.
This is the module’s schematics.
The 8 pins 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 the analog input 4. If your battery is CR2032, like mine, VCC must stay in 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. If is the Leonardo board, SDA in digital input 2 and SCL in digital 3. Before write the code, it is necessary to download the RTClib library, click in this link. Get the code which comes with the library. To open this example, do like is shown in the video below.
This is the complete code of example with DS3231.
You must see this in the serial screen.