#include #include // Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS 2 #define TEMPERATURE_PRECISION 9 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // arrays to hold device addresses uint8_t SourceFeedSen[8], SourceReturnSen[8]; uint8_t LoadFeedSen[8], LoadReturnSen[8]; uint8_t StoreMaxSen[8], StoreMinSen[8]; uint8_t TempSen1[8], TempSen2[8]; // Try for an array of pointers to the arrays so wa can process them in for loops uint8_t *SensorList[6]; // Save the Relay pin setup int relay1Pin = 13; int relay1State = LOW; int lastrelay1State = LOW; // Counter in Seconds long relay1Sec = 0; // Relay/Pump will not cycle more than once every xx seconds long resetinterval = 300; long collectinterval = 60000; // get temps every nn000 milliseconds // Set up some default temperature variables float DeltaTdropF = 5; // Buffer temp for comparisons float SourceDelta = 12; // feed - return HX perf float LoadDelta = 10; // return - feed HX perf float FloorTempF = 120; float SenAdj = 4; // Setup some handy temp variables float SourceFeedTempC, SourceReturnTempC, LastSourceFeedTempC, LastSourceReturnTempC; float LoadFeedTempC, LoadReturnTempC, LastLoadFeedTempC, LastLoadReturnTempC; float StoreMaxTempC, StoreMinTempC , LastStoreMaxTempC, LastStoreMinTempC; // Farenhieght float SourceFeedTempF, SourceReturnTempF, LastSourceFeedTempF, LastSourceReturnTempF; float LoadFeedTempF, LoadReturnTempF, LastLoadFeedTempF, LastLoadReturnTempF; float StoreMaxTempF, StoreMinTempF, LastStoreMaxTempF, LastStoreMinTempF; // Calibrate Values for adjusting sensor to "real" temps. float SourceFeedCalF = 10; // attached to pipe at solder joint lost some degrees float SourceReturnCalF = 10; float LoadFeedCalF = 10; float LoadReturnCalF = 10; float StoreMaxCalF = 2; float StoreMinCalF = 2; // Maximum Values for testing trends. float SourceFeedMaxF = 0; float SourceReturnMaxF = 0; float LoadFeedMaxF = 0; float LoadReturnMaxF = 0; // Current state Values for testing trends. int SourceFeedTrend = LOW; int SourceHXTrend = LOW; int LoadFeedTrend = LOW; int LoadHXTrend = LOW; // Current state Values for testing trends. float SourceFeedTrendCnt = 0; float SourceHXTrendCnt = 0; float LoadFeedTrendCnt = 0; float LoadHXTrendCnt = 0; // Set up some handy loop counters and general variables. float ver = 2.0; int j,k; int sennum; // Some format flags to control what prints int logSourceFeed = HIGH; int logSourceReturn = HIGH; int logLoadFeed = HIGH; int logLoadReturn = HIGH; int logStoreMax = LOW; int logStoreMin = LOW; void setup(void) { // Fill in sensor list with named var addresses SensorList[0] = SourceFeedSen; SensorList[1] = SourceReturnSen; SensorList[2] = LoadFeedSen; SensorList[3] = LoadReturnSen; SensorList[4] = StoreMaxSen; SensorList[5] = StoreMinSen; // start serial port Serial.begin(115200); Serial.println(" "); delay(15000); Serial.print("Gassification Bioler Temperature IC Control Version "); Serial.println(ver); // initialize the relay digital pin as an output: pinMode(relay1Pin, OUTPUT); pinMode(ONE_WIRE_BUS, INPUT); // Start up the library sensors.begin(); // locate devices on the bus Serial.print("Locating devices..."); Serial.print("Found "); sennum = sensors.getDeviceCount(); Serial.print(sennum, DEC); Serial.println(" devices."); delay(5000); // report parasite power requirements Serial.print("Parasite power is: "); if (sensors.isParasitePowerMode()) Serial.println("ON"); else Serial.println("OFF"); // assign address manually. the addresses below will beed to be changed // to valid device addresses on your bus. device address can be retrieved // by using either sensors.search(deviceAddress) or individually via // sensors.getAddress(deviceAddress, index) //SourceFeedSen = { 0x28, 0x54, 0xD6, 0x5E, 0x2, 0x0, 0x0, 0xAC }; //SourceReturnSen = { 0x28, 0x7C, 0x2, 0x5F, 0x2, 0x0, 0x0, 0x75 }; //LoadFeedSen = { 0x28, 0xC9, 0xD6, 0x5E, 0x2, 0x0, 0x0, 0x57 }; //LoadReturnSen = { 0x28, 0xF9, 0xCB, 0x5E, 0x2, 0x0, 0x0, 0x2A }; //StoreMaxSen = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 }; //StoreMinSen = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 }; // search for devices on the bus and assign based on an index. ideally, // you would do this to initially discover addresses on the bus and then // use those addresses and manually assign them (see above) once you know // the devices on your bus (and assuming they don't change). for ( j = 0; j < sennum; j++) { if (!sensors.getAddress(SensorList[j], j)) Serial.println("Unable to find address for Device"); } if (!sensors.getAddress(SourceFeedSen, 0)) Serial.println("Unable to find address for Device 0"); if (!sensors.getAddress(SourceReturnSen, 1)) Serial.println("Unable to find address for Device 1"); if (!sensors.getAddress(LoadFeedSen, 2)) Serial.println("Unable to find address for Device 2"); if (!sensors.getAddress(LoadReturnSen, 3)) Serial.println("Unable to find address for Device 3"); if (!sensors.getAddress(StoreMaxSen, 4)) Serial.println("Unable to find address for Device 4"); if (!sensors.getAddress(StoreMinSen, 5)) Serial.println("Unable to find address for Device 5"); // show the addresses we found on the bus for ( j = 0; j < sennum; j++) { Serial.print("Device Address: "); printAddress(SensorList[j]); Serial.println(); } // Build in some time to get tail going against the serial port to see the startup ie tail -f /dev/ttyUSB0 delay(10000); //10 Sec // set the resolution to 9 bit for ( j = 0; j < sennum; j++) { sensors.setResolution(SensorList[j], 9); } // Confirm the settings at startup for ( j = 0; j < sennum; j++) { Serial.print("Device Resolution : "); printAddress(SensorList[j]); Serial.print(" "); Serial.print(sensors.getResolution(SensorList[j]), DEC); Serial.println(); } // Make sure we are starting with relay off digitalWrite(relay1Pin, LOW); // set the Relay off // Initialize the state vars lastrelay1State = LOW; relay1State = LOW; relay1Sec = millis()/1000; // Set the initial relay last switched time to the startup time } // function to print a device address void printAddress(uint8_t deviceAddress[]) { for (uint8_t i = 0; i < 8; i++) { Serial.print(deviceAddress[i], HEX); if (i < 7) Serial.print(" "); } } // function to print the temperature for a device void printTemperature(uint8_t deviceAddress[]) { // method 1 - slower //Serial.print("Temp C: "); //Serial.print(sensors.getTempC(deviceAddress)); //Serial.print(" Temp F: "); //Serial.print(sensors.getTempF(deviceAddress)); // method 2 - faster float tempC = sensors.getTempC(deviceAddress); Serial.print("Temp C: "); Serial.print(tempC); Serial.print(" Temp F: "); Serial.print(DallasTemperature::toFahrenheit(tempC)); } // function to print a device's resolution void printResolution(uint8_t deviceAddress[]) { Serial.print("Resolution: "); Serial.print(sensors.getResolution(deviceAddress)); Serial.println(); } // main function to print information about a device void printData(uint8_t deviceAddress[]) { Serial.print("Device Address: "); printAddress(deviceAddress); Serial.print(" "); printTemperature(deviceAddress); Serial.println(); } void loop(void) { // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); Serial.println(" DONE"); // print the device information //for ( j = 0; j < sennum; j++) //{ // printData(SensorList[j]); //} // Some example code from the blink demo // digitalWrite(relay1Pin, HIGH); // set the Relay on // delay(1000); // wait for a second // digitalWrite(relay1Pin, LOW); // set the Relay off // delay(1000); // wait for a second // Ok now actually do something to control the EKO // Fill in my vars for easy reading SourceFeedTempF = sensors.getTempF(SourceFeedSen) + SourceFeedCalF; SourceReturnTempF = sensors.getTempF(SourceReturnSen) + SourceReturnCalF; LoadFeedTempF = sensors.getTempF(LoadFeedSen) + LoadFeedCalF; LoadReturnTempF = sensors.getTempF(LoadReturnSen) + LoadReturnCalF; StoreMaxTempF = sensors.getTempF(StoreMaxSen) + StoreMaxCalF; StoreMinTempF = sensors.getTempF(StoreMinSen) + StoreMinCalF; // Do the trending and state logic here befor the tests in case you want to use the // state here to determine on/off. if ( SourceFeedTempF > LastSourceFeedTempF ) { SourceFeedTrendCnt++; if (( SourceFeedTempF > SourceFeedMaxF ) && ( SourceFeedTempF != 0)) { SourceFeedMaxF = SourceFeedTempF; // update the Max } if ( SourceFeedTrendCnt > 2 ) { SourceFeedTrend = HIGH; SourceFeedTrendCnt = 0; Serial.println("SourceFeed trending - set to HIGH"); if ( SourceFeedTempF > SourceFeedMaxF ) { SourceFeedMaxF = SourceFeedTempF; // NEED TO BE IN AN UP TREND TO GET STARTED AGAIN } } } else if ( SourceFeedTempF < LastSourceFeedTempF ) { SourceFeedTrendCnt--; if ( SourceFeedTrendCnt < -2 ) { SourceFeedTrend = LOW; SourceFeedTrendCnt = 0; Serial.println("SourceFeed trending - set to LOW"); } } if ( LoadFeedTempF > LastLoadFeedTempF ) { LoadFeedTrendCnt++; if (( LoadFeedTempF > LoadFeedMaxF ) && ( LoadFeedMaxF != 0)) { LoadFeedMaxF = LoadFeedTempF; // update the Max } if ( LoadFeedTrendCnt > 2 ) { LoadFeedTrend = HIGH; LoadFeedTrendCnt = 0; Serial.println("LoadFeed trending - set to HIGH"); if ( LoadFeedTempF > LoadFeedMaxF ) { LoadFeedMaxF = LoadFeedTempF; // restart the update the Max if we are trending up } } } else if ( LoadFeedTempF < LastLoadFeedTempF ) { LoadFeedTrendCnt--; if ( LoadFeedTrendCnt < -2 ) { LoadFeedTrend = LOW; LoadFeedTrendCnt = 0; Serial.println("LoadFeed trending - set to LOW"); } } if ((millis()/1000) - relay1Sec > resetinterval) { // Save the state before the Checking starts lastrelay1State = relay1State; // if ( (SourceFeedTempF + DeltaTdropF) > LoadFeedTempF ) if ( SourceFeedTempF > ( LoadFeedTempF + DeltaTdropF ) ) { // Turn on Tank pump flag Serial.print("SourceFeed higher than LoadFeed - set relay flag to HIGH/ON "); Serial.print(SourceFeedTempF ,DEC); Serial.print("/"); Serial.println(LoadFeedTempF + DeltaTdropF,DEC); relay1State = HIGH; } else { // Turn off Tank pump flag Serial.print("SourceFeed lower than LoadFeed - set relay flag to LOW/OFF "); Serial.print(SourceFeedTempF ,DEC); Serial.print("/"); Serial.println(LoadFeedTempF + DeltaTdropF,DEC); relay1State = LOW; } if ( SourceReturnTempF <= FloorTempF ) { Serial.print("SourceReturn lower than minimum - set relay flag to LOW/OFF "); Serial.print(SourceReturnTempF,DEC); Serial.print("/"); Serial.println( FloorTempF,DEC); relay1State = LOW; } if ( (( LoadReturnTempF - LoadFeedTempF) <= LoadDelta ) && ( LoadFeedTrend == LOW ) ) { Serial.print("Load temp change lower than minimum - set relay flag to LOW/OFF "); Serial.print(( LoadReturnTempF - LoadFeedTempF),DEC); Serial.print("/"); Serial.println( LoadDelta,DEC); relay1State = LOW; if ( SourceFeedTempF < ( SourceFeedMaxF - 60 ) ) { SourceFeedMaxF = 0; // reset for another run -- boiler is cold LoadFeedMaxF = 0; } } // Now set the relay -- After all the logic so we only turn on/off once if ( ( relay1State == HIGH ) && ( lastrelay1State != relay1State ) ) { Serial.print("Setting Relay pin HIGH Run Sec: "); Serial.println((millis()/1000)- relay1Sec,DEC); digitalWrite(relay1Pin, HIGH); // set the Relay on relay1Sec = millis()/1000; // Using seconds to store longer interval 10-12 hour run times } else if (( relay1State == LOW ) && ( lastrelay1State != relay1State )) { Serial.print("Setting Relay pin LOW Run Sec: "); Serial.println((millis()/1000)- relay1Sec,DEC); digitalWrite(relay1Pin, LOW); // set the Relay off relay1Sec = millis()/1000; // Using seconds to store longer interval 10-12 hour run times } } else { Serial.print("Not setting relay - cycle interval not cleared: "); Serial.print(((millis()/1000) - relay1Sec),DEC); Serial.print("/"); Serial.println( resetinterval,DEC); }// end of if ((millis()/1000) - relay1Sec > resetinterval) // Store the values for the next run LastSourceFeedTempF = SourceFeedTempF; LastSourceReturnTempF = SourceReturnTempF; LastLoadFeedTempF = LoadFeedTempF; LastLoadReturnTempF = LoadReturnTempF; LastStoreMaxTempF = StoreMaxTempF; LastStoreMinTempF = StoreMinTempF; if ( logSourceFeed == HIGH ) { // create an EASY to parse line for database inserts Serial.print("log:SourceFeed:F:"); Serial.println(SourceFeedTempF ); } if ( logSourceReturn == HIGH ) { // create an EASY to parse line for database inserts Serial.print("log:SourceReturn:F:"); Serial.println(SourceReturnTempF ); } if ( logLoadFeed == HIGH ) { // create an EASY to parse line for database inserts Serial.print("log:LoadFeed:F:"); Serial.println(LoadFeedTempF ); } if ( logLoadReturn == HIGH ) { // create an EASY to parse line for database inserts Serial.print("log:LoadReturn:F:"); Serial.println(LoadReturnTempF ); } if ( logStoreMax == HIGH ) { // create an EASY to parse line for database inserts Serial.print("log:StoreMax:F:"); Serial.println(StoreMaxTempF ); } if ( logStoreMin == HIGH ) { // create an EASY to parse line for database inserts Serial.print("log:StoreMin:F:"); Serial.println(StoreMinTempF ); } // Don't loop like crazy the Temps rise and fall SLOW ! delay(collectinterval); } // End of main loop