Having trouble using the DS3231.h library

I am trying to replicate an Arduino Uno based alarm clock that I found at the following website https://diyhacking.com/arduino-alarm-clock-using-real-time-clock-lcd-screen/.

I tried running the following code:

#include <DS3231.h>

#include <Wire.h>

#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

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("Arduino Alarm ");

  // 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);

}

When I run this, I see the following error:

sketch_oct29c:9: error: no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'

DS3231 rtc(SDA, SCL);

I have installed the D23231 library and am not sure what I can do to solve this issue. Does anybody know of a fix for this?

Cheers

Look at the examples that are included with the DS3231 library. The constructor for the class does not take any arguments.

Maybe you can try :

DS3231  rtc(A4, A5);

Or,

DS3231  rtc(27, 28);

See if it can help.

Dear Arduino community

I'm a beginner Arduino user and am attempting to replicate a 24-hour alarm clock demonstrated in a tutorial found at: https://diyhacking.com/arduino-alarm-clock-using-real-time-clock-lcd-screen/.

I downloaded all the most updated libraries associated with the DS3231 Real Time Clock module.

When I attempt to run the following program (I am not the author of this code, as it is directly taken from the page I linked above), I am met with an error that seems to be a result of missing a key library.

Can anyone tell me which libraries I need to install to eliminate the error?

#include <DS3231.h>

 #include <Wire.h>

 #include <LiquidCrystal.h>

 LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

 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("Arduino Alarm ");


     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);

       }

The error returned when I compile and run this program is as follows:

sketch_oct29c:17: error: no matching function for call to 
'DS3231::DS3231(const uint8_t&, const uint8_t&)'

 DS3231  rtc(SDA, SCL);

                 ^

Cheers!

Please post a link to the ds3231 library that you downloaded. There might be more than one of them and you might have picked the wrong one :wink:

The error indicates that the specific constructor does not expect arguments.

You can try

DS3231  rtc();

It should get rid of the error, but if you have the wrong library, you might get other errors.

sketch_oct29c:17: error: no matching function for call to 
'DS3231::DS3231(const uint8_t&, const uint8_t&)'

 DS3231  rtc(SDA, SCL);

                 ^

That syntax is found in the Rinky Dink Electronics library.

http://www.rinkydinkelectronics.com/library.php?id=73

That library does not use the standard i2c library (Wire.h).

I would recommend either the rtcLib.h which is available through the library manager or the Jack Christensen DS3232.h which works for the ds3231 and integrates well with the time library.

Thanks for the suggestions.

The following libraries I had installed previously: DS3231, MD_DS3231, Rtc_by_Makuna, RTClib, RTCtime

Will the DS3232RTC library only perform properly if I delete the libraries that I mentioned above?

@adesmond, do not cross-post. Threads merged.

sterretje:
You can try

DS3231  rtc();

I think that's a prototype for a function that takes no arguments and returns a value of type DS3231. Pretty sure it should be:

DS3231  rtc;

OP:
Two items from previous replies that you have not addressed:

  • Exactly how did you install the DS3231 library? Directly in IDE using Library Manager? Downloaded as .zip file? If so, post (clickable) link to download page and let us know where you put the files on your computer.

  • Did the library you installed include any examples? If so, did you look at them? If so, did any of them include arguments with the constructor for the DS3231 class?

You're using RinkyDink electronics's version of DS3231,
Go to their website and get their DS3231 library. It works.

http://www.rinkydinkelectronics.com/library.php?id=73

1 Like

Zetophee:
...
...

I certainly hope that OP did not have to wait one-and-a-half year to solve the problem :wink: