Source: https://mokxi.com/parts/ds3231
Updated: 2026-11-10

Part

# Real-time clock, DS3231

A clock that keeps time whatever the sketch is doing. Every register is BCD, which catches everybody.

See every part

- 6 pins
- 2 settings
- In 8 projects
- In 3 lessons

Drawn live by the editor's own code, at the size you see it.

At a glance

## The Real-time clock, DS3231 in brief

What it is, and every setting the properties panel gives it.

The DS3231 is the real-time clock on the blue ZS-042 module, with a temperature-compensated crystal that drifts minutes a year where a DS1307 drifts minutes a month. It sits on I2C at 0x68, fixed, with pull-ups on the module: SDA and SCL to A4 and A5 on an Uno, or 21 and 22 on an ESP32, at 2.3 to 5.5 volts. Mokxi models the register map. Every time register is binary coded decimal, so 25 seconds reads as 0x25, and bit 6 of the hours register selects 12-hour mode with bit 5 as PM, so a driver that masks with 0x3F instead of 0x1F reads 3 pm as 23. The calendar knows month lengths and leap years, both alarms have the datasheet’s full mask table, and SQW is either the active-low alarm output or a square wave at 1 Hz, 1.024, 4.096 or 8.192 kHz. The start property sets the time, and the temperature property reads back in quarter degrees. OSF comes up set, which is what RTClib’s lostPower() checks. The coin cell, the 32 kHz output and the drift itself are not modeled.

Family

Clocks and links

Pins

6

start

2026-01-01 12:00:00

temperature

25

Pins

## 6 pins

Named as the editor names them, so a wire lands where you expect it.

- 32K
- SQW
- SCL
- SDA
- VCC
- GND

How to use it

## How to use a DS3231 real-time clock with an Arduino

SDA to A4, SCL to A5, VCC to 5 V and GND to GND; the module has its own pull-ups. With RTClib, create an RTC_DS3231, call begin(), and read the time with now(), which hands back a DateTime with year(), month(), hour() and the rest already converted from BCD.

Read all seven time registers in one transfer, as RTClib and the desk clock both do: reading them one at a time lets the clock tick between minutes and seconds. lostPower() is true at power-up here, and calling adjust() then replaces the time the start property set.

Part pin

Board pin

SDA

A4

SCL

A5

VCC

5 V

GND

GND

RTClib uses Wire, so on an ESP32 the clock goes on GPIO 21 and 22.

Click to open it in the editor

This is the simulator itself, running here. Click anything to open it in the editor.

Open this project in the editor Read the full tutorial

Reading the time with RTClib

How it is modeled

## What is true about the Real-time clock, DS3231, here

In its help article’s own words: what the simulation gets right, and where it stops.

### The DS3231, and BCD

A temperature-compensated crystal oscillator, which is why it is the clock
everybody ends up buying: a DS1307 drifts minutes a month and this one drifts
about that much a year. Address 0x68, fixed. There is no address pin.

Everything in it is binary coded decimal. Each byte holds two decimal
digits, one per nibble, so twenty-five seconds is 0x25 and not 25:

Forget it and 37 minutes past shows as 55. It is the one thing everybody gets
wrong once.

The other trap is the hours register. Bit 6 is the 12-hour flag, and with it set
bits 4:0 are 1 to 12 and bit 5 is PM, so 3 pm is 0x63, and a driver that
masks with 0x3f instead of 0x1f reads it as 23.

The part keeps a real calendar with leap years, both alarms with the whole of
the datasheet's mask table, and SQW as either the alarm output or a square
wave at 1 Hz, 1.024 kHz, 4.096 kHz or 8.192 kHz. OSF (bit 7 of the status
register) comes up set and means "this time cannot be trusted", which on a real
bench is how you find out somebody's coin cell is flat. The start property is
the time it starts at (2026-01-01 12:00:00 by default) and temperature is
what its temperature register reads.

Two things are not modeled and are said plainly here: the 32 kHz output,
because generating it would be 65,536 edges a simulated second for something
nothing in the parts bin can use; and the battery, so a part that loses
VCC loses the time where a real module keeps it.

### Not modeled

Clock stretching, which none of these three chips does anyway. Arbitration
between two masters. Ten-bit addressing. And the rate: the parts decode the bus
from its edges and impose no timing of their own, so a driver that is too fast
works here where a real device would not answer.

Arduino I2C LCD not working uses a scanner and Wire.endTransmission() to tell a wiring fault from a wrong address.

The tutorial Arduino TM1637 walks through Pomodoro timer: TM1637Display, the colon, leading zeros and a countdown timed with millis().

From Two wires, several chips, in full.

Projects

## See the Real-time clock, DS3231 in a project

8 built-in projects use it. Each opens in the editor, already wired.

Lessons

## Where it turns up in a lesson

3 lessons place it in their own circuits.

### Learn articles

3 lessons

- Arduino DS3231 Clock With a TM1637 Display
- I2C Explained: Addresses, Acknowledges and Pull-Ups
- Arduino GC9A01: Round Display Library and Example

Boards

## The boards it is shown on

Each of these 2 boards has a built-in project with the Real-time clock, DS3231 in it.

- Arduino Uno R3
- ESP32-C3-DevKitM-1

Boards

## The Real-time clock, DS3231 on each board

The pins, the voltage and the code change from board to board. Each page has that board’s wiring and a circuit you can run.

- Arduino Uno and DS3231 RTC
- ESP32 and DS3231 RTC
- Arduino Nano and DS3231 RTC

Libraries

## Arduino libraries for the Real-time clock, DS3231

Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.

- RTClib
- DS1307RTC
- DS3231 (NorthernWidget) and DS3231 (Rinky-Dink Electronics)

More parts

## The rest of the bench

Every one of these is drawn and simulated the same way.

Full-size breadboard

A real 0.1 inch grid with the rails and the center channel, 63 columns wide.

Jumper wires

Drag from any pin or hole to any other. Corners snap, and you can drag them.

Power

A supply rail at the voltage you choose.

Ground

The other end of every circuit.

LED

Lights when current flows. Five colors, and the brightness is what your eye would see.

Filament lamp

A tungsten bulb in a holder: an inrush when it is switched on cold, tens of milliseconds to warm up, and dim on half its voltage.

Resistor

Any value you like, with the color bands drawn to match.

ESP32-C3-DevKitM-1

A RISC-V board that runs your firmware at 160 MHz on the real memory map.

Pushbutton

A 12 mm tactile switch. Hold it while the simulation runs.

Raspberry Pi Pico

The RP2040 board on our own Cortex-M0+ core. Pick a program and press Run.

Raspberry Pi Pico W

Raspberry Pi Pico W (RP2040). The same board and the same pinout as a Pico, with the CYW43439 on it. The WiFi is simulated (no radio; real internet through the Cloud panel’s switch), and the on-board LED, which hangs off that chip rather than off GP25, is driven through the same path. Everything else is the Pico.

Raspberry Pi 4 Model B

Raspberry Pi 4 Model B: the 40-pin header, driven by main.py with RPi.GPIO or gpiozero.

See every part

## Wire up the Real-time clock, DS3231

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.

Start building free Open the editor
