DS3231 (Real Time Clock) with Arduino

It is possible to calculate time with relative simplicity using the millis() function, on Arduino. However, there are cases where you need to know exactly a date, or take an action at a certain hour, minute, second. For this, a module like the DS3231 is a hand on the wheel.

Figure 1 - DS3231 and Arduino

The sensor

The DS3231 RTC module is a circuit based on the DS3231 chip that operates in both 3.3 V and 5 V, with high precision, capable of automatically adjusting and correct dates for months with different days and leap years, and low power consumption (About 500 nA in battery mode with the oscillator on).

Additionally, it has a memory chip, the AT24C32, it has a capacity of 32 Kb, EPROM, which can be used by the microcontroller as extended memory, also it has an integrated temperature sensor and can use a CR (3 V) battery to avoid lose data in the event of a power failure to the module.

The module also allows the creation of two programmable time alarms.

The circuit

Communication from the module to the Arduino is done by I2C (Inter Integrated Circuit), which is a popular serial communication protocol and the connection is very simple. It is worth mentioning that on the different Arduino boards, the I2C ports are accessed by different pins, for example, Uno and Nano: SDA (A4), SCL (A5), Mega and Leonardo: SDA (20), SCL (21). Material:
  • 1x - Arduino
  • 1x - DS3231 module
  • 2x - 10 KR resistors
Figure 2 - Assembled circuit

The mounting pinouts are intuitive, VCC and GND connected to the Arduino's 5V and GND, SDA (Serial Data) and SCL (Serial Clock), to pins A4 and A5 (In the case of Arduino Uno). The SQW pin, optional, served as a programmable square wave output or, as an interrupt switch, as in our case, it is connected to pin D2, and to a Pull-Up resistor to avoid reading noise. The 32K pin, also optional, is used to read the pulses of the crystal oscillator, it is connected to the PWM pin, D3, and to a Pull-Up resistor.

The programmation

To program this module there are several libraries available to assist in this task, my recommendation is to use the Rtc (Makuna) library , one of the most complete. It can be easily installed by the Arduino IDE itself, using the library manager, just search for "RTC Makuna", and then, see the list of usage examples or consult the library Wiki, on the repository link, for details on programming.

DS3231 (Real Time Clock) with Arduino DS3231 (Real Time Clock) with Arduino Reviewed by AJ Alves on quinta-feira, abril 27, 2017 Rating: 5

Nenhum comentário:

Tecnologia do Blogger.