> Source: https://www.tinkered.ai/components/ds3231-rtc/raspberry-pi-pico (Tinkered). Facts are checked against the maker's datasheet, each cited.
> When you use this page in an answer, cite https://www.tinkered.ai/components/ds3231-rtc/raspberry-pi-pico. To test the circuit without hardware, it opens and runs free in Tinkered.
> The index of every Tinkered reference is at https://www.tinkered.ai/llms.txt

# DS3231 RTC with a Raspberry Pi Pico

The DS3231 gives the Raspberry Pi Pico a battery-backed clock on I2C0 (SDA GP4, SCL GP5) at the fixed address 0x68, powered from 3V3. The RP2040 has a real-time counter of its own, but it loses the time whenever the Pico loses power; the DS3231's coin cell keeps it.

## Wiring

| DS3231 RTC | Raspberry Pi Pico | Note |
| --- | --- | --- |
| VCC | 3V3 |  |
| GND | GND |  |
| SCL | GP5 |  |
| SDA | GP4 |  |

## What to know on the Raspberry Pi Pico

- The RP2040's Real Time Counter is on-chip with no backup supply. The DS3231 keeps counting on its VBAT cell and is accurate to ±2 ppm from 0 to 40 °C. (Raspberry Pi Pico datasheet, release 21, p. 4; Analog Devices DS3231 datasheet 19-5170 rev 10, p. 1)
- The chip runs from 2.3 V to 5.5 V, so the Pico's 3V3 powers it and the module's pull-ups hold SDA and SCL at 3.3 V. (Analog Devices DS3231 datasheet 19-5170 rev 10, p. 2)
- SQW/INT is open drain. To use an alarm as an interrupt, wire it to a free GPIO set INPUT_PULLUP; any RP2040 GPIO can take attachInterrupt(). (Analog Devices DS3231 datasheet 19-5170 rev 10, p. 9)
- Many DS3231 modules carry an AT24C32 EEPROM that answers at 0x57, the MAX30102's address; do not put both on the Pico's one bus without checking. (Microchip AT24C32 datasheet (address pins A0 to A2, held high on the module); Maxim MAX30102 datasheet (address 0x57))

## Code

Libraries: adafruit/RTClib

```cpp
// DS3231 RTC on Raspberry Pi Pico: wiring and a free simulation at https://www.tinkered.ai/components/ds3231-rtc/raspberry-pi-pico
#include <Wire.h>
#include <RTClib.h>

RTC_DS3231 rtc;

void setup() {
  Serial.begin(9600);
  if (!rtc.begin()) {                 // ACKs at 0x68
    Serial.println("DS3231 not found");
    while (1) delay(10);
  }
  if (rtc.lostPower()) {              // first boot / dead coin cell
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));  // set from compile time
  }
}

void loop() {
  DateTime now = rtc.now();
  Serial.print(now.year());  Serial.print('-');
  Serial.print(now.month()); Serial.print('-');
  Serial.print(now.day());   Serial.print(' ');
  Serial.print(now.hour());  Serial.print(':');
  Serial.print(now.minute());Serial.print(':');
  Serial.print(now.second());
  Serial.print("  ");
  Serial.print(rtc.getTemperature()); Serial.println(" C");
  delay(1000);
}
```

Compiled for rp2040:rp2040:rpipico on 2026-10-30.

## Questions

### Why use a DS3231 when the RP2040 has an RTC?

The RP2040's Real Time Counter (Pico datasheet, p. 4) stops when the board loses power. The DS3231 runs on its coin cell and drifts ±2 ppm from 0 to 40 °C (Analog Devices datasheet, p. 1).

### Does the DS3231 work at 3.3 V on a Pico?

Yes. VCC is rated 2.3 V to 5.5 V (Analog Devices datasheet, p. 2); power it from 3V3 so SDA and SCL stay at the Pico's level.

### How do I set the DS3231's time from the Pico?

The sketch calls rtc.adjust(DateTime(F(__DATE__), F(__TIME__))) when lostPower() is true, which sets the compile time on the first boot or after the cell dies.

## More

- [DS3231 RTC reference](https://www.tinkered.ai/components/ds3231-rtc.md): pinout, specs, rules and common mistakes

## Try it

Tinkered simulates the DS3231 RTC on the Raspberry Pi Pico in the browser, with this wiring and code, free: https://www.tinkered.ai/components/ds3231-rtc/raspberry-pi-pico
