How to interface the DS3231 RTC Module with NodeMCU. Learn to Setup and display the time of DS3231 on Serial Monitor.
First, let’s start with the basics of the DS3231 Real Time Clock Module.
Operating Voltage: 3.3 – 5V
Accuracy: ±2ppm at 0°C to +40°C and ±3.5ppm at -40°C to +85°C
Digital Temp Sensor Output: ±3°C Accuracy
Alarms: Two times of a day
Battery Backup for continuous timekeeping
Integrating Adafruit RTC Library in Arduino IDE.
- Download Adafruit RTC Library Zip file from below given link
- Go to Sketch > Include library > Add .zip Library
- Select the downloaded zip file
- If the Library is successfully added, Arduino IDE will show “Library added to your libraries. Check Include Library menu” on the status bar.
Learn more information about the RTC Library.
Step 1: Required Components
DS3231 RTC Module x 1
NodeMCU WiFi Module x 1
Step 2: Circuit Time
Make a circuit as per the given diagram. In Real-Time Clock there are eight pins available. We will be using only four pins. Connect the pins as below given.
VCC to 3.3V
GND to Ground
SDA to D2 (GPIO 4)
SCL to D1 (GPIO 5)
Step 3: Code Time
This is code for interfacing DS3231 RTC Module with NodeMCU Module. First, we include the necessary libraries for Real-Time Clock and NodeMCU WiFi. In setup, the Serial Monitor is begun at 115200 Baud and Date-Time is set according to system time if the time of RTC is not set. Also, SSID and Password of your WiFi to connect. In the loop, we fetch current date and time from Real-Time Clock and it is displayed in the serial monitor. To reset Real Time Clock, remove all wires from NodeMCU and also battery from Real Time Clock for 10 seconds. Then reassemble the circuit and upload the program again.
Step 4: Upload the code
Set components as per the Circuit Diagram and upload the code to the NodeMCU. DS3231 Real Time Clock will provide time to NodeMCU and it will display in Serial Monitor.
2 thoughts on “Learn interfacing DS3231 RTC Module with NodeMCU”
For some reason there is a CRLF after the now.Year (while using the above code). This does not happen with other time related things (Like now.Day, Month, etc.) Any help? Thanks.
All the eset,
I foudn the reason:
remove ‘ln’ from this line:
and add nl at this line: