Reiner Kunkel
Created October 7, 2018 © GPL3+

Pipe Trace Heating Controller

This came about in the need to protect pipework under a caravan with temperature controlled area switching.

IntermediateWork in progress8
Pipe Trace Heating Controller

Things used in this project

Story

Read more

Code

TraceHeatingControler_V3.ino

C/C++
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
Adafruit_SSD1306 display(OLED_RESET);
#define XPOS 0
#define YPOS 1
#define DELTAY 2

int signed tempSetOut = -2;
int signed tempSetIn = 3;
int signed tempSetPipes = 2;
int signed tempDiffState = 10;
int tempStateOut = 0;
int tempStateIn = 0;
int tempStatePipes = 0;
//#if (SSD1306_LCDHIGHT != 32)
//#error("Hight incorrect");
//#endif

// 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);

/*
 * The setup function. We only start the sensors here
 */
void setup(void)
{
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
  // Start up the library
  sensors.begin();
}

/*
 * Main function, get and show the temperature
 */
void loop(void)
{ 
float tempOut = sensors.getTempCByIndex(0);
float tempIn = sensors.getTempCByIndex(1);
float pipesOut = sensors.getTempCByIndex(2);
if (tempOut < tempSetOut)
{
  tempStateOut = 1;
}
else 
{
  tempStateOut = 0;
}
if (tempIn < tempSetIn)
  {
    tempStateIn =1;
  }
   else {
     tempStateIn = 0;
   } 
  if (pipesOut < tempSetPipes)
  {
    tempStatePipes = 1;
  }
else 
{
  tempStatePipes = 0;
}
if (tempStateOut + tempStatePipes > 0)
{
  digitalWrite(8, HIGH); Serial.println("   Pipe heating on !");
}
else 
{
  digitalWrite(8, LOW); Serial.println(" Trace heating is off !");
}
 if (tempStateIn > 0)
 {
   digitalWrite(9, HIGH); Serial.println(" Inside Heater On !");
 }
 else 
 {
   digitalWrite(9, LOW); Serial.println(" Inside heater Off !");
 }
 
 // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  // After we got the temperatures, we can print them here.
  // We use the function ByIndex, and as an example get the temperature from the first sensor only.
  Serial.print("T outside (index 0) is: ");
  Serial.println(sensors.getTempCByIndex(0)); 
  Serial.print("T inside (index 1) is: ");
  Serial.println(sensors.getTempCByIndex(1));
  Serial.print("T Pipes outside (index 2) is: ");
  Serial.println(sensors.getTempCByIndex(2));
  display.clearDisplay();
 display.display();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.print("OUT ");
  display.print(sensors.getTempCByIndex(0));display.print(" IN ");display.println(sensors.getTempCByIndex(1));
  display.print("PIPES OUT ");display.println(sensors.getTempCByIndex(2));
  //display.setCursor(0,2);  
  display.println(" OUT ,  IN , PIPES");
  display.print(tempSetOut);display.print(" ");display.print(tempStateOut);display.print("    ");display.print(tempSetIn);display.print;display.print(tempStateIn);
  display.print("  ");display.print(tempSetPipes);display.print(" ");display.print(tempStatePipes);
  
  display.display(); // essential or you see nothing
  
  delay(15000);
  
}


Credits

Reiner Kunkel
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.