MathMarkies

Arduino Code

Jul 19th, 2021
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <DS1307.h>
  2.  
  3. #define relay 6
  4.  
  5. DS1307 rtc(A4, A5);
  6.  
  7. bool relayStatus = false;
  8.  
  9. void setup()
  10. {
  11.   rtc.halt(false);
  12.  
  13. pinMode(relay, OUTPUT);
  14. pinMode(11, OUTPUT);
  15.  
  16.   rtc.setSQWRate(SQW_RATE_1);
  17.   rtc.enableSQW(true);
  18.    
  19.   Serial.begin(9600);
  20. }
  21. bool active = false;
  22. int timer = 0;
  23. void loop()
  24. {
  25.   String time = rtc.getTimeStr(FORMAT_SHORT);
  26.  
  27.   String hour = "";
  28.   String min = "";
  29.  
  30.   for(int i = 0;i< time.length(); i++){
  31.    if(time[i] != ':')
  32.    if(hour.length() >= 2)
  33.    min += time[i];
  34.    else
  35.    hour += time[i];
  36.   }
  37.  
  38.   digitalWrite(11, LOW);
  39.  
  40. if(!active){
  41.   Serial.println("hour: "+hour+" : min: "+min);
  42.   if(hour == "15" && min == "06"){
  43.   timer = 0;
  44.   active = true;
  45.   }
  46. }else{
  47.   Serial.println("ALIMENTANDO!");
  48. timer ++;
  49. if(timer >= 120){
  50. digitalWrite(relay, HIGH);
  51. active = false;
  52. }else{digitalWrite(relay, LOW);}
  53.  
  54. }
  55.  
  56. delay(1000);
  57. }
  58.  
RAW Paste Data