I am a beginner, and I'm getting really frustrated with my project. I have done so much research but there is nothing that I could find to figure this out. My goal is to have my servo move at a specific time of day (say 5:00am). But for the life of me I can't get my program to get the time from the RTC and use it to activate my servo program. How do I write a program to run my servo when 5:00am rolls around?
(deleted)
I can print the time, and I can move the servo, the problem lies in connecting the two. The RTC is the DS3231.
This is what I have so far.
#include <Servo.h>
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <Servo.h>
#include <DS3231.h>
#include <Time.h>
#include <Wire.h>
Time t;
DS3231 rtc(SDA, SCL);
Servo myservo;
int pos = 0;
int tempc;
int tempF;
uint32_t syncProvider();
void setup()
{
Serial.begin(115200);
rtc.begin();
Alarm.delay(1000);
Alarm.alarmRepeat(13, 07, 00, MorningAlarm);
// attachInterrupt(1, MorningAlarm, FALLING);
tempc = rtc.getTemp();
tempF = (tempc * 1.8) + 32.0;
myservo.attach(4);
}
void MorningAlarm (){
Serial.print("hi dad");
for (pos = 57; pos <= 92; pos += 1) {
myservo.write(pos);
delay(20);
}
for (pos = 92; pos >= 57; pos -= 1) {
myservo.write(pos);
delay(20);
Serial.print("Success");
}
}
void loop(){
t = rtc.getTime();
// suggest getting time from Arduino here
Serial.print(t.hour,DEC);
Serial.print(":");
Serial.print(t.min,DEC);
Serial.print(":");
Serial.print(t.sec,DEC);
Serial.print(" Temperature:");
Serial.print(tempF);
Serial.print(" F");
Serial.println();
Alarm.delay(1000); // wait one second between clock display
}
Ok, how do I go about connecting the two?
You will use
setSyncProvider(syncProvider);
The argument for the setSyncProvider function-- i.e. syncProvider -- is another function which will return the "unix time"-- that is the uint32_t (or time_t) value. The exact syntax of that function will depend on the library you are using for the DS3231.