RTC not working with interrupts

I'm following this tutorial online

My RTC clock works with the settime and readtest example sketches but i Can't get the interrupt example below to work

i can scrawl together a schematic later but i have the following pin coinnections to my uno

SDa - A5
SCL - A4
VCC - 5 volts
GRN - ground
SQW - D2

at this point i'd just welcome guidance on what to trouble shoot. The blink sketch works on the board. I've tested wires and even ran an I2C scanner to check the address

Thanks in advance

EDITED TO ADD , The LED Doesn't blink!!!

   Arduino DS1307 Set SQW Interrupt
   v. 1.0
   Copyright (C) 2017 Robert Ulbricht

   Set Square Wave Output 1Hz.
   Blink with internal LED using interrupt.

   IDE: 1.8.3 or higher
   Board: Arduino Uno, Arduino Pro Mini, Arduino Mega 2560

   Libraries: none

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <Wire.h>

#define DS1307_CTRL_ID 0x68
#define ledPin LED_BUILTIN

void setSQW(uint8_t value) {

void handleInt() {
  digitalWrite(ledPin, digitalRead(ledPin) ^ 1);

void setup() {
  while (!Serial) ; // wait for serial
  Serial.println("DS1307RTC Set SQW 1 Hz");
  Serial.println("Attach interrupt on D2");


  // D2 on Arduino Uno
  // D2 on Arduino Mega 2560

  // 1Hz

void loop() {

Try adding this to your setup.
pinMode(2, INPUT_PULLUP)
If you still get no output, try a stronger external pullup on D2.

Thank you. I will try that momentarily.
Possible stupid question….. by try a stronger external pull-up …I know you mean a resistor but where would it go? Between D2 and my 5v line?

Yes. Something like 4.7K or 2.2K.

Does your multimeter confirm that you have a 1Hz square wave coming in on D2?

Have not tried that yet….will let you know the results

Are you using an UNO, Nano, Mini, or MEGA? If you use a Leonardo/Micro the interrupt numbers on Pin 2 and Pin 3 are swapped.

You should ALWAYS use 'digitalPinToInterrupt()' with attachInterrupt():

attachInterrupt(digitalPinToInterrupt(2), handleInt, FALLING);

really? On the Uno, however, the I2C pins are assigned as follows:
A4 = SDA
A5 = SCL

A4 is SDA

I’m away from home at moment but yes I will definitely check I have the pins the right way round . Thanks for spotting that

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.