1

I am trying to make a program that runs when it gets to five in the afternoon, so 17:00:00.

I am using this DS3231 library, but I can't figure out a way to get it to send "Woooopp" to the serial monitor at the specified time.

On the DS3231, the pin labeled SCL is connected to A5 on the Arduino and the pin labeled SDA is connected to A4 on the Arduino.

SCL -> A5 SDA -> A4

My code:

#include <DS3231.h>

// Init the DS3231 using the hardware interface
DS3231  rtc (SDA, SCL);

void setup() {
  // Setup Serial connection
  Serial.begin(115200);
  // Uncomment the next line if you are using an Arduino Leonardo
  //while (!Serial) {}

  // Initialize the rtc object
  rtc.begin();

  // The following lines can be uncommented to set the date and time
  // rtc.setDOW(SATURDAY);     // Set Day-of-Week to SUNDAY
  // rtc.setTime(19, 48, 50);     // Set the time to 12:00:00 (24hr format)
  // rtc.setDate(3, 6, 2017);   // Set the date to January 1st, 2014
}

void loop() {
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");

  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());

  // Wait one second before repeating :)

  if (rtc.getTimeStr() == "19:58:12") {
    Serial.println("Woooopp");
  }
  delay (1000);
}

No errors are thrown, however, the code simply does not work.

Any help would be greatly appreciated!

9
  • Which RTC library do you use ? It seems to be this one: rinkydinkelectronics.com/library.php?id=73
    – Jot
    Jun 3, 2017 at 20:26
  • Yes, I used that one. Sorry I forgot to link it, I will edit the question now.
    – Wisaacj
    Jun 3, 2017 at 20:27
  • Try using a shorter delay. All the other stuff also takes time to run, so you are checking slightly less than once per second. So certain seconds will be skipped.
    – Gerben
    Jun 3, 2017 at 20:57
  • Thanks for your answer, I tried that and it worked along with me also declaring the time in a variable beforehand and then comparing that instead. Have a great day!
    – Wisaacj
    Jun 3, 2017 at 21:44
  • When you look at the serial output, is the string you are getting from getTimeStr the same as what you expect?
    – Delta_G
    Jun 3, 2017 at 21:54

1 Answer 1

-1

How to get code to respond to a certain time from the DS3231 RTC?

the easiest is to set up the alarm in rtc.

alternatively, keep reading the rtc until the desired time has passed. not terribly efficient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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