View Single Post
Old 01-03-16, 03:25 PM   #21
Acuario
Apprentice EcoRenovator
 
Join Date: May 2011
Location: Tortosa, Spain
Posts: 218
Thanks: 2
Thanked 75 Times in 44 Posts
Default

7. DS18B20.ino - you will need to put in your own addresses for your sensors
#include <OneWire.h>
#include <DallasTemperature.h>

// Initialize OneWire
OneWire one_wire(DS18B20);
DallasTemperature sensors(&one_wire);

// OneWire Sensor addresses
//28 71 94 2B 06 00 00 2C
//28 81 15 31 04 00 00 34
DeviceAddress compressor = { 0x28, 0x71, 0x94, 0x2B, 0x6, 0x0, 0x0, 0x2C };
DeviceAddress evaporator = { 0x28, 0x81, 0x15, 0x31, 0x4, 0x0, 0x0, 0x34 };

NIL_THREAD(threadReadSensors, arg) {
while (TRUE) {
//Serial.println("Read DS18B20 sensors");
sensors.requestTemperatures();
tempCompressor = sensors.getTempC(compressor);
tempEvaporator = sensors.getTempC(evaporator);
//Serial.println(tempCompressor);
//Serial.println(tempEvaporator);
if (tempCompressor != lastTempCompressor) {
lastTempCompressor = tempCompressor;
}
if (tempEvaporator != lastTempEvaporator) {
lastTempEvaporator = tempEvaporator;
}
// Sleep for 10 seconds.
nilThdSleepSeconds(10);
}
}

Acuario is offline   Reply With Quote