#include <Wire.h>
#include "RTClib.h"

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {

#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero

if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);

if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

void loop () {
DateTime now = rtc.now();

Serial.print(now.year(), DEC);
Serial.print(now.month(), DEC);
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(now.minute(), DEC);
Serial.print(now.second(), DEC);

Serial.print(" since midnight 1/1/1970 = ");
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);

// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));

Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print(future.month(), DEC);
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(future.minute(), DEC);
Serial.print(future.second(), DEC);


enter image description here

If i use 57600 i'll get random symbols in one line 1 line. I have connected PIN5 IN1307N to A4, PIN4 IN1307N to A5

enter image description here

  • What about pull-ups on SDA/SCL? – KIIV Sep 5 '16 at 12:18
  • yup applied. 10k to vcc – antoniomerlin Sep 5 '16 at 12:21
  • Maybe try to use 4k7 (or two 10k in parallel) and shorter wires but it's a wild guess. And you can try I2C scanner if RTC is even found. BTW value 165 is not so random as you think. It's 0xF*10 + 0xF e.g. 0xFF to BCD code. – KIIV Sep 5 '16 at 12:39
  • Scanning... No I2C devices found – antoniomerlin Sep 5 '16 at 12:46
  • Check your wiring: A4 = SDA -> PIN5, A5 = SCL -> PIN6 (PIN4 is GND terminal) – KIIV Sep 5 '16 at 12:56

enter image description here

Following this circuitry solved my issue but still i've not understand the difference between DS1307 and IN1307N.

| improve this answer | |
  • There shouldn't be any difference. Just different factory making the chip. – KIIV Sep 5 '16 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.