Automatic Chicken Feeder

for (pos = 0; pos <= 180; pos += 1) {
}

Since there is nothing between the { and } the for() does nothing other than loop.

what do you mean?

ahh i see i just put it wrong but my main problem is dat the servo motor is not running at time declared time how will i do that?

Not saying this is correct, but is this what you wanted ?

Old

for (pos = 0; pos <= 180; pos += 1) { 
}
    servo1.write(pos);              
    delay(5000);                       
  }

New

for (pos = 0; pos <= 180; pos += 1) 
{ 
    servo1.write(pos);              
    delay(5000);                       
}

yes i already changed it im sorry

Show us your new changes.


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.


if ((rtc.getTimeStr() >= 5)) { 
  { for (pos = 0; pos <= 180; pos += 1) { 
    servo1.write(pos);              
    delay(5000);                       
  }
  

What does this do ?

rtc.getTimeStr() >= 5

it tells that when its 5 am the servo motors will run

What happens at 6, 7, 8, 9, 10, 11, etc. ?

Hello! Can someone help me with programming my project? I will use RTC DS3231 and Servo Motor MG995. The feeding time schedule will be at 5am, 10am, 1pm and 4pm each day and once it reached the time, the servo motor will run for 180 degress and stop for 5seconds, else it will close and open again for the next time declared. Thank You!

What have you tried so far ?

If you have an Arduino already opening and closing the coop door, you might have it run the feeder too. Not kidding, 1 board can run 100+ do something now and then tasks easily but I would use more boards to not have long wire runs.

Step 1 is to set the time.
Step 2 is to remove the bit that sets the time.
Once set you don’t want to reset it again.

Step 3 is to learn how to use time and set the trip points.

Step 4 write the servo routine to rotate.

The timer will change state of a flag.

The flag will start the servo routine.
At the end the servo will reset the flag.

Each step can and should be separate.

Start programming. If you have any questions please post the code using code tags as described in the intro posts for the forum.

Your topics on the same subject have been merged

Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting will result in a suspension from the forum.

In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the “How to get the best out of this forum” guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

hello this is the code that i did but its not work`#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(MONDAY);
rtc.setTime(5, 0, 00);
rtc.setDate(03, 05, 2021);

servo1.attach(6);
servo2.attach(9);
}

void loop()
{
t = rtc.getTime();
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");

// Send date
Serial.print(rtc.getTimeStr());
Serial.print(" – ");

// Send time
Serial.println(rtc.getDateStr());

// Wait one second before repeating
delay (1000);
{
if ((rtc.getTimeStr() >= 5)) {
{ for (pos = 0; pos <= 180; pos += 1) {
servo1.write(pos);
delay(5000);
}

for (pos = 180; pos >= 0; pos -= 1) {
servo1.write(pos);
delay(2000);
}
}
else if ((rtc.getTimeStr() >= 10)) {
for (pos = 0; pos <= 180; pos += 1) {

servo1.write(pos);              
delay(5000);                       

}

for (pos = 180; pos >= 0; pos -= 1) {
servo1.write(pos);
delay(2000);
}
}

else if ((rtc.getTimeStr() >= 13)) { for (pos = 0; pos <= 180; pos += 1) {

servo1.write(pos);              
delay(5000);                       

}

for (pos = 180; pos >= 0; pos -= 1) {
servo1.write(pos);
delay(2000);
}
}
else if ((rtc.getTimeStr() >= 16)) {
for (pos = 0; pos <= 180; pos += 1) {

servo1.write(pos);              
delay(5000);                       

}

for (pos = 180; pos >= 0; pos -= 1) {
servo1.write(pos);
delay(2000);
}
}

if ((rtc.getTimeStr() >= 5)) {
for (pos = 0; pos <= 180; pos += 1) {

servo2.write(pos);              
delay(5000);                       

}

for (pos = 180; pos >= 0; pos -= 1) {
servo1.write(pos);
delay(2000);
}
}

else if ((rtc.getTimeStr() >= 10)) {
for (pos = 0; pos <= 180; pos += 1) {

servo2.write(pos);              
delay(5000);                       

}

for (pos = 180; pos >= 0; pos -= 1) {
servo2.write(pos);
delay(2000);
}
}

else if ((rtc.getTimeStr() >= 13)) { for (pos = 0; pos <= 180; pos += 1) {

servo2.write(pos);              
delay(5000);                       

}

for (pos = 180; pos >= 0; pos -= 1) {
servo2.write(pos);
delay(2000);
}
}

else if ((rtc.getTimeStr() >= 16)) { for (pos = 0; pos <= 180; pos += 1) {

servo2.write(pos);              
delay(5000);                       

}

for (pos = 180; pos >= 0; pos -= 1) {
servo2.write(pos);
delay(2000);
}
}

} }`ing

Can someone help me with my program because its not working once i uploaded it…

#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(MONDAY);     
   rtc.setTime(5, 0, 00);
  rtc.setDate(03, 05, 2021);   
  
servo1.attach(6);
  servo2.attach(9);
}

void loop()
{
  t = rtc.getTime();
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getTimeStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getDateStr());
  
  // Wait one second before repeating 
  delay (1000);
  {
 if ((rtc.getTimeStr() >= 5)) { 
  { for (pos = 0; pos <= 180; pos += 1) { 
    servo1.write(pos);              
    delay(5000);                       
  }
  
for (pos = 180; pos >= 0; pos -= 1) { 
    servo1.write(pos);              
    delay(2000);                       
  }
}
else if ((rtc.getTimeStr() >= 10)) { 
for (pos = 0; pos <= 180; pos += 1) { 
    
    servo1.write(pos);              
    delay(5000);                       
  }
  
for (pos = 180; pos >= 0; pos -= 1) { 
    servo1.write(pos);              
    delay(2000);                       
  }
}

else if ((rtc.getTimeStr() >= 13)) { for (pos = 0; pos <= 180; pos += 1) { 
    
    servo1.write(pos);              
    delay(5000);                       
  }
  
for (pos = 180; pos >= 0; pos -= 1) { 
    servo1.write(pos);              
    delay(2000);                       
  }
}
 else if ((rtc.getTimeStr() >= 16)) {
 for (pos = 0; pos <= 180; pos += 1) { 
    
    servo1.write(pos);              
    delay(5000);                       
  }
  
for (pos = 180; pos >= 0; pos -= 1) { 
    servo1.write(pos);              
    delay(2000);                       
  }
}


 if ((rtc.getTimeStr() >= 5)) { 
for (pos = 0; pos <= 180; pos += 1) { 
    
    servo2.write(pos);              
    delay(5000);                       
  }
  
for (pos = 180; pos >= 0; pos -= 1) { 
    servo1.write(pos);              
    delay(2000);                       
  }
}

else if ((rtc.getTimeStr() >= 10)) { 
for (pos = 0; pos <= 180; pos += 1) { 
    
    servo2.write(pos);              
    delay(5000);                       
  }
  
for (pos = 180; pos >= 0; pos -= 1) { 
    servo2.write(pos);              
    delay(2000);                       
  }
}

else if ((rtc.getTimeStr() >= 13)) { for (pos = 0; pos <= 180; pos += 1) { 
    
    servo2.write(pos);              
    delay(5000);                       
  }
  
for (pos = 180; pos >= 0; pos -= 1) { 
    servo2.write(pos);              
    delay(2000);                       
  }
}


else if ((rtc.getTimeStr() >= 16)) { for (pos = 0; pos <= 180; pos += 1) { 
    
    servo2.write(pos);              
    delay(5000);                       
  }
  
for (pos = 180; pos >= 0; pos -= 1) { 
    servo2.write(pos);              
    delay(2000);                       
  }
}
  

  }  }

Another cross-post merged. @ttmo_00 please follow the forum rules. This is your last warning.

Continuing the discussion from Automatic Chicken Feeder:

Another cross-post merged and @ttmo_00 is now taking a few days break from posting on the forum.

@ttmo_00, I hope that upon your return you will be more respectful of our rules.