Moving servo with RTC DS3231.

#include <DS3231.h>
#include <Servo.h>
// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);
Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0;    // variable to store the servo position

void setup()
{
  // Setup Serial connection
  Serial.begin(115200);
  
  // Initialize the rtc object
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  //rtc.setDOW(SUNDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(20, 1, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(12, 12, 2019);   // Set the date to January 1st, 2014
    myservo.attach(12);  // attaches the servo on pin 9 to the servo object

}

void loop()
{
  clock();

}

void clock()
{
// 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 :)
  delay (1000);

  String(rtc.getTimeStr());
  if(String(rtc.getTimeStr()) == "21,20,30")
 {
  Serial.print("Hello it is time to move");
    myservo.write(0);             
    delay(30);                       
    myservo.write(140);              
    delay(30);                   
  myservo.detach();
 }
}

Wtf? Do you have a question? We can't read minds here

So what does the code do? Did you want it to do something different?

You might also want to say what DS3231 library you're using because it's not the one I have so your code won't even compile here.

BTW that must be a really fast servo if you expect it to get to 0 and then to 140 in only 30 milliseconds.

Steve

You seem to have removed the actual question from your post with some of your editing.

Just a couple of quick thought:

Is the literal string formatted correctly?

if(String(rtc.getTimeStr()) == "21,20,30")

Also, it is very bad to be making a comparison to a time down to the specific second when you have numerous delay() statements in your code, you are very likely to miss that specific time.

Why are you detaching the servo? Servos need a continuous signal in order to hold their position, they tend to drift or jitter a bit when not receiving any signal.