DS3231 RTC with an ESP32 DevKit V1
The DS3231 is an I2C real-time clock whose integrated temperature-compensated crystal oscillator (TCXO) holds time to ±2 ppm, about a minute a year, between 0 and 40 °C.

The DS3231 module runs from the ESP32 DevKit V1's 3V3, inside its 2.3 V to 5.5 V range, and answers at its fixed address 0x68 on GPIO21 (SDA) and GPIO22 (SCL). On a networked ESP32 it keeps the time through resets and Wi-Fi outages, with its coin cell holding the clock when the board is off.
Wiring the DS3231 RTC to the ESP32 DevKit V1
Pin by pin.
| DS3231 RTC | ESP32 DevKit V1 |
|---|---|
| VCC | 3V3 |
| GND | GND |
| SCL | GPIO22 (D22) |
| SDA | GPIO21 (D21) |
What to know on the ESP32 DevKit V1
- The sketch sets the clock from the compile time after a power loss. On an ESP32 you can set it from NTP over Wi-Fi instead and let the DS3231 carry the time while the network is down; it holds ±2 ppm from 0 to 40 °C.Analog Devices DS3231 datasheet 19-5170 rev 10, p. 1
- To wake a sleeping ESP32 on an alarm, wire SQW/INT to an RTC GPIO such as GPIO33 (RTC_GPIO8); RTC GPIOs can wake the chip from deep sleep. SQW is open drain, so it needs a pull-up to 3V3.Espressif ESP32 Series Datasheet v5.3, p. 14; Espressif ESP32 Series Datasheet v5.3, p. 61; Analog Devices DS3231 datasheet 19-5170 rev 10, p. 9
- Do not put SQW on GPIO34 to GPIO39 and rely on INPUT_PULLUP: those pins have no internal pull resistors, so add an external pull-up there.Espressif ESP32 Series Datasheet v5.3, p. 61
DS3231 RTC code for the ESP32 DevKit V1
Compiled for esp32:esp32:esp32 on 2026-10-30.
// DS3231 RTC on ESP32 DevKit V1: wiring and a free simulation at https://www.tinkered.ai/components/ds3231-rtc/esp32
#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);
}
DS3231 RTC on the ESP32 DevKit V1: questions
Does the DS3231 work at 3.3 V on the ESP32?
Yes. VCC takes 2.3 V to 5.5 V, 3.3 V typical (Analog Devices datasheet, p. 2), and powered from 3V3 its module pull-ups keep SDA and SCL at 3.3 V.
Can I use two DS3231 modules on one ESP32?
Not on one bus: the address is fixed at 0x68 (Analog Devices datasheet, p. 16). The ESP32 has a second I2C controller (ESP32 datasheet, p. 4), so the second module can go on Wire1 with its own pins.
Why use a DS3231 when the ESP32 can get the time over Wi-Fi?
NTP needs a network at every boot. The DS3231 keeps time with no network and with the board unpowered, on its backup cell at 3.0 µA maximum (Analog Devices datasheet, p. 3).
Keep going
This guide as plain Markdown. /components/ds3231-rtc/esp32.md