I want to trigger the servo motor using a predefined time using an rtc module. However, the servo motor isn't triggering at all.
Then here's my source code
/*
- Austin Tarango
- Jan 10, 2017
- Sunrise Alarm Code
*/
#include <DS1307.h> //Include the clock library
#include <Servo.h>
Servo myservo;
// Changable Vars
int setHour = 15; // Set hours to wake (military time)
int setMin = 12; // Set minute to wakeint Relay = 9; // Set pinout with with PWM
int pos =0;
int Relay =9;
// Set up Vars
DS1307 rtc(SDA, SCL);
Time t;
void start();
void setup()
{
pinMode(Relay, OUTPUT);
Serial.begin(9600); // Match to serial monitor
rtc.begin();
}
void loop()
{
t = rtc.getTime(); // Make a time class called 't'
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
if (t.hour == setHour && t.min == setMin) // Check if it's time to wake up!
{
start();
}
// Wait one second before repeating
delay (1000);
}
void start()
{
for (pos = 0; pos <= 60; 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(10); // waits 15ms for the servo to reach the position
}
for (pos = 60; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
}