Servo control with RTC on Arduino uno

hello, I am trying to control the Servo motor (MG996R) with RTC in my project. While the code works fine at first, it just flickers and doesn't work in later movements. Where is the error in my code? Can you help me? I'm using Arduino uno.

Some of my code it continous like that

#include <Servo.h>

#include <MyRealTimeClock.h>

Servo myservo;

MyRealTimeClock myRTC(6, 7, 8); // Assign Digital Pins

int Hour;

int Min;

int Sec;

void setup() {

Serial.begin(9600);

myservo.attach(9);

myservo.write(0);

/* To set the current time and date in specific format

| Second 00 | Minute 59 | Hour 10 | Day 12 | Month 07 | Year 2015 |

*/

//myRTC.setDS1302Time(00, 30, 07, 02 , 01, 11, 2022);

}

void loop() {

// Allow the update of variables for time / accessing the individual element.

myRTC.updateTime();

////////////////////

Hour = myRTC.hours;

Min = myRTC.minutes;

Sec = myRTC.seconds;

Serial.print("Current Date / Time: ");

Serial.print(myRTC.dayofmonth); // Element 1

Serial.print("/");

Serial.print(myRTC.month); // Element 2

Serial.print("/");

Serial.print(myRTC.year); // Element 3

Serial.print(" ");

Serial.print(myRTC.hours); // Element 4

Serial.print(":");

Serial.print(myRTC.minutes); // Element 5

Serial.print(":");

Serial.println(myRTC.seconds); // Element 6

//Serial.print komutları silinecek testten sonra

if(Hour== 7 && Min== 30 && Sec== 0)

{

myservo.write(0);

delay(5);

}

else if(Hour== 7 && Min== 30 && Sec== 10){

myservo.write(10);

delay(5);

}

else if(Hour== 7 && Min== 30 && Sec== 20){

myservo.write(20);

delay(5);

}

else if(Hour== 7 && Min== 30 && Sec== 30){

myservo.write(95);

delay(5);

}

else if(Hour== 7 && Min== 38 && Sec== 0){

myservo.write(4);

delay(5);

}

else if(Hour== 7 && Min== 38 && Sec== 10){

myservo.write(5);

delay(5);

}

else if(Hour== 7 && Min== 38 && Sec== 20){

myservo.write(6);

delay(5);

}

Step 1
Read
How to get the best out of this forum
And if you don't know what to do next, reread that and focus on the "code problems" section.

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