Arduino RTClib DS1307 Clock: Wiring, Code and Simulator

To build this Arduino RTClib DS1307 Clock project you need an Arduino Uno and a DS1307 RTC module. Adafruit RTClib sets a DS1307 once, then reads the date and time back every second. Make the 4 connections in the wiring table, upload the Arduino C++ code, and change the date in rtc.adjust(), or print now.dayOfTheWeek().

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1DS1307 RTC moduleReal-time clock on I²C at 0x68: seven BCD registers from 0x00 (seconds, minutes, hours, day, date, month, year). SDA/SCL to the I²C pins, 5V, GND.

Wiring

#FromTo
1Arduino Uno GNDDS1307 RTC module GND
2Arduino Uno 5VDS1307 RTC module 5V
3Arduino Uno A4DS1307 RTC module SDA
4Arduino Uno A5DS1307 RTC module SCL

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add a DS1307 RTC module from the parts palette.
  3. Wire 1. Connect Arduino Uno GND to DS1307 RTC module GND.
  4. Wire 2. Connect Arduino Uno 5V to DS1307 RTC module 5V.
  5. Wire 3. Connect Arduino Uno A4 to DS1307 RTC module SDA.
  6. Wire 4. Connect Arduino Uno A5 to DS1307 RTC module SCL.
  7. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  8. Run it. Press Run. Change the date in rtc.adjust(), or print now.dayOfTheWeek().

Arduino C++ code

// RTClib: the Adafruit real-time-clock library, talking to a DS1307 over I2C.
// rtc.adjust() sets the clock once; rtc.now() reads it back as a DateTime.
#include <RTClib.h>

RTC_DS1307 rtc;

void setup() {
  Serial.begin(9600);
  if (!rtc.begin()) {
    Serial.println("DS1307 not found. Check SDA (A4) and SCL (A5).");
    while (true) {}
  }
  rtc.adjust(DateTime(2026, 9, 29, 12, 34, 56));
  Serial.println("Clock set.");
}

void loop() {
  DateTime now = rtc.now();
  char line[24];
  snprintf(line, sizeof line, "%04d-%02d-%02d %02d:%02d:%02d",
           now.year(), now.month(), now.day(), now.hour(), now.minute(), now.second());
  Serial.println(line);
  delay(1000);
}

What to try

Change the date in rtc.adjust(), or print now.dayOfTheWeek().

Frequently asked questions

How do I wire the RTClib DS1307 Clock project on an Arduino Uno?

Make 4 connections: Arduino Uno GND to DS1307 RTC module GND; Arduino Uno 5V to DS1307 RTC module 5V; Arduino Uno A4 to DS1307 RTC module SDA; Arduino Uno A5 to DS1307 RTC module SCL.

What parts do I need for this Arduino project?

An Arduino Uno and a DS1307 RTC module.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

Adafruit RTClib sets a DS1307 once, then reads the date and time back every second.

More Arduino Uno projects