user68817: #include <DS1302.h>
#include <Servo.h>
Time t;
Servo myservo;
int Hour;
int Min;
int Sec;
// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
myservo.attach(9); 
myservo.write(45); 
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
Serial.begin(9200);
// The following lines can be commented out to use the values already stored in the DS1302
//rtc.setDOW(SUNDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(8, 59, 50); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(8, 25, 2019); // Set the date to August 25th, 2019
}

void loop()
{
t = rtc.getTime();
Hour = t.hour;
Min = t.min;
Sec = t.sec;
 Serial.print(Hour);
 Serial.print(":");
 Serial.print(Min);
 Serial.print(":");
 Serial.println(Sec);

//set the time for fish feeding 
if ((Hour== 2 && Min== 0 && Sec== 2)||(Hour== 21 && Min== 0 && Sec== 2)) {
myservo.write(0);
delay (300);
myservo.write(45);
delay (300);}
}


user31668: Explanation about the multiple time execution
if ((Hour== 9 && Min== 14)||(Hour== 21 && Min== 0)) {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
 }


Assume the time is 9:14:00 (9 hours, 14 minutes, 00 seconds).. the if condition passes.

The for loop will get executed. The duration needed to complete the loop is roughly 5 seconds.

Later, it will again go to the if condition. The time will be now 9:14:06.. it means, the condition will pass again.. the motor will again rotate.. this will repeat for about 11 times.. until the time changes to 9:15:00 or more.

So the solution is to give a delay, before exiting the if loop if you wait for a minute with
delay(60000);


then, the next 'if' condition will fail and works as per your expectation.

Part 2:
debugging:
        if ((Hour== 9 && Min== 14)||(Hour== 21 && Min== 0)) {
          for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
            // in steps of 1 degree
            myservo.write(pos);              // tell servo to go to position in variable 'pos'
            delay(15);
            Serial.println("moving");
    ....



68817: <pre><code>#include &lt;DS1302.h&gt;
#include &lt;Servo.h&gt;
Time t;
Servo myservo;
int Hour;
int Min;
int Sec;
// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
myservo.attach(9); 
myservo.write(45); 
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
Serial.begin(9200);
// The following lines can be commented out to use the values already stored in the DS1302
//rtc.setDOW(SUNDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(8, 59, 50); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(8, 25, 2019); // Set the date to August 25th, 2019
}

void loop()
{
t = rtc.getTime();
Hour = t.hour;
Min = t.min;
Sec = t.sec;
 Serial.print(Hour);
 Serial.print(&quot;:&quot;);
 Serial.print(Min);
 Serial.print(&quot;:&quot;);
 Serial.println(Sec);

//set the time for fish feeding 
if ((Hour== 2 &amp;&amp; Min== 0 &amp;&amp; Sec== 2)||(Hour== 21 &amp;&amp; Min== 0 &amp;&amp; Sec== 2)) {
myservo.write(0);
delay (300);
myservo.write(45);
delay (300);}
}
</code></pre>
 31668: <p><strong>Explanation about the multiple time execution</strong></p>
<pre><code>if ((Hour== 9 &amp;&amp; Min== 14)||(Hour== 21 &amp;&amp; Min== 0)) {
  for (pos = 0; pos &lt;= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos &gt;= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
 }
</code></pre>
<ol>
<li><p>Assume the time is 9:14:00 (9 hours, 14 minutes, 00 seconds).. the <code>if</code> condition passes.</p>
</li>
<li><p>The for loop will get executed. The duration needed to complete the loop is roughly 5 seconds.</p>
</li>
<li><p>Later, it will again go to the if condition. The time will be now 9:14:06.. it means, the condition will pass again.. the motor will again rotate.. this will repeat for about 11 times.. until the time changes to 9:15:00 or more.</p>
</li>
<li><p>So the solution is to give a delay, before exiting the <code>if</code> loop if you wait for a minute with</p>
<p>delay(60000);</p>
</li>
</ol>
<p>then, the next 'if' condition will fail and works as per your expectation.</p>
<hr />
<p><strong>Part 2:</strong></p>
<p>debugging:</p>
<pre><code>        if ((Hour== 9 &amp;&amp; Min== 14)||(Hour== 21 &amp;&amp; Min== 0)) {
          for (pos = 0; pos &lt;= 180; pos += 1) { // goes from 0 degrees to 180 degrees
            // in steps of 1 degree
            myservo.write(pos);              // tell servo to go to position in variable 'pos'
            delay(15);
            Serial.println(&quot;moving&quot;);
    ....
</code></pre>
<p><a href="https://i.stack.imgur.com/YNd9A.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YNd9A.gif" alt="enter image description here" /></a></p>
