Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use Adaruit DS3231: Examples, Pinouts, and Specs

Image of Adaruit DS3231Design with Adaruit DS3231 in Cirkit Designer

Introduction

The Adafruit DS3231 is a precision real-time clock (RTC) module that maintains accurate timekeeping even when the main power to the device it's connected to is turned off. Utilizing a temperature-compensated crystal oscillator, the DS3231 provides high stability and accuracy. Common applications include timekeeping in embedded systems, data logging with timestamps, and scheduling in various electronic projects.

Explore Projects Built with Adaruit DS3231

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Arduino UNO with RTC DS3231 Timekeeping: A project utilizing Adaruit DS3231 in a practical application
Arduino UNO with RTC DS3231 Timekeeping

This circuit connects an Arduino UNO microcontroller with a DS3231 Real Time Clock (RTC) module. The Arduino provides 5V power and ground to the RTC and communicates with it via the I2C protocol using the A4 (SDA) and A5 (SCL) pins. The embedded code on the Arduino is used to initialize the RTC, check for power loss, set the current time if needed, and periodically read and print the current time to the serial monitor.

Open Project in Cirkit Designer
Image of Arduino UNO with DS1307 RTC Controlled LED Lighting System: A project utilizing Adaruit DS3231 in a practical application
Arduino UNO with DS1307 RTC Controlled LED Lighting System

This circuit features an Arduino UNO connected to a DS1307 Real Time Clock (RTC) module for timekeeping and a red LED with a series resistor for indication purposes. The Arduino communicates with the RTC via I2C (using A4 and A5 pins for SDA and SCL, respectively), and controls the LED connected to digital pin D8 through a 330-ohm resistor. The embedded code sets the RTC time, checks the current time, and turns the LED on or off based on the specified time condition (between 11:00 AM and 11:43 AM).

Open Project in Cirkit Designer

Technical Specifications

Key Technical Details

Pin Configuration and Descriptions

Pin Number Name Description
1 VCC Power supply (2.3V to 5.5V)
2 GND Ground connection
3 SDA I2C Data line
4 SCL I2C Clock line
5 SQW Square Wave/Interrupt output
6 32K 32kHz Output
7 RST Reset input (active low)

Usage Instructions

Integrating with a Circuit

  1. Power Connections: Connect VCC to a 2.3V to 5.5V power supply and GND to the ground.
  2. I2C Connections: Connect SDA and SCL to your microcontroller's I2C data and clock lines respectively. For Arduino UNO, SDA is A4 and SCL is A5.
  3. Battery Backup: Insert a CR2032 coin cell battery to keep the RTC running when main power is lost.
  4. Square Wave/Interrupts: Optionally, use the SQW pin for generating square waves or as an interrupt signal.
  5. 32kHz Output: Optionally, use the 32K pin if a 32kHz reference signal is required.

Important Considerations and Best Practices

Example Code for Arduino UNO

#include <Wire.h>
#include <RTClib.h>

RTC_DS3231 rtc;

void setup() {
  Serial.begin(9600);
  
  // Check if the RTC is connected correctly
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  // Check if the RTC lost power and if so, set the time
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, setting the time!");
    // The following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {
  DateTime now = rtc.now();
  
  // Print the current date and time
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
  
  // Wait for a second
  delay(1000);
}

Troubleshooting and FAQs

Common Issues

Solutions and Tips for Troubleshooting

FAQs

Q: How do I set the time on the DS3231? A: The time can be set using the rtc.adjust(DateTime(...)); function in the Arduino sketch.

Q: Can the DS3231 be used in low-power applications? A: Yes, the DS3231 has a very low power consumption, especially when running off the backup battery.

Q: What is the purpose of the 32K pin? A: The 32K pin outputs a 32kHz square wave that can be used as a clock reference for other devices.