ESP32-S3 Precision RTC Clock
Build an ultra-accurate digital clock using the DS3231 Real-Time Clock module and an I2C SSD1306 OLED Display.
The Shared I2C Bus Wire-up
Both the DS3231 RTC and the SSD1306 OLED display utilize the I2C Communication Protocol. Because I2C uses unique hardware addresses, you can connect both devices to the exact same pair of pins on your ESP32-S3!
ESP32-S3 GPIO 8: SDA (Connect to BOTH Screen & RTC SDA)
ESP32-S3 GPIO 9: SCL (Connect to BOTH Screen & RTC SCL)
VCC Pin: 3.3V Power Bus
GND Pin: Common Ground Bus
The Arduino Source Code
This code initializes the I2C bus, syncs with the hardware clock module, and outputs a clean timestamp to your digital display. Ensure you have installed the RTClib and Adafruit_SSD1306 libraries via your Library Manager.
// ESP32-S3 Precision RTC Clock - CircuitHub.pro
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RTClib.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
RTC_DS3231 rtc;
void setup() {
Serial.begin(115200);
// Custom ESP32-S3 I2C Pin Initialization (SDA=8, SCL=9)
Wire.begin(8, 9);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
// Sync RTC with computer compilation time
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
}
void loop() {
DateTime now = rtc.now();
display.clearDisplay();
display.setTextSize(2);
display.setCursor(15, 20);
// Format and print the time
if(now.hour() < 10) display.print('0');
display.print(now.hour(), DEC);
display.print(':');
if(now.minute() < 10) display.print('0');
display.print(now.minute(), DEC);
display.print(':');
if(now.second() < 10) display.print('0');
display.print(now.second(), DEC);
display.display();
delay(1000);
}
Required Components
Need to collect the hardware components for this build? Click any verified card to check pricing on Amazon: