#include <OneWire.h>
#include <DallasTemperature.h>
// 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 = 7;
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 = 180;
long collectinterval = 60000; // get temps every nn000 milliseconds
// Set up some default temperature variables
float DeltaTdropF = 5; // Buffer temp for comparisons
float FloorTempF = 120;
float SenAdj = 4;
// Setup some handy temp variables
// Farenhieght
float SourceFeedTempF, SourceReturnTempF, LastSourceFeedTempF, LastSourceReturnTempF;
float LoadFeedTempF, LoadReturnTempF, LastLoadFeedTempF, LastLoadReturnTempF;
float StoreMaxTempF, StoreMinTempF, LastStoreMaxTempF, LastStoreMinTempF;
// 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.
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 };
// set the resolution to 9 bit
for ( j = 0; j < sennum; j++)
{
sensors.setResolution(SensorList[j], 9);
}
// 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 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();
}