Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- const byte Rly_Fan1 = 6; //Pin Relay Fan #1
- const byte Rly_Fan2 = 7; //Pin Relay Fan #2
- const byte Rly_Fan3 = 8; //Pin Relay Fan #3
- unsigned long Dly_Periode = 5000; // it's 5 min but I'm 5 seconds for the speed of the tests
- unsigned long Millis_Now; // read millis = no
- unsigned long previousMillis;
- boolean Lock_Boucle = 0;
- boolean Lock_Fan1 = 0;
- boolean Lock_Fan2 = 0;
- boolean Lock_Fan3 = 0;
- float temp;
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- void setup() {
- //Serial.begin(9600);
- lcd.begin (16, 2);
- pinMode(Rly_Fan1, OUTPUT);
- digitalWrite(Rly_Fan1, HIGH); //set a 0V
- pinMode(Rly_Fan2, OUTPUT);
- digitalWrite(Rly_Fan2, HIGH); //set a 0V
- pinMode(Rly_Fan3, OUTPUT);
- digitalWrite(Rly_Fan3, HIGH); //set a 0V
- lcd.print ("T reel:");
- }
- void loop() {
- temp = analogRead (0) ;
- temp = temp / 2.06 ;
- lcd.print ("temp:");
- // the goal is simple: it is to make activate the 3 fans successively if tepm> 26
- // 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
- // but be careful if temp> 26 The temple counter does not start with the van 1 only starts with the fan 2 and 3
- // if tepm> 24 disables the 3 fans successively 3 then 2 then 1
- // but beware if temp <25 the first fan to turn off should not wait 5 min in all possible:
- // 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)
- // 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)
- // if temp <25 and only one fan is active so the fan 1 will go directly without waiting 5 min
- if (temp > 26 && Lock_Fan1 == 0) { // Starting the fan # 1 the fan 1 of the spear without waiting 5000
- digitalWrite(Rly_Fan1, LOW ); // start fan1
- Lock_Fan1 = 1;
- previousMillis = millis();
- }
- Millis_Now = millis();
- if ((Millis_Now - previousMillis) >= Dly_Periode) {
- 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
- digitalWrite(Rly_Fan2, LOW ); // start fan1
- Lock_Boucle = 1;
- Lock_Fan2 = 1;
- }
- 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
- digitalWrite(Rly_Fan3, LOW ); // Start the Fan3
- Lock_Boucle = 1;
- Lock_Fan3 = 1;
- previousMillis = millis ();
- }
- }
- Millis_Now = millis();
- 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
- digitalWrite(Rly_Fan3, HIGH ); // Stop Fan # 3
- Lock_Fan3 = 0;
- previousMillis = millis ();
- }
- Millis_Now = millis();
- if ((Millis_Now - previousMillis) >= Dly_Periode) {
- 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
- digitalWrite(Rly_Fan2, HIGH ); // Stop Fan # 2
- Lock_Fan2 = 0;
- }
- 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
- digitalWrite(Rly_Fan1, HIGH ); // Stop Fan # 1
- Lock_Boucle = 1;
- Lock_Fan1 = 0;
- previousMillis = millis ();
- }
- }
- 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
- digitalWrite(Rly_Fan2, HIGH ); // Stop Fan # 2
- Lock_Fan2 = 0;
- previousMillis = millis();
- }
- Millis_Now = millis();
- if ((Millis_Now - previousMillis) >= Dly_Periode) {
- 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
- digitalWrite(Rly_Fan1, HIGH ); // Stop fan # 1
- Lock_Fan1 = 0;
- previousMillis = millis();
- }
- }
- 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
- 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
- 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
- previousMillis = Millis_Now;
- Lock_Boucle = 0;
- }
- delay (1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement