DS1307 + Coin-Cell RTC

Add a battery-backed real-time clock to any Arduino with two wires and a coin cell, then read date and time over I²C.

Difficulty: Breadboard. Estimated build time: about 30 minutes. Estimated parts cost: about US$5.00. 6-line bill of materials. Compare supplier offers when available. A real-time clock you build by hand on a breadboard, not a pre-soldered module.

Wire the DS1307 DIP

Place the DS1307 in the centre of the breadboard. Connect pin 1 and pin 2 to the 32.768 kHz crystal (no ground; the crystal floats between them). Pin 3 goes to V_BAT (CR2032 +). Pin 4 is GND. Pin 5 is SDA, pin 6 is SCL, both with 4.7 kΩ pull-ups to V_CC. Pin 7 is the optional square-wave output (leave floating). Pin 8 is V_CC = 5 V from the Arduino.

Install RTClib and set the time

Open the Arduino IDE Library Manager, search “RTClib by Adafruit”, install. Open File > Examples > RTClib > ds1307. The first time, uncomment the rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); line so the clock takes the compile time as the initial setting. Upload, watch Serial print the current time, then comment that line out again and re-upload so the clock keeps its own time on every reset.

Remove power and check the backup

Disconnect the Arduino from USB for a few minutes. Reconnect. The clock should report the elapsed time accurately — if it resets, the coin cell is missing or its V_BAT pin is floating. The CR2032 holds the chip alive at less than 500 nA, so a fresh battery lasts close to ten years.

Use the time in a sketch

Any sketch can call rtc.now() to read a DateTime object. Print only if the minute changed, schedule actions for specific hours, or pass the timestamp string to an SD card data logger so each row has a real date instead of millis since boot. Pair with an SSD1306 OLED for a desktop clock.