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
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | DS1307 RTC module | Real-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
| # | From | To |
|---|---|---|
| 1 | Arduino Uno GND | DS1307 RTC module GND |
| 2 | Arduino Uno 5V | DS1307 RTC module 5V |
| 3 | Arduino Uno A4 | DS1307 RTC module SDA |
| 4 | Arduino Uno A5 | DS1307 RTC module SCL |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add a DS1307 RTC module from the parts palette.
- Wire 1. Connect Arduino Uno GND to DS1307 RTC module GND.
- Wire 2. Connect Arduino Uno 5V to DS1307 RTC module 5V.
- Wire 3. Connect Arduino Uno A4 to DS1307 RTC module SDA.
- Wire 4. Connect Arduino Uno A5 to DS1307 RTC module SCL.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- 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
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator