Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. const byte Rly_Fan1 = 6; //Pin Relay Fan #1
  3. const byte Rly_Fan2 = 7; //Pin Relay Fan #2
  4. const byte Rly_Fan3 = 8; //Pin Relay Fan #3
  5.  
  6. unsigned long Dly_Periode = 5000; // it's 5 min but I'm 5 seconds for the speed of the tests
  7. unsigned long Millis_Now; // read millis = no
  8. unsigned long previousMillis;
  9.  
  10. boolean Lock_Boucle = 0;
  11. boolean Lock_Fan1 = 0;
  12. boolean Lock_Fan2 = 0;
  13. boolean Lock_Fan3 = 0;
  14.  
  15. float temp;
  16.  
  17. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  18.  
  19. void setup() {
  20. //Serial.begin(9600);
  21. lcd.begin (16, 2);
  22. pinMode(Rly_Fan1, OUTPUT);
  23. digitalWrite(Rly_Fan1, HIGH); //set a 0V
  24. pinMode(Rly_Fan2, OUTPUT);
  25. digitalWrite(Rly_Fan2, HIGH); //set a 0V
  26. pinMode(Rly_Fan3, OUTPUT);
  27. digitalWrite(Rly_Fan3, HIGH); //set a 0V
  28.  
  29. lcd.print ("T reel:");
  30.  
  31. }
  32.  
  33. void loop() {
  34. temp = analogRead (0) ;
  35. temp = temp / 2.06 ;
  36. lcd.print ("temp:");
  37.  
  38. // the goal is simple: it is to make activate the 3 fans successively if tepm> 26
  39.  
  40. // if tepm> 26 in active fan 1 then assist 5 min if the temperature is still> 26 in active fan 2 then assist 5 min if the temperature is still> 26 in active fan 3
  41. // but be careful if temp> 26 The temple counter does not start with the van 1 only starts with the fan 2 and 3
  42.  
  43. // if tepm> 24 disables the 3 fans successively 3 then 2 then 1
  44. // but beware if temp <25 the first fan to turn off should not wait 5 min in all possible:
  45.  
  46. // if temp <25 and the 3 fans are active so the 3 rd fan is the 1 st fan to turn off (in this case the 3 rd fan should not wait 5 min the other fans 2 and 1 wait 5 min then turn off if the temperature is still <24)
  47. // if temp <25 and two fans are active so the 2nd fan is the first fan to turn off (in this case the 2nd fan should not wait 5 minutes other fans in this case 1) wait 5 min and then get dry if the temperature is still <24)
  48. // if temp <25 and only one fan is active so the fan 1 will go directly without waiting 5 min
  49.  
  50.  
  51. if (temp > 26 && Lock_Fan1 == 0) { // Starting the fan # 1 the fan 1 of the spear without waiting 5000
  52. digitalWrite(Rly_Fan1, LOW ); // start fan1
  53. Lock_Fan1 = 1;
  54. previousMillis = millis();
  55. }
  56.  
  57. Millis_Now = millis();
  58. if ((Millis_Now - previousMillis) >= Dly_Periode) {
  59. if (temp > 26 && Lock_Boucle == 0 && Lock_Fan1 == 1 && Lock_Fan2 == 0) { // Start Fan # 2 after 5000 if the temperature is still> 26 start Fan # 2
  60. digitalWrite(Rly_Fan2, LOW ); // start fan1
  61. Lock_Boucle = 1;
  62. Lock_Fan2 = 1;
  63. }
  64.  
  65. if (temp > 26 && Lock_Boucle == 0 && Lock_Fan1 == 1 && Lock_Fan2 == 1 && Lock_Fan3 == 0) { // Start the Fan3 after 5000 if the temperare is still> 26 launches Fan # 2
  66.  
  67. digitalWrite(Rly_Fan3, LOW ); // Start the Fan3
  68. Lock_Boucle = 1;
  69. Lock_Fan3 = 1;
  70. previousMillis = millis ();
  71. }
  72. }
  73.  
  74. Millis_Now = millis();
  75.  
  76. if (temp < 24 && Lock_Fan1 == 1 && Lock_Fan2 == 1 && Lock_Fan3 == 1 ) { // Stop Fan # 3 if the temperature is <24 and the 3 fans are successively off the fan 3 stop without waiting 5000
  77. digitalWrite(Rly_Fan3, HIGH ); // Stop Fan # 3
  78. Lock_Fan3 = 0;
  79. previousMillis = millis ();
  80. }
  81. Millis_Now = millis();
  82. if ((Millis_Now - previousMillis) >= Dly_Periode) {
  83.  
  84. if (temp < 24 && Lock_Boucle == 0 && Lock_Fan1 == 1 && Lock_Fan2 == 1 && Lock_Fan3 == 0 ) { // Stop Fan # 2 if the temperature is still <24 and fan 3 is disable wait for 5000 then stop the fan 2
  85. digitalWrite(Rly_Fan2, HIGH ); // Stop Fan # 2
  86. Lock_Fan2 = 0;
  87. }
  88. if (temp < 24 && Lock_Boucle == 0 && Lock_Fan1 == 1 && Lock_Fan2 == 0 && Lock_Fan3 == 0 ) { // Stop Fan # 1 if the temperature is still <24 and fan 3 and 2 are disabled in wait for 5000 and then stop the fan 1
  89. digitalWrite(Rly_Fan1, HIGH ); // Stop Fan # 1
  90. Lock_Boucle = 1;
  91. Lock_Fan1 = 0;
  92. previousMillis = millis ();
  93. }
  94. }
  95.  
  96.  
  97.  
  98. if (temp < 24 && Lock_Fan1 == 1 && Lock_Fan2 == 1 && Lock_Fan3 == 0 ) { // Stop Fan # 2 if the temperature is <24 and fans 1 and 2 are active fan 2 stop without waiting 5000
  99. digitalWrite(Rly_Fan2, HIGH ); // Stop Fan # 2
  100. Lock_Fan2 = 0;
  101. previousMillis = millis();
  102. }
  103.  
  104. Millis_Now = millis();
  105. if ((Millis_Now - previousMillis) >= Dly_Periode) {
  106. if (temp < 24 && Lock_Boucle == 0 && Lock_Fan1 == 1 && Lock_Fan2 == 0 && Lock_Fan3 == 0 ) { // Stop fan # 1 if the temperature is still <24 and fan 1 only is active wait for 5000 and then stop the fan 1
  107. digitalWrite(Rly_Fan1, HIGH ); // Stop fan # 1
  108. Lock_Fan1 = 0;
  109. previousMillis = millis();
  110. }
  111. }
  112.  
  113.  
  114. if (temp < 24 && Lock_Fan1 == 1 && Lock_Fan2 == 0 && Lock_Fan3 == 0 ) { // Stop fan # 1 if the temperature <24 and fan 1 only is active stops fan 1 without waiting 5000
  115. digitalWrite(Rly_Fan1, HIGH ); //Arret ventilateur. // when I add this condition of missing in the program in appear other defaults danc there are errors in the use of the function millis
  116. Lock_Fan1 = 0; // when I delete this condition (line 111 to 116) there is only the defals: if temp <24 and the 3 fan are active fan 3 and 2 stops directly at the same time then 5 min then the fan 1 s' stop
  117. previousMillis = Millis_Now;
  118. Lock_Boucle = 0;
  119. }
  120. delay (1000);
  121. /* Fin Enpeche millis() de OVERFLOW */
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement