rtc ds3231 problem [with fritzing diagram and code]

Hi, I am beginner in arduino and I am trying to do alarm clock using arduino. However I do not able to get rtc time. LCD is working fine as it display the print command in void setup(). My main reference for this program is here

I use i2c lcd like here which is not available in fritzing, so I just insert note where the wire is connected to lcd pin.

Fritzing diagram

#include <DS3231.h>

#include <Wire.h>



#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F ,2,1,0,4,5,6,7,3, POSITIVE);

DS3231  rtc(SDA, SCL);

Time  t;

#define buz 11

int Hor;

int Min;

int Sec;




void setup()

{  

  Wire.begin();

  rtc.begin();

  Serial.begin(9600);

  pinMode(buz, OUTPUT);

  lcd.begin(16,2);     

  lcd.setCursor(0,0);

  lcd.print("DIYHacking.com");

  lcd.setCursor(0,1);

  lcd.print("Hisap gam ");

  // The following lines can be uncommented to set the date and time

  rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY

  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)

  rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014

  

  delay(2000);

}




void loop()

{

  t = rtc.getTime();

  Hor = t.hour;

  Min = t.min;

  Sec = t.sec;

  lcd.setCursor(0,0);

  lcd.print("Time: ");

  lcd.print(rtc.getTimeStr());

 lcd.setCursor(0,1);

 lcd.print("Date: ");

 lcd.print(rtc.getDateStr());




 if( Hor == 11 &&  (Min == 32 || Min == 33)) //Comparing the current time with the Alarm time

{

Buzzer();

Buzzer();

lcd.clear();

lcd.print("Alarm ON");

lcd.setCursor(0,1);

lcd.print("Alarming");

Buzzer();

Buzzer();

} 

 delay(1000); 

}




void Buzzer()

{

digitalWrite(buz,HIGH);

delay(500);

digitalWrite(buz, LOW);

delay(500);

}

Have you tried any of the examples that come with that RTC library? Were you successful with the example code? Have you ran the I2C scanner to see if the RTC's I2C address is right and the RTC is communicating via the I2C bus?

// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
  Serial.begin (115200); //*****  make sure serial monitor baud matches *****

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

groundFungus:
Have you tried any of the examples that come with that RTC library? Were you successful with the example code? Have you ran the I2C scanner to see if the RTC's I2C address is right and the RTC is communicating via the I2C bus?

// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
  Serial.begin (115200); //*****  make sure serial monitor baud matches *****

// Leonardo: wait for serial port to connect
  while (!Serial)
    {
    }

Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
 
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

I have run this code and got this as output.

I2C scanner. Scanning ...
Found address: 63 (0x3F)
Done.
Found 1 device(s).

Your RTC is I2C also, right?
Your scan returned 3F, which is the address you are using for your LCD display.
Can you remove the LCD and run the scan again? I would like to see what address it finds for the RTC.

Maybe 68, if it is the adafruit version.

I have never used 2 I2C devices at the same time. Does the scan program detect them all if you have many?

The I2C scanner will detect all devices on the bus. Max that I have had is 5 and all were reported in one scan.

vinceherman:
Your RTC is I2C also, right?
Your scan returned 3F, which is the address you are using for your LCD display.
Can you remove the LCD and run the scan again? I would like to see what address it finds for the RTC.

Maybe 68, if it is the adafruit version.

I have never used 2 I2C devices at the same time. Does the scan program detect them all if you have many?

I have removed the LCD and this is the output of the serial monitor.

Ievice(s).

I2C scanner. Scanning ...
Done.
Found 0 device(s).

Found 0 device(s).

Then the device is probably not connected/configured properly. I have no experience with those parts so can be of little help except to say to carefully check connections. Is the chip on a module? Which module, if so?

That fritzing diagram is useless. Wire just the rtc module, four wires total needed. If the i2c scanner doesn't see the module, recheck the wiring. If the is any doubt, use the terminals on the upper left side of the Uno marked SCK and SDA rather than A4 and A5 which are same pins but not marked as to the i2c functionality.

Once the scanner sees the ds3231, the rtc should work.