RTC project doesn't work without open IDE serial monitor

Hello everybody,

I’m making a robotic clock with an Arduino Micro, a RTC DS1307 modul, one 9g servo for hour indication and two 9g servo to make a robotic arm to indicate minut.

The systeme is power by 12v 1.5A power suppli connect to Vin of the Arduino Micro, I use the regulate +5V of the bord to power servos and RTC with a 200uF capacitor.

My probleme is : Everything work good (RTC and Servos) ONLY when I open the serial monitor of the Arduino IDE whereas if I just plug USB or/and power the system with the external power suppli, servos don’t move and stay every time at the same position.

If I plug the USB and open the serial monitor, i can switch on the power suppli, close the monitor and take of the USB, the clock is working

If i just switch off and on the power suppli, the clock doesn’t work, servo stay in one position

#include <Wire.h>
#include "RTClib.h"
#include <Servo.h>

Servo servomin1;
Servo servomin2;
Servo servoheure;

RTC_DS1307 rtc;

//char daysOfTheWeek[7][12] = {"Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"};

void setup () {

 servomin1.attach(12);
 servomin2.attach(11);
 servoheure.attach(10);
  
  while (!Serial); // for Leonardo/Micro/Zero

  Serial.begin(9600);
  Wire.begin();
  rtc.begin();
  
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
     //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
   servomin1.write(50); 
   delay(600)   
   servomin2.write(100);
   delay(700);
}

void loop () {
    DateTime now = rtc.now();
    
    //Serial.print(now.year(), DEC);
    //Serial.print('/');
    //Serial.print(now.month(), DEC);
    //Serial.print('/');
   // Serial.print(now.day(), DEC);
   // Serial.print(" (");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

   if (now.minute()== 1){
      servomin1.write(26);    
      servomin2.write(111);   
    }
    if (now.minute()== 2){
      servomin1.write(55);   
      servomin2.write(110);  
    }
    if (now.minute()== 3){
      servomin1.write(18);    
      servomin2.write(70);  
    }
    if (now.minute()== 4){
      servomin1.write(60);    
      servomin2.write(82);   
    }
    if (now.minute()== 5){
      servomin1.write(60);    
      servomin2.write(146);   
    }
    if (now.minute()== 6){
      servomin1.write(85);   
      servomin2.write(146);   
    }
    if (now.minute()== 7){
      servomin1.write(63);    
      servomin2.write(50);  
    }
    if (now.minute()== 8){
      servomin1.write(123);   
      servomin2.write(102);   
    }
    if (now.minute()== 9){
      servomin1.write(105);   
      servomin2.write(145);   
    }
    if (now.minute()== 10{
      servomin1.write(51);    
      servomin2.write(102);   
    }
                                       // .... the same until 60, cut because to much word for one post
  
     if (now.hour()== 1){                 
      servoheure.write(1);          
    }
     if (now.hour()== 2){
      servoheure.write(13);          
    }
     if (now.hour()== 3){
      servoheure.write(23);          
    }
     if (now.hour()== 4){
      servoheure.write(40);          
    }
     if (now.hour()== 5){
      servoheure.write(54);          
    }
     if (now.hour()== 6){
      servoheure.write(71);          
    }
     if (now.hour()== 7){
      servoheure.write(84);          
    }
     if (now.hour()== 8){
      servoheure.write(100);          
    }
     if (now.hour()== 9){
      servoheure.write(115);          
    }
     if (now.hour()== 10){
      servoheure.write(138);          
    }
     if (now.hour()== 11){
      servoheure.write(135);          
    }     
    if (now.hour()== 12){
      servoheure.write(8);          
    }

delay (2000);
    
}

Please can you help me !

Thanks you

remove this line:

  while (!Serial); // for Leonardo/Micro/Zero

or place it under Serial.begin() if you have a Leonardo/Micro/Zero

I remove it, it's working !!!

thanks a lots!

dubarn2:
I remove it, it's working !!!

thanks a lots!

Great, that line says "Wait here until a Serial connection is established." In your case, you asked for the Serial connection after that line, and well... it won't get there 'cuz its waiting, forever for something that won't happen.

thanks you an other time for the explanation!