/************************************************************************************************ Sequence these SEED 4-Bank DPDT Relays, with 1 second ON, 1 Second OFF, with 5 second delay ddf - 01/30/2015 in Preparation for Furnace Control or monitoring Only four Arduino Digital I/O pins, pins 4-7, are required to control the four different relays. Additionally the 5V and two GND Arduino pins are also required to power up the Relay Shield. Increased Time Delays - 08/07/2015, added some additional safety features 08/08/2015 What to do when no heat is requested, and what to do when done Error Flags incorporated 08/09/2015 RunTilDone-1() substituted for run and shutdown , {not used at all ??) 08/11/2015 Added the "Enable" condition 08/15/2015 Modified the Time from 8 seconds to 15 seconds 08/17/2015 Re-modified the Delay Times ************************************************************************************************/ int D0 = 0; int D1 = 1; int D2 = 2; int Enable = D0; int HeatRequest = D1; int AirFlow = D2; int Relay1 = 7; // These are identified in reverse numerical order ! int Relay2 = 6; int Relay3 = 5; int Relay4 = 4; int DelayTime1 = 5000; // wait 5000 milliseconds (5 seconds) for AirFlow 08/17/2015 int DelayTime2 = 20000; // wait 20000 milliseconds (20 seconds) for Flutter 08/17/2015 boolean Running = 0; boolean Fan = 0; boolean Air = 0; boolean StartUpError = 0; boolean AirFlowFailure = 0; boolean ErrorFlag = false; void StartUp(); void RunTilDone1(); void RunTilDone2(); void Error(); int ErrorCode = 0; int i = 0; // the setup routine runs once when you press reset: void setup() { // declare pins D0, D1, and D2 as inputs: pinMode(Enable, INPUT_PULLUP); pinMode(HeatRequest, INPUT_PULLUP); pinMode(AirFlow, INPUT_PULLUP); // declare pin 4-7 to be an outputs: pinMode(Relay1, OUTPUT); // Show Fan (*Heat) Request with LED 1 pinMode(Relay2, OUTPUT); // Show "Gas On" with LED 2 pinMode(Relay3, OUTPUT); // Show "Success" with LED 3 pinMode(Relay4, OUTPUT); // Show "ERROR" with LED 4 // } // the loop routine runs over and over again forever: void loop() { if(ErrorFlag = true) Error(); // Don't even try to run if there was an error //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if(digitalRead(Enable) == LOW) { StartUp(); } // RunTilDone1(); // RunTilDone2(); } // endif for "LOOP" //================================================================================= //------------------------------------------------------------------------------- // This part of the loop watches for the request for HEAT & AirFlow Requests //------------------------------------------------------------------------------- //================================================================================= void StartUp() { // If no Error, then stay in the Loop, waiting for Heat Request if(Running == false) { // Relay 1-4 = J1-J4 as NO & NC while(digitalRead(Enable) == LOW && digitalRead(HeatRequest) == LOW) { digitalWrite(Relay1,HIGH); // Turn ON the Exhaust Fan // Wait for a few seconds for the "Airflow" to occur. delay(DelayTime1); // wait 5000 milliseconds (5 seconds) if(digitalRead(AirFlow) == LOW) // Check for AirFlow inside the Heat loop { digitalWrite(Relay2,HIGH); // Turn ON the Gas Solenoid //======== delay(DelayTime2); // wait 20000 milliseconds (20 seconds) Running = true; digitalWrite(Relay3,HIGH); // Success !! //======== // delay(500); // digitalWrite(Relay3, LOW); // delay(500); // digitalWrite(Relay3, HIGH); //======== } else { AirFlowFailure = true; Running = false; // Avoid burning up the Exhaust Fan digitalWrite(Relay1, LOW); // Turn off the Exhaust Fan digitalWrite(Relay2, LOW); // Turn off the Gas Solenoid digitalWrite(Relay4, HIGH); // Indicate Error ErrorCode = 2; Error(); } //======== } // endif for HeatRequest & Turning on the Gas } // endif Running } // endif Startup //================================================================================= //================================================================================= void RunTilDone1() { while(digitalRead(HeatRequest == LOW) && digitalRead(AirFlow == LOW) ) { digitalWrite(Relay1, HIGH); digitalWrite(Relay2, HIGH); delay(500); digitalWrite(Relay3, LOW); delay(500); digitalWrite(Relay3, HIGH); } digitalWrite(Relay1, LOW); digitalWrite(Relay2, LOW); digitalWrite(Relay3, LOW); } //================================================================================= //================================================================================= void RunTilDone2() { // Now test for the proper "Running" conditions, by redundancy if(Running == true) { if(digitalRead(HeatRequest) == LOW) { delay(9000); // Wait 9 seconds, to avoid flutter if(digitalRead(HeatRequest) == LOW) // Now, check again { Fan = true; } // HEAT still requested } else Fan = false; // Double-Check Exhaust-Fan Airflow if(digitalRead(Fan == true && AirFlow) == LOW) Air = true; else { Air = false; digitalWrite(Relay2, LOW); // OOPS!, turn off the Gas RIGHT NOW!! Running = false; digitalWrite(Relay3, LOW); // Turn off the "Success" Indicator digitalWrite(Relay4, HIGH); // Turn om the ERROR Indicator digitalWrite(Relay1, LOW); // Turn off the Fan Fan = false; // Lost Airflow - STOP HERE } if(Fan == true && Air == true) { Running = true; digitalWrite(Relay3, HIGH); // Use as a "Flag" } else // OOPS!! { digitalWrite(Relay2, LOW); // Turn off the gas solenoid first delay(1000); digitalWrite(Relay1, LOW); // Now, turn off the fexhaust fan Running = false; // Declare the session done digitalWrite(Relay3, LOW); // Turn off the Indicator } } // endif for "Running" } //================================================================================= void Error() { digitalWrite(Relay2, LOW); // Turn off the gas solenoid first digitalWrite(Relay1, LOW); // Now, turn off the fexhaust fan Running = false; // Declare the session done digitalWrite(Relay3, LOW); // Turn off the "OK" Indicator while(ErrorCode == 1) { // if(digitalRead(Enable == LOW) // Compiling error { digitalWrite(Relay4, HIGH); // Turn on the "ERROR" Indicator delay(1000); digitalWrite(Relay4, LOW); delay(1000); } } while(ErrorCode == 2) { // if(digitalRead(Enable == LOW) // Compiling error { digitalWrite(Relay4, HIGH); // Turn on the "ERROR" Indicator delay(2000); digitalWrite(Relay4, LOW); delay(2000); } } AirFlowFailure = true; // delay(100000); }