Hi, I am pretty new to this but I am trying to make my curtain go up and down at specific times using the rtc module ds3231. all the components work on their own. my idea is that I connect the rtc module, stepper driver and relay module to the arduino uno. from the relay I connect the stepper motor because it needs 12v and the arduino cant provide that voltage.
any tips to make it work or do I need more components?
The code I have done is this:
#include <DS3231.h>
#include <Stepper.h>
#include "RTClib.h"
int Relay = 4;
RTC_DS3231 rtc;
char weekDays[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const int OnHour = 7; //SET TIME TO ON RELAY (24 HOUR FORMAT)
const int OnMin = 00;
const int OffHour = 7; //SET TIME TO OFF RELAY
const int OffMin = 30;
//const int OnHourAfternoon = 17;
//const int OnMinAfternoon = 00;
//const int OffHourAfternoon = 18;
//const int OffMinAfternoon = 40;
void setup() {
Serial.begin(9600);
rtc.begin();
pinMode(Relay, OUTPUT);
digitalWrite(Relay, LOW);
}
bool ifWeekend(int day) {
if (day == 6 || day == 0) {
return (true);
} else {
return (false);
}
}
DateTime t = rtc.adjust(DateTime(F(__DATE__),
F(__TIME__)));
void loop() {
DateTime now = rtc.now();
Serial.print(t.hour);
Serial.print(" hour(s), ");
Serial.print(t.min);
Serial.print(" minute(s)");
Serial.println(" ");
delay (1000);
if(t.hour == OnHour && t.min == OnMin){
digitalWrite(Relay,HIGH);
Serial.println("LIGHT ON");
}
else if(t.hour() == OffHour && t.min == OffMin){
digitalWrite(Relay,LOW);
Serial.println("LIGHT OFF");
}
if(OnHour >= 7.00 and Onmin <= 7.30) up()
if(t.hour >= 18.00 and t.min <= 18.30) down()
}
void up() {
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRev);
delay(1000);
}
void down() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRev);
delay(1000);
}