Hi you all wizkids behind the screens, trying to compile this code to UNO but get some errors, is this due to that it is an old piece of code i found online, or is it really somthing wrong with it?
Code is originally from Dallas i think
Greatful for all help
Br
/ Andy
...
// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
#define TEMPERATURE_PRECISION 12
// 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
DeviceAddress insideThermometer, outsideThermometer;
const int RELAY1 = 12;
float deltaT = 0;
float tempOutside = 0;
float tempBoiler = 0;
int defrostActive = 0; //Avfrostning aktiv
int defrostNeeded = 0; //Räknare behov
unsigned long timeStart = 0; //Avfrostning start
unsigned long timeRun = 0; //Avfrostning pågått
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
pinMode (RELAY1, OUTPUT);
// Start up the library
sensors.begin();
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" devices.");
// report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
Serial.print("Device 0 Address: ");
printAddress(insideThermometer);
Serial.println();
Serial.print("Device 1 Address: ");
printAddress(outsideThermometer);
Serial.println();
// set the resolution to 9 bit per device
sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);
sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
Serial.print("Device 0 Resolution: ");
Serial.print(sensors.getResolution(insideThermometer), DEC);
Serial.println();
Serial.print("Device 1 Resolution: ");
Serial.print(sensors.getResolution(outsideThermometer), DEC);
Serial.println();
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
// zero pad the address if necessary
if (deviceAddress < 16) Serial.print("0");
Serial.print(deviceAddress, HEX);
}
}
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
Serial.print("Temp C: ");
Serial.print(tempC, 3);
//g Serial.print(" Temp F: ");
//g Serial.print(DallasTemperature::toFahrenheit(tempC));
}
// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
Serial.print("Resolution: ");
Serial.print(sensors.getResolution(deviceAddress));
Serial.println();
}
// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
Serial.print("Device Address: ");
printAddress(deviceAddress);
Serial.print(" ");
printTemperature(deviceAddress);
Serial.println();
}
void loop(void)
{
delay (3000);
sensors.requestTemperatures();
printData(insideThermometer);
printData(outsideThermometer);
tempOutside = sensors.getTempC(insideThermometer);
tempBoiler = sensors.getTempC(outsideThermometer);
deltaT = tempOutside - tempBoiler;
Serial.println (tempOutside, 3);
Serial.println (tempBoiler, 3);
Serial.println (deltaT, 3);
if ((deltaT > 6) && (tempBoiler < -3.5) && (defrostActive == 0)) {
defrostNeeded++;
Serial.println ("Räknar upp");
}
else if (defrostNeeded > 0) {
defrostNeeded = 0 ; //nollställ räknare om behovet försvann
}
delay (2000);
Serial.println (defrostNeeded);
Serial.println (tempOutside, 3);
Serial.println (tempBoiler, 3);
if (defrostNeeded > 12 && defrostActive == 0) { //60 sek avfrostningsbehov före start
defrostActive = 1;
defrostNeeded = 0;
Serial.println ("Startar avfrostning");
digitalWrite (RELAY1, HIGH);
timeStart = millis();
}
timeRun = millis() - timeStart;
if (defrostActive == 1) {
if (timeRun > 720000 || tempBoiler > 10) { //Pågått 12 min eller når 10 grader.
digitalWrite (RELAY1, LOW);
defrostActive = 0;
delay(1800000); //30 min fördröjnig efter avfrostning
}
}
}