Mere.ino 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #include <DS3231.h> //RTC DS3231 by andrew wickert
  2. #include <Wire.h>
  3. /*****************************************************************
  4. Déclaration des Capteurs
  5. *****************************************************************/
  6. //relay Lumiere
  7. const int Double = 5;
  8. //relay Arrosage
  9. const int Arro = 4;
  10. //relay aditionnel
  11. const int add = 3;
  12. //relay Ventilation
  13. const int Ventil = 2;
  14. /*
  15. //Interrupteur
  16. const int interLumBas = 6; //inter Lumiere bas ON/OFF
  17. const int interLumOff = 7; //inter Lumiere OFF
  18. const int interVentAuto = 8; //inter Ventilation ON/Auto
  19. const int interVentOff = 9; //inter Ventilation OFF
  20. const int interArroAuto = 10;//inter Arro ON/Auto
  21. const int interArroOff = 11;//inter Arro OFF
  22. const int inter7 = 12;*/
  23. //RTC
  24. DS3231 Clock;
  25. /*****************************************************************
  26. Déclaration des Variables globals
  27. *****************************************************************/
  28. //Variable lumiere
  29. int newDay = 1; // Variable pour savoir si nouveau jour.
  30. int HA; //heure allumage en minute
  31. int HE; //heure extinction en minute (Ha +18H +/-15min)
  32. //Variable Extraction
  33. int tmpExtract, humExtract;
  34. int extract;
  35. //Variabe Arrosage
  36. int HAro = 19 * 60;//Heure d'arrosage en minute
  37. /***********************************************************************
  38. Setup
  39. **********************************************************************/
  40. void setup() {
  41. Serial.begin(9600);
  42. /***********************************************************************
  43. init des pins
  44. * *********************************************************************/
  45. //PIN Lumiere
  46. pinMode(Double, OUTPUT);
  47. digitalWrite(Double, HIGH);
  48. //Pin ventilation
  49. pinMode(Ventil, OUTPUT);
  50. digitalWrite(Ventil, HIGH);
  51. //Pin Arrosage
  52. pinMode(Arro, OUTPUT);
  53. digitalWrite(Arro, HIGH);
  54. /***********************************************************************
  55. init des capteurs
  56. * *********************************************************************/
  57. //RTC
  58. Wire.begin();
  59. }
  60. void loop() {
  61. /***********************************************************************
  62. Gestion des capteurs
  63. * **********************************************************************/
  64. //RTC
  65. bool h24, am;
  66. int heure = Clock.getHour(h24, am );
  67. int minu = Clock.getMinute();
  68. int sec = Clock.getSecond();
  69. int HMin = heure * 60 + minu; // heure en minute
  70. Serial.print(heure);
  71. Serial.print(":");
  72. Serial.println(minu);
  73. /***********************************************************************
  74. Gestion de la lumiere
  75. * *********************************************************************
  76. */
  77. if (newDay == 1) {
  78. newDay = 0;
  79. HA = random (232, 247);
  80. HE = HA + 1065 + random(15);
  81. }
  82. if (HMin == 0) {
  83. newDay = 1;
  84. }
  85. if (HMin >= HA & HMin < HE) { //On met en route si on est dans le temps et que l'inter2 est en allumé
  86. Serial.println("Double lumiere ON");
  87. digitalWrite(Double, LOW);
  88. }
  89. else {
  90. Serial.println("Lumiere Eteint");
  91. digitalWrite(Double, HIGH);
  92. }
  93. /***********************************************************************
  94. Gestion de l'extraction
  95. * *********************************************************************/
  96. if (minu >= 50) {
  97. Serial.println("Extracteur ON");
  98. digitalWrite(Ventil, LOW);
  99. }
  100. else {
  101. Serial.println("Extracteur OFF");
  102. digitalWrite(Ventil, HIGH);
  103. }
  104. /***********************************************************************
  105. Gestion de l'arrosage
  106. * *********************************************************************/
  107. if (HMin == HAro & sec < 30) {
  108. Serial.println("arro ON");
  109. digitalWrite(Arro, LOW);
  110. } else {
  111. Serial.println("arro OFF");
  112. digitalWrite(Arro, HIGH);
  113. }
  114. Serial.println("");
  115. Serial.println("");
  116. delay(1000);
  117. }