Académique Documents
Professionnel Documents
Culture Documents
The DS3231 RTC module shown in the figure is equipped with a 3V CR2032 battery and is able
to provide information on date, time and ambient temperature.
Thanks to the battery it is equipped with, once the time and date have been memorized, it keeps
on counting the time, even when it is not in use or removed from the circuit.
The module supplies the information to the Arduino through the I2C communication protocol or
SDA / SCL bus.
In Arduino Uno this protocol is managed by the A4 and A5 ports in Arduino Mega 2560 on ports
D20 and D21.
In this exercise we will not only use the RTC DS3231 module, but we will also use a 16x02 LCD
display managed by an I2C driver and then we will have two components that use the SDA /
SCL bus at the same time.
COMPONENTS:
Arduino ONE
RTC DS3231
16x02 I2C LCD Display
2x Microswitch buttons
2x 10KOhm resistors
Breadboard
Jumper cables MM / MF
CONNECTION DIAGRAM:
In the circuit there are 2 buttons connected to pins 8 and 9 respectively. The two buttons are used
to set the date and time parameters (minutes, hours, date, month and year).
The first button selects the parameter and the second one increases the selected parameter.
LIBRARIES:
First we need to install a library on the Arduino IDE.
We will use the library Newliquidcrystal_1.3.5 for operating the I2C LCD display.
To install the libraries open Arduino IDE and click Sketch> #includi Library> Add to Library ..
.ZIP file and select the library you just downloaded.
The following Arduino sketch does not use any library for the DS3231 RTC module, the Wire
library is for communication between the Arduino and the DS3231 for the I2C protocol.
Download file
SKETCH:
Download file
The DS3231 module only works with the BCD format ( Binary-coded decimal on wikipedia )
and to convert the BCD to decimal and vice versa I used the following 2 lines (example per
minute):
void DS3231_display ( ) { }
Inside this small function at the bottom is the pause of the blinking and is interrupted by the
buttons (connected to pins 8 and 9).
With this function we can see the blinking of the selected parameter with a frequency of 2Hz.
So a delay of 250 ms arrives after printing the selected parameter and after this delay 2 spaces
are printed to make the parameter disappear on the LCD display, then another 250 ms delay
arrives after printing the 2 spaces.
void blink_parameter ( ) {
byte j = 0 ;
while ( j < 10 && digitalRead ( 8 ) && digitalRead ( 9 )) {
j ++ ;
delay ( 25 ) ;
}
}