Advertisement
AngyalRobert

idokapcsolo

Jan 2nd, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. //VIRAL SCIENCE
  2. //SPECIFIC TIME TRIGGER RELAY
  3. #include <DS3231.h>
  4.  
  5. int Relay = 3;
  6.  
  7. DS3231  rtc(SDA, SCL);
  8. Time t;
  9.  
  10. const int OnHour[12]  = { 8, 10, 12, 14, 16, 18, 20, 22,  0,  2,  4,  6}; //SET TIME TO ON RELAY (24 HOUR FORMAT)
  11. const int OnMin[12]   = {15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15};
  12. const int OffHour[12] = { 8, 10, 12, 14, 16, 18, 20, 22,  0,  2,  4,  6}; //SET TIME TO OFF RELAY
  13. const int OffMin[12]  = {16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16};
  14.  
  15. void setup() {
  16.   Serial.begin(115200);
  17.   rtc.begin();
  18.   pinMode(Relay, OUTPUT);
  19.   digitalWrite(Relay, LOW);
  20. }
  21.  
  22. void loop() {
  23.   t = rtc.getTime();
  24.   Serial.print(t.hour);
  25.   Serial.print(" hour(s), ");
  26.   Serial.print(t.min);
  27.   Serial.print(" minute(s)");
  28.   Serial.println(" ");
  29.   delay (1000);
  30.  
  31.   unsigned char i;
  32.  
  33.   for (i=0; i<12; i++){
  34.   if(t.hour == OnHour[i] && t.min == OnMin[i]){
  35.     digitalWrite(Relay,HIGH);
  36.     Serial.println("LIGHT ON");
  37.     }
  38.    
  39.     else if(t.hour == OffHour[i] && t.min == OffMin[i]){
  40.       digitalWrite(Relay,LOW);
  41.       Serial.println("LIGHT OFF");
  42.     }
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement