Automatic Scheduled Feeder

whats wrong with my program? can someone help me with this?

#include <TimeLib.h>
#include <DS3231.h>
#include <Servo.h>

Servo servo1;
Servo servo2;
Time t;
int pos = 0;

// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);
void setup()
{
  // Setup Serial connection
  Serial.begin(9600);
  // 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(FRIDAY);     
   rtc.setTime(20, 06, 10);
  rtc.setDate(11, 05, 2021);   
  
servo1.attach(6);
 servo2.attach(9);
}
 void loop()
{
  t = rtc.getTime();
 
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  

  Serial.print(rtc.getTimeStr());
  Serial.print(" -- ");

 
  Serial.println(rtc.getDateStr());
  
  delay (1000);
  {
    if ((rtc.getTime().hour >= 5)&&(rtc.getTime().hour <= 6)) {

  for (pos = 45; pos <= 180; pos += 1) { 
    servo1.write(pos);
    servo2.write(pos);              
    delay(15);                        
  }
  for (pos = 180; pos >= 45; pos -= 1) { 
    servo1.write(pos);
    servo2.write(pos);              
    delay(15);                      
  }
 }
   
else if ((rtc.getTime().hour  >= 10)&&(rtc.getTime().hour <= 11))
{ 
  for (pos = 45; pos <= 150; pos += 1) { 
    servo1.write(pos);
    servo2.write(pos);              
    delay(15);                        
  }
  
  for (pos = 150; pos >= 45; pos -= 1) { 
    servo1.write(pos);
    servo2.write(pos);              
    delay(15);                      
  }
 }
}
 if ((rtc.getTime().hour  >= 13)&&(rtc.getTime().hour <= 14))
 {
  for (pos = 45; pos <= 180; pos += 1) { 
    servo1.write(pos);
    servo2.write(pos);              
    delay(15);                        
  }
  for (pos = 180; pos >= 45; pos -= 1) { 
    servo1.write(pos);
    servo2.write(pos);              
    delay(15);                      
  }  
  }

else if ((rtc.getTime().hour  >= 16)&&(rtc.getTime().hour <= 17))
{ 
  for (pos = 45; pos <= 180; pos += 1) { 
    servo1.write(pos);
    servo2.write(pos);              
    delay(15);                        
  }
  for (pos = 180; pos >= 45; pos -= 1) { 
    servo1.write(pos);
    servo2.write(pos);              
    delay(15);                      
  }
 }
}

What’s not working ?

Where are your comments for your lines of code ?

my servo motor will run when it hits the time but it's not working

Sure thing. Click the flag icon and select "something else". Then ask the forum moderators to move your post to an appropriate forum section.

Show us a good schematic of your circuit.

Show us a good image of your ‘actual’ wiring.

Give links to components.

i dont have schematic diagram of it but i am sure that theres a problem in my program

It would look better if you ask the moderators yourself, rather than one of us doing it.

Take a pencil and a piece of paper and design a wiring diagram.

i already did that thanks

There are posting rules you must follow when asking for help.

Summary:
Show us a good schematic of your circuit. Show us a good image of your ‘actual’ wiring. Give links to components.

In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch. Use the </> icon from the ‘reply menu’ to attach the copied sketch.

Ah, the mods moved it already.

1 Like

Prove you are advancing to points in the sketch with print statements.

Do the servos work with the examples that come with the library ?

yes

How are the servos powered ?

Confirm there is a proper common GND between the Arduino and the servos.

power supply

i am also usng breadboard

What power supply ?

  for (pos = 45; pos <= 180; pos += 1)
  { 
    Serial.println(“We got to this point”);  //  <——<<< add this line
    servo1.write(pos);
    servo2.write(pos);              
    delay(15);
}

dc power jack

Will not respond anymore unless we see a good image of the actual wiring.

Cannot follow the wiring as most of it is hidden from sight !

If you are powering the servos from the Arduino 5v pin, don’t .

What is printed to the serial monitor with the addition of the print line of code ?